Ani14 commited on
Commit
5db3787
Β·
verified Β·
1 Parent(s): 99bfafd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -64
app.py CHANGED
@@ -189,28 +189,18 @@ def generate_download_button(file, label, mime_type):
189
 
190
  # --- Streamlit UI ---
191
  st.set_page_config("Deep Research Assistant", layout="centered")
192
- # 🧠 Initialize session state
 
 
 
193
  if "follow_up_input" not in st.session_state:
194
  st.session_state["follow_up_input"] = ""
195
  if "methodology_recommended" not in st.session_state:
196
  st.session_state["methodology_recommended"] = False
 
 
197
 
198
-
199
- # Mermaid.js for mind map rendering
200
- st.markdown("""
201
- <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
202
- <script>
203
- mermaid.initialize({ startOnLoad: true });
204
- </script>
205
- """, unsafe_allow_html=True)
206
-
207
- st.markdown("""
208
- <style>
209
- .stApp { background-color: #0f172a; color: white; }
210
- h1, h2, h3 { color: #facc15; }
211
- </style>
212
- """, unsafe_allow_html=True)
213
-
214
  with st.sidebar:
215
  st.title("🧠 Deep Research Assistant")
216
  topic = st.text_input("πŸ” Enter your research topic")
@@ -222,6 +212,7 @@ with st.sidebar:
222
 
223
  st.title("πŸ“˜ Research Output")
224
 
 
225
  if research_button and topic:
226
  try:
227
  with st.status("πŸ” Gathering and analyzing sources...") as status:
@@ -284,15 +275,15 @@ APA Citations:
284
  full_output += chunk
285
  output_placeholder.markdown(full_output, unsafe_allow_html=True)
286
 
287
- # Save output for follow-up
288
  st.session_state["last_report"] = full_output
289
 
290
- # πŸ”Ή Downloads
291
  st.subheader("πŸ“„ Downloads")
292
  st.markdown(generate_download_button(generate_pdf(full_output), "Research_Report.pdf", "application/pdf"), unsafe_allow_html=True)
293
  st.markdown(generate_download_button(generate_latex(full_output), "Research_Report.tex", "application/x-latex"), unsafe_allow_html=True)
294
 
295
- # πŸ”Ή Plagiarism Check
296
  st.subheader("πŸ”Ž Plagiarism Check")
297
  overlaps = check_plagiarism(full_output, topic)
298
  if overlaps:
@@ -302,50 +293,52 @@ APA Citations:
302
  else:
303
  st.success("βœ… No major overlaps found.")
304
 
305
- st.subheader("πŸ’¬ Ask a Follow-Up")
306
-
307
- st.session_state["follow_up_input"] = st.text_input(
308
- "Ask a question about the report:", value=st.session_state["follow_up_input"]
309
- )
310
-
311
- if st.button("πŸ”„ Submit Follow-Up") and st.session_state["follow_up_input"]:
312
- if st.session_state["last_report"]:
313
- try:
314
- follow_prompt = [
315
- {"role": "system", "content": "You are a helpful academic assistant."},
316
- {"role": "user", "content": st.session_state["last_report"]},
317
- {"role": "user", "content": st.session_state["follow_up_input"]}
318
- ]
319
- follow_output = ""
320
- follow_box = st.empty()
321
- for chunk in call_llm(follow_prompt):
322
- follow_output += chunk
323
- follow_box.markdown(follow_output, unsafe_allow_html=True)
324
- except Exception as e:
325
- st.error(f"❌ Follow-up failed: {e}")
326
- else:
327
- st.warning("⚠️ Generate the research report first.")
328
-
329
- st.subheader("πŸ§ͺ Methodology Recommender")
330
-
331
- if st.button("🧠 Suggest Research Methodologies"):
332
- if st.session_state["last_report"]:
333
- try:
334
- method_prompt = [
335
- {"role": "system", "content": "You are a research advisor. Based on the following research report, suggest suitable research methodologies (quantitative, qualitative, ML/AI techniques, etc.). Be concise and give bullet-point suggestions."},
336
- {"role": "user", "content": st.session_state["last_report"]}
337
- ]
338
- method_output = ""
339
- method_box = st.empty()
340
- for chunk in call_llm(method_prompt):
341
- method_output += chunk
342
- method_box.markdown(method_output, unsafe_allow_html=True)
343
- except Exception as e:
344
- st.error(f"❌ Methodology suggestion failed: {e}")
345
- else:
346
- st.warning("⚠️ Generate the research report first.")
347
 
 
 
 
348
 
 
349
 
350
- except Exception as e:
351
- st.error(f"❌ Error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
 
190
  # --- Streamlit UI ---
191
  st.set_page_config("Deep Research Assistant", layout="centered")
192
+
193
+ # Initialize session state
194
+ if "last_report" not in st.session_state:
195
+ st.session_state["last_report"] = ""
196
  if "follow_up_input" not in st.session_state:
197
  st.session_state["follow_up_input"] = ""
198
  if "methodology_recommended" not in st.session_state:
199
  st.session_state["methodology_recommended"] = False
200
+ if "chat_history" not in st.session_state:
201
+ st.session_state["chat_history"] = []
202
 
203
+ # --- Sidebar Inputs ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  with st.sidebar:
205
  st.title("🧠 Deep Research Assistant")
206
  topic = st.text_input("πŸ” Enter your research topic")
 
212
 
213
  st.title("πŸ“˜ Research Output")
214
 
215
+ # --- Main Report Generation ---
216
  if research_button and topic:
217
  try:
218
  with st.status("πŸ” Gathering and analyzing sources...") as status:
 
275
  full_output += chunk
276
  output_placeholder.markdown(full_output, unsafe_allow_html=True)
277
 
278
+ # Save output for follow-up and methodology
279
  st.session_state["last_report"] = full_output
280
 
281
+ # --- Downloads ---
282
  st.subheader("πŸ“„ Downloads")
283
  st.markdown(generate_download_button(generate_pdf(full_output), "Research_Report.pdf", "application/pdf"), unsafe_allow_html=True)
284
  st.markdown(generate_download_button(generate_latex(full_output), "Research_Report.tex", "application/x-latex"), unsafe_allow_html=True)
285
 
286
+ # --- Plagiarism Check ---
287
  st.subheader("πŸ”Ž Plagiarism Check")
288
  overlaps = check_plagiarism(full_output, topic)
289
  if overlaps:
 
293
  else:
294
  st.success("βœ… No major overlaps found.")
295
 
296
+ except Exception as e:
297
+ st.error(f"❌ Error occurred: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
+ # --- Follow-up Q&A (always visible) ---
300
+ st.divider()
301
+ st.subheader("πŸ’¬ Follow-up Q&A")
302
 
303
+ followup = st.text_input("Ask a follow-up question:", key="follow_up_input")
304
 
305
+ if st.button("Ask"):
306
+ if followup:
307
+ try:
308
+ chat = st.session_state.chat_history + [{"role": "user", "content": followup}]
309
+ response = ""
310
+ for chunk in call_llm(chat, max_tokens=1500):
311
+ response += chunk
312
+ st.session_state.chat_history.append({"role": "user", "content": followup})
313
+ st.session_state.chat_history.append({"role": "assistant", "content": response})
314
+ st.markdown(response)
315
+ except Exception as e:
316
+ st.error(f"Follow-up error: {e}")
317
+
318
+ # --- Chat history display (optional) ---
319
+ with st.expander("πŸ“œ View Full Chat History", expanded=False):
320
+ for msg in st.session_state.chat_history:
321
+ role = msg["role"]
322
+ prefix = "πŸ‘€ You" if role == "user" else "πŸ€– Assistant"
323
+ st.markdown(f"**{prefix}:** {msg['content']}")
324
+
325
+ # --- Methodology Recommender ---
326
+ st.divider()
327
+ st.subheader("πŸ§ͺ Methodology Recommender")
328
+
329
+ if st.button("🧠 Suggest Research Methodologies"):
330
+ if st.session_state["last_report"]:
331
+ try:
332
+ method_prompt = [
333
+ {"role": "system", "content": "You are a research advisor. Based on the following research report, suggest suitable research methodologies (quantitative, qualitative, ML/AI techniques, etc.). Be concise and give bullet-point suggestions."},
334
+ {"role": "user", "content": st.session_state["last_report"]}
335
+ ]
336
+ method_output = ""
337
+ method_box = st.empty()
338
+ for chunk in call_llm(method_prompt):
339
+ method_output += chunk
340
+ method_box.markdown(method_output, unsafe_allow_html=True)
341
+ except Exception as e:
342
+ st.error(f"❌ Methodology suggestion failed: {e}")
343
+ else:
344
+ st.warning("⚠️ Generate the research report first.")