Ani14 commited on
Commit
a6a0096
Β·
verified Β·
1 Parent(s): dd69cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -43
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["last_report"] = ""
195
- if "generate_mindmap" not in st.session_state:
196
- st.session_state["generate_mindmap"] = False
197
- if "follow_up" not in st.session_state:
198
- st.session_state["follow_up"] = ""
 
 
 
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["last_report"] = full_output
 
292
 
293
  # πŸ”Ή Downloads
294
  st.subheader("πŸ“„ Downloads")
@@ -305,46 +309,50 @@ APA Citations:
305
  else:
306
  st.success("βœ… No major overlaps found.")
307
 
308
- # πŸ”Ή Mind Map Generator
309
- st.subheader("🧭 Visual Mind Map")
310
- if st.button("πŸ—Ί Generate Mind Map"):
311
- st.session_state["generate_mindmap"] = True
312
 
313
- if st.session_state.get("generate_mindmap") and st.session_state["last_report"]:
314
- try:
315
- mindmap_prompt = [
316
- {"role": "system", "content": "Convert this research report into a mermaid.js mind map."},
317
- {"role": "user", "content": st.session_state["last_report"]}
318
- ]
319
- mindmap_code = ""
320
- for chunk in call_llm(mindmap_prompt):
321
- mindmap_code += chunk
322
- mindmap_code = mindmap_code.replace("```mermaid", "").replace("```", "").strip()
323
- st.markdown(f"<div class='mermaid'>{mindmap_code}</div>", unsafe_allow_html=True)
324
- except Exception as e:
325
- st.error(f"Mind map generation failed: {e}")
326
- finally:
327
- st.session_state["generate_mindmap"] = False
328
 
329
  # πŸ”Ή Follow-up Interaction
330
- if st.button("πŸ”„ Submit Follow-Up"):
331
- st.session_state["follow_up"] = follow_input
332
 
333
- if st.session_state.get("follow_up") and st.session_state["last_report"]:
334
- try:
335
- follow_prompt = [
336
- {"role": "system", "content": "You are a helpful academic assistant."},
337
- {"role": "user", "content": st.session_state["last_report"]},
338
- {"role": "user", "content": st.session_state["follow_up"]}
339
- ]
340
- follow_output = ""
341
- follow_box = st.empty()
342
- for chunk in call_llm(follow_prompt):
343
- follow_output += chunk
344
- follow_box.markdown(follow_output, unsafe_allow_html=True)
345
- except Exception as e:
346
- st.error(f"Follow-up failed: {e}")
347
- finally:
348
- st.session_state["follow_up"] = ""
 
 
 
 
 
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}")