IAMTFRMZA commited on
Commit
e1d9b68
Β·
verified Β·
1 Parent(s): c1043ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -29
app.py CHANGED
@@ -1,58 +1,44 @@
1
- import streamlit as st
2
  import json
3
 
4
- # Load the JSON file once with caching
5
  @st.cache_data
6
  def load_data():
7
- with open("51940670-Manual-of-Surgical-Pathology-Third-Edition_1_structured_output.json", "r") as f:
8
  return json.load(f)
9
 
10
  data = load_data()
11
 
12
  st.title("πŸ“˜ Surgical Pathology Manual - Page Summary & FAQ")
13
 
14
- # Step 1: Get all page numbers where 'page' exists and is digit
15
- page_numbers = sorted({
16
- int(entry["page"])
17
- for entry in data
18
- if "page" in entry and str(entry["page"]).isdigit()
19
- })
20
-
21
- # Step 2: User selects page
22
  selected_page = st.selectbox("Select Page Number", page_numbers)
23
 
24
- # Step 3: Filter entries by page
25
- page_content = [
26
- entry for entry in data
27
- if str(entry.get("page", "")) == str(selected_page)
28
- ]
29
 
30
- # Step 4: Display summary and FAQs
31
  if page_content:
32
  for section in page_content:
33
  section_title = section.get("section_heading", "Untitled Section")
34
- summary = section.get("summary", None)
35
- faq = section.get("faq", [])
36
 
37
  st.markdown(f"### 🧠 Section: {section_title}")
38
 
39
- # Show summary
40
- if summary and isinstance(summary, str):
41
  st.markdown("#### πŸ” Summary")
42
  st.write(summary)
43
  else:
44
  st.info("No summary available for this section.")
45
 
46
- # Show FAQ
47
- if faq and isinstance(faq, list) and any("question" in q for q in faq):
48
  st.markdown("#### ❓ FAQ")
49
  for qna in faq:
50
- question = qna.get("question", "").strip()
51
- answer = qna.get("answer", "").strip()
52
- if question:
53
- st.markdown(f"**Q:** {question}")
54
- st.markdown(f"**A:** {answer if answer else '_No answer provided._'}")
55
  else:
56
  st.info("No FAQs available for this section.")
57
  else:
58
- st.warning("No content found for the selected page.")
 
 
1
  import json
2
 
3
+ # Load the structured pathology JSON file
4
  @st.cache_data
5
  def load_data():
6
+ with open("51940670-Manual-of-Surgical-Pathology-Third-Edition_1_structured_output (1).json", "r") as f:
7
  return json.load(f)
8
 
9
  data = load_data()
10
 
11
  st.title("πŸ“˜ Surgical Pathology Manual - Page Summary & FAQ")
12
 
13
+ # Get available pages
14
+ page_numbers = sorted({int(entry["page"]) for entry in data if "page" in entry})
 
 
 
 
 
 
15
  selected_page = st.selectbox("Select Page Number", page_numbers)
16
 
17
+ # Filter content for the selected page
18
+ page_content = [entry for entry in data if int(entry.get("page", -1)) == selected_page]
 
 
 
19
 
 
20
  if page_content:
21
  for section in page_content:
22
  section_title = section.get("section_heading", "Untitled Section")
23
+ summary = section.get("summary")
24
+ faq = section.get("faq")
25
 
26
  st.markdown(f"### 🧠 Section: {section_title}")
27
 
28
+ if summary:
 
29
  st.markdown("#### πŸ” Summary")
30
  st.write(summary)
31
  else:
32
  st.info("No summary available for this section.")
33
 
34
+ if faq:
 
35
  st.markdown("#### ❓ FAQ")
36
  for qna in faq:
37
+ question = qna.get("question", "")
38
+ answer = qna.get("answer", "")
39
+ st.markdown(f"**Q:** {question}")
40
+ st.markdown(f"**A:** {answer}")
 
41
  else:
42
  st.info("No FAQs available for this section.")
43
  else:
44
+ st.warning("No content found for the selected page.")