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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -189,6 +189,13 @@ def generate_download_button(file, label, mime_type):
189
 
190
  # --- Streamlit UI ---
191
  st.set_page_config("Deep Research Assistant", layout="centered")
 
 
 
 
 
 
 
192
 
193
  # Mermaid.js for mind map rendering
194
  st.markdown("""
@@ -300,8 +307,11 @@ APA Citations:
300
 
301
  # πŸ”Ή Mind Map Generator
302
  st.subheader("🧭 Visual Mind Map")
303
- if st.button("πŸ—Ί Generate Mind Map", key="mindmap_btn"):
304
- if "last_report" in st.session_state:
 
 
 
305
  mindmap_prompt = [
306
  {"role": "system", "content": "Convert this research report into a mermaid.js mind map."},
307
  {"role": "user", "content": st.session_state["last_report"]}
@@ -311,26 +321,30 @@ APA Citations:
311
  mindmap_code += chunk
312
  mindmap_code = mindmap_code.replace("```mermaid", "").replace("```", "").strip()
313
  st.markdown(f"<div class='mermaid'>{mindmap_code}</div>", unsafe_allow_html=True)
314
- else:
315
- st.error("❌ No report found. Please run research first.")
 
 
316
 
317
  # πŸ”Ή Follow-up Interaction
318
- st.subheader("πŸ’¬ Ask a Follow-Up")
319
- follow_input = st.text_input("Ask a question about the report:")
320
  if st.button("πŸ”„ Submit Follow-Up"):
321
- if "last_report" in st.session_state:
 
 
 
322
  follow_prompt = [
323
  {"role": "system", "content": "You are a helpful academic assistant."},
324
  {"role": "user", "content": st.session_state["last_report"]},
325
- {"role": "user", "content": follow_input}
326
  ]
327
  follow_output = ""
328
  follow_box = st.empty()
329
  for chunk in call_llm(follow_prompt):
330
  follow_output += chunk
331
  follow_box.markdown(follow_output, unsafe_allow_html=True)
332
- else:
333
- st.warning("⚠️ Please generate the report first.")
334
-
 
335
  except Exception as e:
336
- st.error(f"❌ Error occurred: {e}")
 
189
 
190
  # --- Streamlit UI ---
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("""
 
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"]}
 
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}")