Ani14 commited on
Commit
68d14e0
ยท
verified ยท
1 Parent(s): 4b91de7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -49
app.py CHANGED
@@ -189,11 +189,23 @@ def generate_download_button(file, label, mime_type):
189
 
190
  # --- Streamlit UI ---
191
  st.set_page_config("Deep Research Bot", layout="centered")
 
 
 
 
 
 
 
 
 
192
  st.markdown("""
193
  <style>
194
  .stApp { background-color: #0f172a; color: white; }
195
  h1, h2, h3 { color: #facc15; }
196
- .css-1d391kg, .css-1kyxreq, .css-q8sbsg { background-color: #1e293b; color: white; border-radius: 10px; padding: 10px; }
 
 
 
197
  </style>
198
  """, unsafe_allow_html=True)
199
 
@@ -235,23 +247,25 @@ if research_button and topic:
235
 
236
  merged = merge_duplicates(all_sources)
237
 
238
- st.markdown("---")
239
- st.subheader("๐Ÿ–ผ Source Previews")
240
- image_shown = False
241
- cols = st.columns(2)
242
- for i, m in enumerate(merged):
243
- if m.get("image_url"):
244
- with cols[i % 2]:
245
- st.image(m["image_url"], caption=m["title"], use_container_width=True)
246
- image_shown = True
247
- if not image_shown:
248
- st.info("โ„น๏ธ No image previews available from sources.")
249
-
250
- citations = [generate_apa_citation(m['title'], m['url'], m['source']) for m in merged]
251
- combined_text = "\n\n".join(
252
- [f"- [{m['title']}]({m['url']})\n> {m.get('snippet', m.get('summary', ''))[:300]}..." for m in merged]
253
- )
254
- status.update(label="๐Ÿง  Synthesizing final report...")
 
 
255
 
256
  prompt = f"""
257
  You are an expert research assistant.
@@ -260,13 +274,13 @@ You are an expert research assistant.
260
  3. Write a full academic-style report on the newly proposed topic using a {tone.lower()} tone.
261
 
262
  Report Format:
263
- - **Introduction**: Context and importance of the new topic.
264
- - **Identified Research Gap**: Summary of missing or underexplored areas.
265
- - **Proposed Novel Topic**: Explanation of the new idea and its significance.
266
- - **Methodology**: Outline methods or frameworks to explore the idea.
267
- - **Comparative Insight**: How the new idea differs/improves over previous works.
268
- - **Future Work**: Possible expansions or questions.
269
- - **Citations**: Include APA style citations at the end.
270
 
271
  Sources:
272
  {combined_text}
@@ -275,6 +289,7 @@ APA Citations:
275
  {chr(10).join(citations)}
276
  """
277
 
 
278
  st.subheader(f"๐Ÿ“ {report_type} on '{topic}'")
279
  output_placeholder = st.empty()
280
  full_output = ""
@@ -282,49 +297,60 @@ APA Citations:
282
  full_output += chunk
283
  output_placeholder.markdown(full_output, unsafe_allow_html=True)
284
 
 
 
 
 
285
  st.markdown("---")
286
  st.subheader("๐Ÿ“„ Downloads")
287
  st.markdown(generate_download_button(generate_pdf(full_output), "Research_Report.pdf", "application/pdf"), unsafe_allow_html=True)
288
  st.markdown(generate_download_button(generate_latex(full_output), "Research_Report.tex", "application/x-latex"), unsafe_allow_html=True)
289
 
290
- overlaps = check_plagiarism(full_output, topic)
291
  st.markdown("---")
292
  st.subheader("๐Ÿ”Ž Plagiarism Check")
 
293
  if overlaps:
294
- st.warning("Potential overlaps detected:")
295
  for hit in overlaps:
296
  st.markdown(f"- [{hit['title']}]({hit['url']})")
297
  else:
298
- st.success("โœ… No major overlaps found.")
299
- # Mind Map Generator (Visual, not code block)
 
300
  st.markdown("---")
301
  st.subheader("๐Ÿงญ Visual Mind Map")
302
-
303
- # Inject Mermaid.js script to enable rendering
304
- st.markdown("""
305
- <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
306
- <script>
307
- mermaid.initialize({ startOnLoad: true });
308
- </script>
309
- """, unsafe_allow_html=True)
310
-
311
  if st.button("๐Ÿ—บ Generate Mind Map"):
312
  mindmap_prompt = [
313
- {"role": "system", "content": "You are a researcher that summarizes a topic into a mind map using Mermaid.js."},
314
- {"role": "user", "content": f"Generate a mermaid mind map for the following research paper:\n\n{st.session_state['last_report']}"}
315
  ]
316
-
317
  mindmap_code = ""
318
  for chunk in call_llm(mindmap_prompt):
319
  mindmap_code += chunk
320
-
321
- # Clean any code block wrapping
322
  mindmap_code = mindmap_code.replace("```mermaid", "").replace("```", "").strip()
323
-
324
- st.markdown(f"""
325
- <div class="mermaid">
326
- {mindmap_code}
327
- </div>
328
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  except Exception as e:
330
  st.error(f"โŒ Error occurred: {e}")
 
189
 
190
  # --- Streamlit UI ---
191
  st.set_page_config("Deep Research Bot", layout="centered")
192
+
193
+ # Inject Mermaid.js for mind map rendering
194
+ st.markdown("""
195
+ <script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
196
+ <script>
197
+ mermaid.initialize({ startOnLoad: true });
198
+ </script>
199
+ """, unsafe_allow_html=True)
200
+
201
  st.markdown("""
202
  <style>
203
  .stApp { background-color: #0f172a; color: white; }
204
  h1, h2, h3 { color: #facc15; }
205
+ .css-1d391kg, .css-1kyxreq, .css-q8sbsg {
206
+ background-color: #1e293b; color: white;
207
+ border-radius: 10px; padding: 10px;
208
+ }
209
  </style>
210
  """, unsafe_allow_html=True)
211
 
 
247
 
248
  merged = merge_duplicates(all_sources)
249
 
250
+ # Image previews
251
+ st.markdown("---")
252
+ st.subheader("๐Ÿ–ผ Source Previews")
253
+ image_shown = False
254
+ cols = st.columns(2)
255
+ for i, m in enumerate(merged):
256
+ if m.get("image_url"):
257
+ with cols[i % 2]:
258
+ st.image(m["image_url"], caption=m["title"], use_container_width=True)
259
+ image_shown = True
260
+ if not image_shown:
261
+ st.info("โ„น๏ธ No image previews available from sources.")
262
+
263
+ citations = [generate_apa_citation(m['title'], m['url'], m['source']) for m in merged]
264
+ combined_text = "\n\n".join(
265
+ [f"- [{m['title']}]({m['url']})\n> {m.get('snippet', m.get('summary', ''))[:300]}..." for m in merged]
266
+ )
267
+
268
+ st.status("๐Ÿง  Synthesizing final report...")
269
 
270
  prompt = f"""
271
  You are an expert research assistant.
 
274
  3. Write a full academic-style report on the newly proposed topic using a {tone.lower()} tone.
275
 
276
  Report Format:
277
+ - Introduction
278
+ - Identified Research Gap
279
+ - Proposed Novel Topic
280
+ - Methodology
281
+ - Comparative Insight
282
+ - Future Work
283
+ - Citations (APA)
284
 
285
  Sources:
286
  {combined_text}
 
289
  {chr(10).join(citations)}
290
  """
291
 
292
+ # Generate report
293
  st.subheader(f"๐Ÿ“ {report_type} on '{topic}'")
294
  output_placeholder = st.empty()
295
  full_output = ""
 
297
  full_output += chunk
298
  output_placeholder.markdown(full_output, unsafe_allow_html=True)
299
 
300
+ # Store report for mind map and follow-up
301
+ st.session_state["last_report"] = full_output
302
+
303
+ # Downloads
304
  st.markdown("---")
305
  st.subheader("๐Ÿ“„ Downloads")
306
  st.markdown(generate_download_button(generate_pdf(full_output), "Research_Report.pdf", "application/pdf"), unsafe_allow_html=True)
307
  st.markdown(generate_download_button(generate_latex(full_output), "Research_Report.tex", "application/x-latex"), unsafe_allow_html=True)
308
 
309
+ # Plagiarism
310
  st.markdown("---")
311
  st.subheader("๐Ÿ”Ž Plagiarism Check")
312
+ overlaps = check_plagiarism(full_output, topic)
313
  if overlaps:
314
+ st.warning("โš ๏ธ Overlaps found:")
315
  for hit in overlaps:
316
  st.markdown(f"- [{hit['title']}]({hit['url']})")
317
  else:
318
+ st.success("โœ… No significant overlaps found.")
319
+
320
+ # Mind Map Generator (Visual)
321
  st.markdown("---")
322
  st.subheader("๐Ÿงญ Visual Mind Map")
 
 
 
 
 
 
 
 
 
323
  if st.button("๐Ÿ—บ Generate Mind Map"):
324
  mindmap_prompt = [
325
+ {"role": "system", "content": "You are a researcher who converts reports into Mermaid.js mind maps."},
326
+ {"role": "user", "content": f"Create a mermaid mind map for this research:\n{full_output}"}
327
  ]
 
328
  mindmap_code = ""
329
  for chunk in call_llm(mindmap_prompt):
330
  mindmap_code += chunk
331
+
 
332
  mindmap_code = mindmap_code.replace("```mermaid", "").replace("```", "").strip()
333
+ st.markdown(f"<div class='mermaid'>{mindmap_code}</div>", unsafe_allow_html=True)
334
+
335
+ # Follow-up Q&A
336
+ st.markdown("---")
337
+ st.subheader("๐Ÿ’ฌ Ask a Follow-Up Question")
338
+ follow_input = st.text_input("Ask a question related to the report above:")
339
+ if st.button("๐Ÿ”„ Submit Follow-Up"):
340
+ if "last_report" in st.session_state:
341
+ with st.spinner("Thinking..."):
342
+ follow_prompt = [
343
+ {"role": "system", "content": "You are a helpful research assistant."},
344
+ {"role": "user", "content": f"Here is the report:\n{st.session_state['last_report']}"},
345
+ {"role": "user", "content": follow_input}
346
+ ]
347
+ follow_output = ""
348
+ follow_placeholder = st.empty()
349
+ for chunk in call_llm(follow_prompt):
350
+ follow_output += chunk
351
+ follow_placeholder.markdown(follow_output, unsafe_allow_html=True)
352
+ else:
353
+ st.error("โš ๏ธ Report not found. Please generate a report first.")
354
+
355
  except Exception as e:
356
  st.error(f"โŒ Error occurred: {e}")