Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ if not OPENAI_API_KEY or not ASSISTANT_ID:
|
|
24 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
25 |
|
26 |
# ------------------ Load Structured JSON ------------------
|
27 |
-
STRUCTURED_JSON_PATH = "51940670-Manual-of-Surgical-Pathology-Third-Edition_1_structured_output.json"
|
28 |
try:
|
29 |
with open(STRUCTURED_JSON_PATH, "r") as f:
|
30 |
structured_data = json.load(f)
|
@@ -139,17 +139,23 @@ with right:
|
|
139 |
if st.session_state.image_url:
|
140 |
match = re.search(r'/(\d{3})\.png', st.session_state.image_url)
|
141 |
if match:
|
142 |
-
page_number = match.group(1)
|
143 |
page_entry = next((entry for entry in structured_data if entry.get("page_number") == page_number), None)
|
144 |
if page_entry:
|
145 |
summary_text = page_entry.get("summary", "No summary available.")
|
146 |
-
faq_list = page_entry.get("faqs", [])
|
147 |
|
|
|
|
|
148 |
st.markdown(summary_text)
|
149 |
|
|
|
150 |
st.subheader("β Auto-Generated FAQ")
|
151 |
if faq_list:
|
152 |
for faq in faq_list:
|
153 |
-
|
|
|
|
|
|
|
154 |
else:
|
155 |
st.info("No FAQs available for this page.")
|
|
|
24 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
25 |
|
26 |
# ------------------ Load Structured JSON ------------------
|
27 |
+
STRUCTURED_JSON_PATH = "/mnt/data/51940670-Manual-of-Surgical-Pathology-Third-Edition_1_structured_output (1).json"
|
28 |
try:
|
29 |
with open(STRUCTURED_JSON_PATH, "r") as f:
|
30 |
structured_data = json.load(f)
|
|
|
139 |
if st.session_state.image_url:
|
140 |
match = re.search(r'/(\d{3})\.png', st.session_state.image_url)
|
141 |
if match:
|
142 |
+
page_number = int(match.group(1)) # β
Must be int to match JSON
|
143 |
page_entry = next((entry for entry in structured_data if entry.get("page_number") == page_number), None)
|
144 |
if page_entry:
|
145 |
summary_text = page_entry.get("summary", "No summary available.")
|
146 |
+
faq_list = page_entry.get("faqs", []) or page_entry.get("questions", [])
|
147 |
|
148 |
+
# Summary Output
|
149 |
+
st.subheader("π Summary")
|
150 |
st.markdown(summary_text)
|
151 |
|
152 |
+
# FAQs Output
|
153 |
st.subheader("β Auto-Generated FAQ")
|
154 |
if faq_list:
|
155 |
for faq in faq_list:
|
156 |
+
if isinstance(faq, dict): # for {"question": "...", "answer": "..."}
|
157 |
+
st.markdown(f"**Q:** {faq.get('question', '')}\n\n**A:** {faq.get('answer', '')}")
|
158 |
+
else: # fallback if it's just a list of questions
|
159 |
+
st.markdown(f"**Q:** {faq}")
|
160 |
else:
|
161 |
st.info("No FAQs available for this page.")
|