Ani14 commited on
Commit
151e525
Β·
verified Β·
1 Parent(s): f138bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -52
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 (important for notebooks + event loops)
8
  nest_asyncio.apply()
 
9
 
10
- # Streamlit page config
11
- st.set_page_config(page_title="GPT Researcher Async UI", layout="wide")
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
- # Async wrapper function
24
- async def run_gpt_researcher(query: str, report_type: str):
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
- # Additional context
34
- context = researcher.get_research_context()
35
- costs = researcher.get_costs()
36
- images = researcher.get_research_images()
37
- sources = researcher.get_research_sources()
38
-
39
- return report, context, costs, images, sources
 
40
 
41
- # Main Execution
42
- if run_button and query:
43
- st.info("πŸ€– Autonomous agent is researching... Please wait.")
44
-
45
- # Run async function in Streamlit
46
- report, context, costs, images, sources = asyncio.run(run_gpt_researcher(query, report_type))
 
 
 
 
 
 
 
 
 
 
47
 
48
- st.success("βœ… Research completed!")
 
 
 
49
 
50
- # Show final report
51
  st.subheader("πŸ“„ Final Report")
52
  st.markdown(report, unsafe_allow_html=True)
53
 
54
- # Show sources
55
- if sources:
56
- st.subheader("πŸ“š Sources Used")
57
- for src in sources:
58
- title = src.get("title", "Untitled")
59
- url = src.get("url", "#")
60
- st.markdown(f"- [{title}]({url})")
61
 
62
- # Show research cost
63
- if costs:
64
- st.subheader("πŸ’° Cost Breakdown")
65
- st.json(costs)
66
 
67
- # Show related images
68
  if images:
69
- st.subheader("πŸ–ΌοΈ Related Images")
70
  for img in images:
71
  st.image(img, use_column_width=True)
72
 
73
- # Download button for the report
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")