File size: 1,481 Bytes
91f00be
c725f07
de022f5
 
91f00be
 
 
 
 
 
de022f5
c725f07
 
de022f5
 
91f00be
de022f5
c725f07
91f00be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ------------------ 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.")