ericilavia commited on
Commit
e43aba9
·
verified ·
1 Parent(s): 2c55626

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +46 -5
src/streamlit_app.py CHANGED
@@ -1,7 +1,8 @@
1
- import asyncio
2
- import streamlit as st
3
- from typing import Dict, Any, List
4
- from agents import Agent, Runner, trace, set_default_openai_key
 
5
  from firecrawl import FirecrawlApp
6
  from agents.tool import function_tool
7
 
@@ -38,4 +39,44 @@ with st.sidebar:
38
  st.session_state.firecrawl_api_key = firecrawl_api_key
39
  set_default_openai_key(firecrawl_api_key)
40
 
41
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio # This will helpus to handle tasks without blocking execution
2
+ import streamlit as st # Build the web application
3
+ from typing import Dict, Any, List
4
+ from agents import Agent, Runner, trace
5
+ from agents import set_default_openai_key
6
  from firecrawl import FirecrawlApp
7
  from agents.tool import function_tool
8
 
 
39
  st.session_state.firecrawl_api_key = firecrawl_api_key
40
  set_default_openai_key(firecrawl_api_key)
41
 
42
+ st.title("Openai Deep Research Agent")
43
+ st.markdown("This openai agent from openi agent SDK performs deep search on any topic")
44
+
45
+ reasearch_topic = st.text_input("Enter research topic: ")
46
+
47
+ @function_tool
48
+ async def deep_research(query: str, max_depth: int, time_limit: int, max_urls: int):
49
+ """
50
+ Perform comprehensive web research using Firecrawl's deep research endpoint.
51
+ """
52
+
53
+ try:
54
+ firecrawl_app = FirecrawlApp(api_key = st.session_state.firecrawl_api_key)
55
+ params = {
56
+ "maxDepth": max_depth,
57
+ "timeLimit": time_limit,
58
+ "maxUrls": max_urls
59
+ }
60
+
61
+ def on_activity(activity):
62
+ st.write(f"[{activity['type']}]{activity['message']}")
63
+
64
+ with st.spinner("Performing Deep Research..."):
65
+ resp = firecrawl_app.deep_research(
66
+ query = query,
67
+ param = param,
68
+ on_activity = on_activity
69
+ )
70
+ return {
71
+ "success" : True,
72
+ "final_analysis" : resp["data"]["finalAnalysis"]
73
+ "sources_count": len(resp["data"]["sources"]),
74
+ "sources":resp["data"]["sources"]
75
+ }
76
+ except Exception as e:
77
+ st.error(f"Deep Research Error: {str(e)}")
78
+ return {
79
+ "error" : str(e),
80
+ "success" : False
81
+ }
82
+