Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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"
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 315 |
-
st.error("
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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":
|
| 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 |
-
|
| 333 |
-
st.
|
| 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}")
|