Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,16 +6,16 @@ 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
|
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?")
|
@@ -26,28 +26,40 @@ with st.sidebar:
|
|
26 |
start = st.button("π Start Deep Research")
|
27 |
|
28 |
# Async wrapper
|
29 |
-
async def
|
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,
|
44 |
|
45 |
-
#
|
46 |
if start and query:
|
47 |
st.info("π€ Running super deep research...")
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
st.success("β
Report generation complete!")
|
|
|
51 |
st.subheader("π Final Report")
|
52 |
st.markdown(report, unsafe_allow_html=True)
|
53 |
|
@@ -55,9 +67,6 @@ if start and query:
|
|
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:
|
|
|
6 |
from gpt_researcher import GPTResearcher
|
7 |
from dotenv import load_dotenv
|
8 |
|
|
|
9 |
nest_asyncio.apply()
|
10 |
load_dotenv()
|
11 |
|
12 |
+
# Inject Tavily API key
|
13 |
os.environ["TAVILY_API_KEY"] = "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"
|
14 |
|
15 |
st.set_page_config(page_title="π§ Super Deep Research Agent", layout="wide")
|
16 |
st.title("π GPT-Powered Super Deep Research Assistant")
|
17 |
|
18 |
+
# --- Sidebar UI ---
|
19 |
with st.sidebar:
|
20 |
st.header("π Setup Research Agent")
|
21 |
query = st.text_input("π Research Topic", "Is AI a threat to creative jobs?")
|
|
|
26 |
start = st.button("π Start Deep Research")
|
27 |
|
28 |
# Async wrapper
|
29 |
+
async def run_research_with_logs(query, report_type, source, tone, fmt, log_callback):
|
30 |
agent = GPTResearcher(
|
31 |
query=query,
|
32 |
report_type=report_type,
|
33 |
report_source=source,
|
34 |
report_format=fmt,
|
35 |
+
tone=tone,
|
36 |
+
log_fn=log_callback
|
37 |
)
|
38 |
await agent.conduct_research()
|
39 |
report = await agent.write_report()
|
40 |
context = agent.get_research_context()
|
41 |
sources = agent.get_research_sources()
|
|
|
42 |
images = agent.get_research_images()
|
43 |
+
return report, context, sources, images
|
44 |
|
45 |
+
# --- Main Run ---
|
46 |
if start and query:
|
47 |
st.info("π€ Running super deep research...")
|
48 |
+
|
49 |
+
log_placeholder = st.empty()
|
50 |
+
log_text = ""
|
51 |
+
|
52 |
+
def stream_log(msg):
|
53 |
+
nonlocal log_text
|
54 |
+
log_text += f"π’ {msg}\n"
|
55 |
+
log_placeholder.code(log_text, language="text")
|
56 |
+
|
57 |
+
report, context, sources, images = asyncio.run(
|
58 |
+
run_research_with_logs(query, report_type, source_type, tone, output_format, log_callback=stream_log)
|
59 |
+
)
|
60 |
|
61 |
st.success("β
Report generation complete!")
|
62 |
+
|
63 |
st.subheader("π Final Report")
|
64 |
st.markdown(report, unsafe_allow_html=True)
|
65 |
|
|
|
67 |
for s in sources:
|
68 |
st.markdown(f"- [{s.get('title', 'Untitled')}]({s.get('url', '#')})")
|
69 |
|
|
|
|
|
|
|
70 |
if images:
|
71 |
st.subheader("πΌοΈ Relevant Images")
|
72 |
for img in images:
|