GitsSaikat commited on
Commit
66d7dde
Β·
unverified Β·
1 Parent(s): 31e9175

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -110
app.py CHANGED
@@ -11,18 +11,20 @@ st.set_page_config(
11
  initial_sidebar_state="expanded"
12
  )
13
 
14
- # Load and display logo in sidebar
15
  logo = Image.open('logo.png')
16
- st.sidebar.image(logo, width=200, use_container_width=True)
17
 
18
- # Initialize session state for API keys
19
- if 'api_keys_configured' not in st.session_state:
20
- st.session_state.api_keys_configured = False
21
 
22
- # Custom CSS (previous CSS remains the same)
23
  st.markdown("""
24
  <style>
25
- /* ... previous CSS ... */
 
 
 
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
- # Sidebar for API Configuration
 
 
 
 
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
- if not st.session_state.api_keys_configured:
102
- st.warning("⚠️ Please configure your API keys in the sidebar before proceeding.")
103
- else:
104
- # Title and description
105
- st.title("πŸ” Open DeepResearch")
106
- st.markdown("""
107
- <div style='background-color: #e3f2fd; padding: 1rem; border-radius: 10px; margin-bottom: 2rem;'>
108
- <h4 style='color: #1565C0; margin-bottom: 0.5rem;'>Welcome to the Open DeepResearch!</h4>
109
- <p style='color: #424242;'>
110
- This application helps you conduct comprehensive research on any topic by:
111
- <br>
112
- β€’ Generating relevant search queries<br>
113
- β€’ Analyzing multiple sources<br>
114
- β€’ Synthesizing information into a detailed report
115
- </p>
116
- </div>
117
- """, unsafe_allow_html=True)
118
 
119
- # Main form in a container
120
- with st.container():
121
- col1, col2 = st.columns([2, 1])
122
-
123
- with col1:
124
- with st.form("research_form", clear_on_submit=False):
125
- st.markdown("### Research Parameters")
126
-
127
- user_query = st.text_area(
128
- "Research Query",
129
- placeholder="Enter your research topic or question here...",
130
- help="Be as specific as possible for better results",
131
- height=100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  )
133
-
134
- col_a, col_b = st.columns(2)
135
- with col_a:
136
- iter_limit_input = st.number_input(
137
- "Maximum Iterations",
138
- min_value=1,
139
- max_value=20,
140
- value=10,
141
- help="Higher values mean more thorough research but longer processing time"
142
- )
143
-
144
- submitted = st.form_submit_button("πŸš€ Start Research")
145
-
146
- with col2:
147
- st.markdown("### Tips for Better Results")
148
- st.info("""
149
- β€’ Be specific in your query
150
- β€’ Use clear, focused questions
151
- β€’ Consider including relevant keywords
152
- β€’ Specify time periods if applicable
153
- """)
154
 
155
- # Process and display results
156
- if submitted:
157
- if not user_query.strip():
158
- st.error("⚠️ Please enter a research query before proceeding.")
159
- else:
160
- try:
161
- with st.spinner("πŸ”„ Conducting research... This may take a few minutes..."):
162
- final_report = run_research(user_query, int(iter_limit_input))
163
-
164
- st.markdown("""
165
- <div class='report-container'>
166
- <h3 style='color: #1E88E5; margin-bottom: 1rem;'>πŸ“Š Research Report</h3>
167
- </div>
168
- """, unsafe_allow_html=True)
169
-
170
- # Display the report in tabs
171
- tab1, tab2 = st.tabs(["πŸ“ Formatted Report", "πŸ“„ Raw Text"])
172
-
173
- with tab1:
174
- st.markdown(final_report)
175
-
176
- with tab2:
177
- st.text_area(
178
- label="",
179
- value=final_report,
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
- except Exception as e:
193
- st.error(f"❌ An error occurred during research: {str(e)}")
194
- st.markdown("""
195
- <div style='background-color: #ffebee; padding: 1rem; border-radius: 10px;'>
196
- <p style='color: #c62828;'>Please try again with a different query or contact support if the issue persists.</p>
197
- </div>
198
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
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)