documentaitest / app.py
IAMTFRMZA's picture
Update app.py
c1043ca verified
raw
history blame
1.87 kB
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.")