Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,66 @@
|
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import asyncio
|
4 |
import nest_asyncio
|
5 |
from gpt_researcher import GPTResearcher
|
|
|
6 |
|
7 |
-
# Allow async in Streamlit
|
8 |
nest_asyncio.apply()
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
st.title("π GPT Researcher (Async Streamlit Interface)")
|
13 |
-
|
14 |
-
# Sidebar Inputs
|
15 |
-
with st.sidebar:
|
16 |
-
st.header("π§ Research Agent Setup")
|
17 |
-
query = st.text_input("π Research Topic", "Should I invest in Nvidia?")
|
18 |
-
report_type = st.selectbox("π Report Type", [
|
19 |
-
"research_report", "summary", "detailed_report"
|
20 |
-
])
|
21 |
-
run_button = st.button("π Run Research Agent")
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
researcher = GPTResearcher(query, report_type)
|
26 |
-
|
27 |
-
# Phase 1: Planning + Research
|
28 |
-
await researcher.conduct_research()
|
29 |
-
|
30 |
-
# Phase 2: Writing
|
31 |
-
report = await researcher.write_report()
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
st.subheader("π Final Report")
|
52 |
st.markdown(report, unsafe_allow_html=True)
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
st.
|
57 |
-
for src in sources:
|
58 |
-
title = src.get("title", "Untitled")
|
59 |
-
url = src.get("url", "#")
|
60 |
-
st.markdown(f"- [{title}]({url})")
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
st.subheader("π° Cost Breakdown")
|
65 |
-
st.json(costs)
|
66 |
|
67 |
-
# Show related images
|
68 |
if images:
|
69 |
-
st.subheader("πΌοΈ
|
70 |
for img in images:
|
71 |
st.image(img, use_column_width=True)
|
72 |
|
73 |
-
|
74 |
-
st.download_button("πΎ Download Report", data=report, file_name="report.md", mime="text/markdown")
|
|
|
1 |
+
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import asyncio
|
5 |
import nest_asyncio
|
6 |
from gpt_researcher import GPTResearcher
|
7 |
+
from dotenv import load_dotenv
|
8 |
|
9 |
+
# Allow async execution in Streamlit
|
10 |
nest_asyncio.apply()
|
11 |
+
load_dotenv()
|
12 |
|
13 |
+
# Inject Tavily API key (used internally by gpt-researcher if configured)
|
14 |
+
os.environ["TAVILY_API_KEY"] = "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"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
st.set_page_config(page_title="π§ Super Deep Research Agent", layout="wide")
|
17 |
+
st.title("π GPT-Powered Super Deep Research Assistant")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
with st.sidebar:
|
20 |
+
st.header("π Setup Research Agent")
|
21 |
+
query = st.text_input("π Research Topic", "Is AI a threat to creative jobs?")
|
22 |
+
report_type = st.selectbox("π Report Type", ["research_report", "summary", "detailed_report"])
|
23 |
+
tone = st.selectbox("π£οΈ Tone", ["objective", "persuasive", "informative"])
|
24 |
+
source_type = st.selectbox("π‘ Source Scope", ["web", "arxiv", "semantic-scholar", "hybrid"])
|
25 |
+
output_format = st.selectbox("π Output Format", ["markdown", "text"])
|
26 |
+
start = st.button("π Start Deep Research")
|
27 |
|
28 |
+
# Async wrapper
|
29 |
+
async def run_research(query, report_type, source, tone, fmt):
|
30 |
+
agent = GPTResearcher(
|
31 |
+
query=query,
|
32 |
+
report_type=report_type,
|
33 |
+
report_source=source,
|
34 |
+
report_format=fmt,
|
35 |
+
tone=tone
|
36 |
+
)
|
37 |
+
await agent.conduct_research()
|
38 |
+
report = await agent.write_report()
|
39 |
+
context = agent.get_research_context()
|
40 |
+
sources = agent.get_research_sources()
|
41 |
+
costs = agent.get_costs()
|
42 |
+
images = agent.get_research_images()
|
43 |
+
return report, context, sources, costs, images
|
44 |
|
45 |
+
# Run and show results
|
46 |
+
if start and query:
|
47 |
+
st.info("π€ Running super deep research...")
|
48 |
+
report, context, sources, costs, images = asyncio.run(run_research(query, report_type, source_type, tone, output_format))
|
49 |
|
50 |
+
st.success("β
Report generation complete!")
|
51 |
st.subheader("π Final Report")
|
52 |
st.markdown(report, unsafe_allow_html=True)
|
53 |
|
54 |
+
st.subheader("π Sources")
|
55 |
+
for s in sources:
|
56 |
+
st.markdown(f"- [{s.get('title', 'Untitled')}]({s.get('url', '#')})")
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
st.subheader("π° Token Usage & Cost")
|
59 |
+
st.json(costs)
|
|
|
|
|
60 |
|
|
|
61 |
if images:
|
62 |
+
st.subheader("πΌοΈ Relevant Images")
|
63 |
for img in images:
|
64 |
st.image(img, use_column_width=True)
|
65 |
|
66 |
+
st.download_button("πΎ Download Report", report, file_name="deep_research.md", mime="text/markdown")
|
|