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