Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
import asyncio
|
@@ -6,18 +5,20 @@ import nest_asyncio
|
|
6 |
from gpt_researcher import GPTResearcher
|
7 |
from dotenv import load_dotenv
|
8 |
|
|
|
9 |
nest_asyncio.apply()
|
10 |
load_dotenv()
|
11 |
|
12 |
-
#
|
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 |
-
#
|
19 |
with st.sidebar:
|
20 |
-
st.header("π
|
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"])
|
@@ -25,7 +26,7 @@ with st.sidebar:
|
|
25 |
output_format = st.selectbox("π Output Format", ["markdown", "text"])
|
26 |
start = st.button("π Start Deep Research")
|
27 |
|
28 |
-
# Async
|
29 |
async def run_research_with_logs(query, report_type, source, tone, fmt, log_callback):
|
30 |
agent = GPTResearcher(
|
31 |
query=query,
|
@@ -42,34 +43,51 @@ async def run_research_with_logs(query, report_type, source, tone, fmt, log_call
|
|
42 |
images = agent.get_research_images()
|
43 |
return report, context, sources, images
|
44 |
|
45 |
-
#
|
46 |
if start and query:
|
47 |
-
st.info("π€ Running super deep research...")
|
48 |
-
|
49 |
log_placeholder = st.empty()
|
50 |
-
log_text = ""
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
log_text
|
55 |
-
log_placeholder.code(log_text, language="text")
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
st.success("β
|
62 |
|
|
|
63 |
st.subheader("π Final Report")
|
64 |
st.markdown(report, unsafe_allow_html=True)
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
st.
|
|
|
|
|
69 |
|
|
|
70 |
if images:
|
71 |
-
st.subheader("πΌοΈ
|
72 |
for img in images:
|
73 |
st.image(img, use_column_width=True)
|
74 |
|
|
|
75 |
st.download_button("πΎ Download Report", report, file_name="deep_research.md", mime="text/markdown")
|
|
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
import asyncio
|
|
|
5 |
from gpt_researcher import GPTResearcher
|
6 |
from dotenv import load_dotenv
|
7 |
|
8 |
+
# Apply for async event loop (required for Streamlit + asyncio)
|
9 |
nest_asyncio.apply()
|
10 |
load_dotenv()
|
11 |
|
12 |
+
# Set the Tavily API key (used internally by gpt-researcher)
|
13 |
os.environ["TAVILY_API_KEY"] = "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"
|
14 |
|
15 |
+
# Streamlit UI config
|
16 |
st.set_page_config(page_title="π§ Super Deep Research Agent", layout="wide")
|
17 |
st.title("π GPT-Powered Super Deep Research Assistant")
|
18 |
|
19 |
+
# Sidebar configuration
|
20 |
with st.sidebar:
|
21 |
+
st.header("π Research Configuration")
|
22 |
query = st.text_input("π Research Topic", "Is AI a threat to creative jobs?")
|
23 |
report_type = st.selectbox("π Report Type", ["research_report", "summary", "detailed_report"])
|
24 |
tone = st.selectbox("π£οΈ Tone", ["objective", "persuasive", "informative"])
|
|
|
26 |
output_format = st.selectbox("π Output Format", ["markdown", "text"])
|
27 |
start = st.button("π Start Deep Research")
|
28 |
|
29 |
+
# Async logic
|
30 |
async def run_research_with_logs(query, report_type, source, tone, fmt, log_callback):
|
31 |
agent = GPTResearcher(
|
32 |
query=query,
|
|
|
43 |
images = agent.get_research_images()
|
44 |
return report, context, sources, images
|
45 |
|
46 |
+
# Main research execution
|
47 |
if start and query:
|
48 |
+
st.info("π€ Running super deep research agent...")
|
|
|
49 |
log_placeholder = st.empty()
|
|
|
50 |
|
51 |
+
# Enclosing function to use nonlocal log_text
|
52 |
+
def run_loggable_research():
|
53 |
+
log_text = ""
|
|
|
54 |
|
55 |
+
def stream_log(msg):
|
56 |
+
nonlocal log_text
|
57 |
+
log_text += f"π’ {msg}\n"
|
58 |
+
log_placeholder.code(log_text, language="text")
|
59 |
+
|
60 |
+
return asyncio.run(
|
61 |
+
run_research_with_logs(
|
62 |
+
query,
|
63 |
+
report_type,
|
64 |
+
source_type,
|
65 |
+
tone,
|
66 |
+
output_format,
|
67 |
+
log_callback=stream_log
|
68 |
+
)
|
69 |
+
)
|
70 |
+
|
71 |
+
# Run it
|
72 |
+
report, context, sources, images = run_loggable_research()
|
73 |
|
74 |
+
st.success("β
Research Complete!")
|
75 |
|
76 |
+
# Display report
|
77 |
st.subheader("π Final Report")
|
78 |
st.markdown(report, unsafe_allow_html=True)
|
79 |
|
80 |
+
# Display sources
|
81 |
+
if sources:
|
82 |
+
st.subheader("π Sources")
|
83 |
+
for s in sources:
|
84 |
+
st.markdown(f"- [{s.get('title', 'Untitled')}]({s.get('url', '#')})")
|
85 |
|
86 |
+
# Display images
|
87 |
if images:
|
88 |
+
st.subheader("πΌοΈ Related Images")
|
89 |
for img in images:
|
90 |
st.image(img, use_column_width=True)
|
91 |
|
92 |
+
# Download button
|
93 |
st.download_button("πΎ Download Report", report, file_name="deep_research.md", mime="text/markdown")
|