Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 {
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
)
|
| 254 |
-
|
|
|
|
|
|
|
| 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 |
-
-
|
| 264 |
-
-
|
| 265 |
-
-
|
| 266 |
-
-
|
| 267 |
-
-
|
| 268 |
-
-
|
| 269 |
-
-
|
| 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 |
-
|
| 291 |
st.markdown("---")
|
| 292 |
st.subheader("๐ Plagiarism Check")
|
|
|
|
| 293 |
if overlaps:
|
| 294 |
-
st.warning("
|
| 295 |
for hit in overlaps:
|
| 296 |
st.markdown(f"- [{hit['title']}]({hit['url']})")
|
| 297 |
else:
|
| 298 |
-
st.success("โ
No
|
| 299 |
-
|
|
|
|
| 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
|
| 314 |
-
{"role": "user", "content": f"
|
| 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 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|