Spaces:
Running
Running
GitsSaikat
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,20 @@ st.set_page_config(
|
|
11 |
initial_sidebar_state="expanded"
|
12 |
)
|
13 |
|
14 |
-
# Load
|
15 |
logo = Image.open('logo.png')
|
16 |
-
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
st.session_state.api_keys_configured = False
|
21 |
|
22 |
-
# Custom CSS
|
23 |
st.markdown("""
|
24 |
<style>
|
25 |
-
|
|
|
|
|
|
|
26 |
.api-container {
|
27 |
background-color: #f8f9fa;
|
28 |
padding: 1.5rem;
|
@@ -38,10 +40,14 @@ st.markdown("""
|
|
38 |
</style>
|
39 |
""", unsafe_allow_html=True)
|
40 |
|
41 |
-
#
|
|
|
|
|
|
|
|
|
42 |
with st.sidebar:
|
|
|
43 |
st.markdown("### βοΈ API Configuration")
|
44 |
-
st.info("Please configure your API keys before starting research.")
|
45 |
|
46 |
with st.expander("Configure API Keys", expanded=not st.session_state.api_keys_configured):
|
47 |
api_form = st.form("api_keys_form")
|
@@ -71,7 +77,6 @@ with st.sidebar:
|
|
71 |
if not all([openrouter_key, serpapi_key, jina_key]):
|
72 |
st.error("β All API keys are required!")
|
73 |
else:
|
74 |
-
# Store API keys in session state
|
75 |
st.session_state.openrouter_key = openrouter_key
|
76 |
st.session_state.serpapi_key = serpapi_key
|
77 |
st.session_state.jina_key = jina_key
|
@@ -82,7 +87,6 @@ with st.sidebar:
|
|
82 |
if st.session_state.api_keys_configured:
|
83 |
st.success("β
API Keys configured")
|
84 |
|
85 |
-
# Add links to get API keys
|
86 |
st.markdown("### π Get API Keys")
|
87 |
st.markdown("""
|
88 |
- [OpenRouter API Key](https://openrouter.ai/keys)
|
@@ -90,116 +94,125 @@ with st.sidebar:
|
|
90 |
- [Jina API Key](https://jina.ai/api-key)
|
91 |
""")
|
92 |
|
93 |
-
def run_research(user_query, iteration_limit):
|
94 |
-
# Set API keys in the research module
|
95 |
deep_research.OPENROUTER_API_KEY = st.session_state.openrouter_key
|
96 |
deep_research.SERPAPI_API_KEY = st.session_state.serpapi_key
|
97 |
deep_research.JINA_API_KEY = st.session_state.jina_key
|
98 |
-
return asyncio.run(deep_research.research_flow(user_query, iteration_limit))
|
99 |
|
100 |
# Main content
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
β’ Synthesizing information into a detailed report
|
115 |
-
</p>
|
116 |
-
</div>
|
117 |
-
""", unsafe_allow_html=True)
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
with
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
)
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
β’ Consider including relevant keywords
|
152 |
-
β’ Specify time periods if applicable
|
153 |
-
""")
|
154 |
|
155 |
-
|
156 |
-
if
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
<
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
height=500,
|
181 |
-
help="You can copy the raw text from here"
|
182 |
-
)
|
183 |
-
|
184 |
-
# Download button for the report
|
185 |
-
st.download_button(
|
186 |
-
label="π₯ Download Report",
|
187 |
-
data=final_report,
|
188 |
-
file_name="research_report.txt",
|
189 |
-
mime="text/plain"
|
190 |
)
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
# Footer
|
201 |
st.markdown("""
|
202 |
<div style='text-align: center; color: #666; padding: 2rem;'>
|
203 |
<p>Built by GitsSaikat β€οΈ</p>
|
204 |
</div>
|
205 |
-
""", unsafe_allow_html=True)
|
|
|
11 |
initial_sidebar_state="expanded"
|
12 |
)
|
13 |
|
14 |
+
# Load images
|
15 |
logo = Image.open('logo.png')
|
16 |
+
banner = Image.open('banner.png')
|
17 |
|
18 |
+
# Display banner at top
|
19 |
+
# st.image(banner, use_container_width=True)
|
|
|
20 |
|
21 |
+
# Custom CSS
|
22 |
st.markdown("""
|
23 |
<style>
|
24 |
+
.stImage > img {
|
25 |
+
border-radius: 10px;
|
26 |
+
margin-bottom: 2rem;
|
27 |
+
}
|
28 |
.api-container {
|
29 |
background-color: #f8f9fa;
|
30 |
padding: 1.5rem;
|
|
|
40 |
</style>
|
41 |
""", unsafe_allow_html=True)
|
42 |
|
43 |
+
# Initialize session state
|
44 |
+
if 'api_keys_configured' not in st.session_state:
|
45 |
+
st.session_state.api_keys_configured = False
|
46 |
+
|
47 |
+
# Sidebar configuration
|
48 |
with st.sidebar:
|
49 |
+
st.image(logo, width=200, use_container_width=True)
|
50 |
st.markdown("### βοΈ API Configuration")
|
|
|
51 |
|
52 |
with st.expander("Configure API Keys", expanded=not st.session_state.api_keys_configured):
|
53 |
api_form = st.form("api_keys_form")
|
|
|
77 |
if not all([openrouter_key, serpapi_key, jina_key]):
|
78 |
st.error("β All API keys are required!")
|
79 |
else:
|
|
|
80 |
st.session_state.openrouter_key = openrouter_key
|
81 |
st.session_state.serpapi_key = serpapi_key
|
82 |
st.session_state.jina_key = jina_key
|
|
|
87 |
if st.session_state.api_keys_configured:
|
88 |
st.success("β
API Keys configured")
|
89 |
|
|
|
90 |
st.markdown("### π Get API Keys")
|
91 |
st.markdown("""
|
92 |
- [OpenRouter API Key](https://openrouter.ai/keys)
|
|
|
94 |
- [Jina API Key](https://jina.ai/api-key)
|
95 |
""")
|
96 |
|
97 |
+
def run_research(user_query, iteration_limit, search_limit):
|
|
|
98 |
deep_research.OPENROUTER_API_KEY = st.session_state.openrouter_key
|
99 |
deep_research.SERPAPI_API_KEY = st.session_state.serpapi_key
|
100 |
deep_research.JINA_API_KEY = st.session_state.jina_key
|
101 |
+
return asyncio.run(deep_research.research_flow(user_query, iteration_limit, search_limit))
|
102 |
|
103 |
# Main content
|
104 |
+
st.title("π Open DeepResearch")
|
105 |
+
st.markdown("""
|
106 |
+
<div style='background-color: #5dade2; padding: 1rem; border-radius: 10px; margin-bottom: 2rem;'>
|
107 |
+
<h4 style='color: #1565C0; margin-bottom: 0.5rem;'>Welcome to the Open DeepResearch!</h4>
|
108 |
+
<p style='color: #424242;'>
|
109 |
+
This application helps you conduct comprehensive research on any topic by:
|
110 |
+
<br>
|
111 |
+
β’ Generating relevant search queries<br>
|
112 |
+
β’ Analyzing multiple sources<br>
|
113 |
+
β’ Synthesizing information into a detailed report
|
114 |
+
</p>
|
115 |
+
</div>
|
116 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
117 |
|
118 |
+
with st.container():
|
119 |
+
col1, col2 = st.columns([2, 1])
|
120 |
+
|
121 |
+
with col1:
|
122 |
+
with st.form("research_form", clear_on_submit=False):
|
123 |
+
st.markdown("### Research Parameters")
|
124 |
+
|
125 |
+
user_query = st.text_area(
|
126 |
+
"Research Query",
|
127 |
+
placeholder="Enter your research topic or question here...",
|
128 |
+
help="Be as specific as possible for better results",
|
129 |
+
height=100,
|
130 |
+
disabled=not st.session_state.api_keys_configured
|
131 |
+
)
|
132 |
+
|
133 |
+
col_a, col_b = st.columns(2)
|
134 |
+
with col_a:
|
135 |
+
iter_limit_input = st.number_input(
|
136 |
+
"Maximum Iterations",
|
137 |
+
min_value=1,
|
138 |
+
max_value=20,
|
139 |
+
value=10,
|
140 |
+
help="Higher values mean more thorough research but longer processing time",
|
141 |
+
disabled=not st.session_state.api_keys_configured
|
142 |
+
)
|
143 |
+
|
144 |
+
with col_b:
|
145 |
+
search_limit_input = st.number_input(
|
146 |
+
"Results Per Search",
|
147 |
+
min_value=1,
|
148 |
+
max_value=20,
|
149 |
+
value=5,
|
150 |
+
help="Number of results per search. Lower values reduce token usage",
|
151 |
+
disabled=not st.session_state.api_keys_configured
|
152 |
)
|
153 |
+
|
154 |
+
submitted = st.form_submit_button(
|
155 |
+
"π Start Research",
|
156 |
+
disabled=not st.session_state.api_keys_configured
|
157 |
+
)
|
158 |
+
|
159 |
+
with col2:
|
160 |
+
st.markdown("### Tips for Better Results")
|
161 |
+
st.info("""
|
162 |
+
β’ Be specific in your query
|
163 |
+
β’ Use clear, focused questions
|
164 |
+
β’ Consider including relevant keywords
|
165 |
+
β’ Specify time periods if applicable
|
166 |
+
β’ Lower search results reduce token usage
|
167 |
+
""")
|
168 |
+
|
169 |
+
if not st.session_state.api_keys_configured:
|
170 |
+
st.warning("β οΈ Please configure your API keys in the sidebar to enable research.")
|
|
|
|
|
|
|
171 |
|
172 |
+
if submitted and st.session_state.api_keys_configured:
|
173 |
+
if not user_query.strip():
|
174 |
+
st.error("β οΈ Please enter a research query before proceeding.")
|
175 |
+
else:
|
176 |
+
try:
|
177 |
+
with st.spinner("π Conducting research... This may take a few minutes..."):
|
178 |
+
final_report = run_research(user_query, int(iter_limit_input), int(search_limit_input))
|
179 |
+
|
180 |
+
st.markdown("""
|
181 |
+
<div class='report-container'>
|
182 |
+
<h3 style='color: #1E88E5; margin-bottom: 1rem;'>π Research Report</h3>
|
183 |
+
</div>
|
184 |
+
""", unsafe_allow_html=True)
|
185 |
+
|
186 |
+
tab1, tab2 = st.tabs(["π Formatted Report", "π Raw Text"])
|
187 |
+
|
188 |
+
with tab1:
|
189 |
+
st.markdown(final_report)
|
190 |
+
|
191 |
+
with tab2:
|
192 |
+
st.text_area(
|
193 |
+
label="",
|
194 |
+
value=final_report,
|
195 |
+
height=500,
|
196 |
+
help="You can copy the raw text from here"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
)
|
198 |
+
|
199 |
+
st.download_button(
|
200 |
+
label="π₯ Download Report",
|
201 |
+
data=final_report,
|
202 |
+
file_name="research_report.txt",
|
203 |
+
mime="text/plain"
|
204 |
+
)
|
205 |
+
|
206 |
+
except Exception as e:
|
207 |
+
st.error(f"β An error occurred during research: {str(e)}")
|
208 |
+
st.markdown("""
|
209 |
+
<div style='background-color: #ffebee; padding: 1rem; border-radius: 10px;'>
|
210 |
+
<p style='color: #c62828;'>Please try again with a different query or contact support if the issue persists.</p>
|
211 |
+
</div>
|
212 |
+
""", unsafe_allow_html=True)
|
213 |
|
|
|
214 |
st.markdown("""
|
215 |
<div style='text-align: center; color: #666; padding: 2rem;'>
|
216 |
<p>Built by GitsSaikat β€οΈ</p>
|
217 |
</div>
|
218 |
+
""", unsafe_allow_html=True)
|