Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -191,11 +191,14 @@ def generate_download_button(file, label, mime_type):
|
|
| 191 |
st.set_page_config("Deep Research Assistant", layout="centered")
|
| 192 |
# π§ Initialize session state
|
| 193 |
if "last_report" not in st.session_state:
|
| 194 |
-
st.session_state
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Mermaid.js for mind map rendering
|
| 201 |
st.markdown("""
|
|
@@ -288,7 +291,8 @@ APA Citations:
|
|
| 288 |
output_placeholder.markdown(full_output, unsafe_allow_html=True)
|
| 289 |
|
| 290 |
# Save output for follow-up
|
| 291 |
-
st.session_state
|
|
|
|
| 292 |
|
| 293 |
# πΉ Downloads
|
| 294 |
st.subheader("π Downloads")
|
|
@@ -305,46 +309,50 @@ APA Citations:
|
|
| 305 |
else:
|
| 306 |
st.success("β
No major overlaps found.")
|
| 307 |
|
| 308 |
-
|
| 309 |
-
st.
|
| 310 |
-
if
|
| 311 |
-
st.session_state
|
| 312 |
|
| 313 |
-
if st.session_state.
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
|
| 329 |
# πΉ Follow-up Interaction
|
| 330 |
-
|
| 331 |
-
st.session_state["follow_up"] = follow_input
|
| 332 |
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
except Exception as e:
|
| 350 |
st.error(f"β Error occurred: {e}")
|
|
|
|
| 191 |
st.set_page_config("Deep Research Assistant", layout="centered")
|
| 192 |
# π§ Initialize session state
|
| 193 |
if "last_report" not in st.session_state:
|
| 194 |
+
st.session_state.last_report = ""
|
| 195 |
+
|
| 196 |
+
if "mindmap_triggered" not in st.session_state:
|
| 197 |
+
st.session_state.mindmap_triggered = False
|
| 198 |
+
|
| 199 |
+
if "followup_question" not in st.session_state:
|
| 200 |
+
st.session_state.followup_question = ""
|
| 201 |
+
|
| 202 |
|
| 203 |
# Mermaid.js for mind map rendering
|
| 204 |
st.markdown("""
|
|
|
|
| 291 |
output_placeholder.markdown(full_output, unsafe_allow_html=True)
|
| 292 |
|
| 293 |
# Save output for follow-up
|
| 294 |
+
st.session_state.last_report = full_output
|
| 295 |
+
|
| 296 |
|
| 297 |
# πΉ Downloads
|
| 298 |
st.subheader("π Downloads")
|
|
|
|
| 309 |
else:
|
| 310 |
st.success("β
No major overlaps found.")
|
| 311 |
|
| 312 |
+
st.subheader("π§ Visual Mind Map")
|
| 313 |
+
mindmap_button = st.button("πΊ Generate Mind Map")
|
| 314 |
+
if mindmap_button:
|
| 315 |
+
st.session_state.mindmap_triggered = True
|
| 316 |
|
| 317 |
+
if st.session_state.mindmap_triggered and st.session_state.last_report:
|
| 318 |
+
mindmap_prompt = [
|
| 319 |
+
{"role": "system", "content": "Convert this research report into a mermaid.js mind map."},
|
| 320 |
+
{"role": "user", "content": st.session_state.last_report}
|
| 321 |
+
]
|
| 322 |
+
mindmap_code = ""
|
| 323 |
+
for chunk in call_llm(mindmap_prompt):
|
| 324 |
+
mindmap_code += chunk
|
| 325 |
+
|
| 326 |
+
mindmap_code = mindmap_code.replace("```mermaid", "").replace("```", "").strip()
|
| 327 |
+
st.markdown(f"<div class='mermaid'>{mindmap_code}</div>", unsafe_allow_html=True)
|
| 328 |
+
|
| 329 |
+
# Reset trigger after rendering
|
| 330 |
+
st.session_state.mindmap_triggered = False
|
| 331 |
+
|
| 332 |
|
| 333 |
# πΉ Follow-up Interaction
|
| 334 |
+
st.subheader("π¬ Ask a Follow-Up")
|
|
|
|
| 335 |
|
| 336 |
+
followup_input = st.text_input("Ask a question about the report:")
|
| 337 |
+
|
| 338 |
+
followup_submit = st.button("π Submit Follow-Up")
|
| 339 |
+
if followup_submit and followup_input:
|
| 340 |
+
st.session_state.followup_question = followup_input
|
| 341 |
+
|
| 342 |
+
if st.session_state.followup_question and st.session_state.last_report:
|
| 343 |
+
follow_prompt = [
|
| 344 |
+
{"role": "system", "content": "You are a helpful academic assistant."},
|
| 345 |
+
{"role": "user", "content": st.session_state.last_report},
|
| 346 |
+
{"role": "user", "content": st.session_state.followup_question}
|
| 347 |
+
]
|
| 348 |
+
follow_output = ""
|
| 349 |
+
follow_box = st.empty()
|
| 350 |
+
for chunk in call_llm(follow_prompt):
|
| 351 |
+
follow_output += chunk
|
| 352 |
+
follow_box.markdown(follow_output, unsafe_allow_html=True)
|
| 353 |
+
|
| 354 |
+
# Reset after showing
|
| 355 |
+
st.session_state.followup_question = ""
|
| 356 |
+
|
| 357 |
except Exception as e:
|
| 358 |
st.error(f"β Error occurred: {e}")
|