documentaitest / app.py
IAMTFRMZA's picture
Update app.py
91f00be verified
raw
history blame
1.48 kB
# ------------------ Right Column: Structured Summary + FAQ (with Buttons) ------------------
with right:
st.subheader("πŸ“Œ Summary & FAQ (from Structured Data)")
# Controls
col1, col2 = st.columns(2)
show_summary = col1.button("πŸ“ Load Summary")
show_faq = col2.button("❓ Load FAQ")
summary_text = "Click the button to load summary."
faq_list = []
if st.session_state.image_url:
match = re.search(r'/(\d{3})\.png', st.session_state.image_url)
if match:
page_number = int(match.group(1))
page_entry = next((entry for entry in structured_data if entry.get("page_number") == page_number), None)
if page_entry:
if show_summary:
summary_text = page_entry.get("summary", "No summary available.")
if show_faq:
faq_list = page_entry.get("faqs", []) or page_entry.get("questions", [])
# Display Summary
if show_summary:
st.subheader("πŸ“ Summary")
st.markdown(summary_text)
# Display FAQs
if show_faq:
st.subheader("❓ Auto-Generated FAQ")
if faq_list:
for faq in faq_list:
if isinstance(faq, dict):
st.markdown(f"**Q:** {faq.get('question', '')}\n\n**A:** {faq.get('answer', '')}")
else:
st.markdown(f"**Q:** {faq}")
else:
st.info("No FAQs available for this page.")