cryogenic22 commited on
Commit
44fed4e
·
verified ·
1 Parent(s): b7b447f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +170 -109
app.py CHANGED
@@ -60,44 +60,95 @@ def run_market_research(topic: str, progress_container):
60
  else:
61
  raw_text = str(result)
62
 
63
- # Process the raw text into structured sections
64
  sections = raw_text.split('===')
65
- processed_report = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
 
67
  for section in sections:
68
  if not section.strip():
69
  continue
70
 
71
- # Split into section name and content
72
  parts = section.strip().split('\n', 1)
73
  if len(parts) == 2:
74
  section_name, content = parts
75
- processed_report[section_name.strip()] = content.strip()
76
-
77
- # Create final report structure
78
- final_report = {
79
- 'exec_summary': processed_report.get('EXECUTIVE SUMMARY', ''),
80
- 'market_analysis': processed_report.get('MARKET ANALYSIS', ''),
81
- 'future_outlook': processed_report.get('FUTURE OUTLOOK', ''),
82
- 'appendices': processed_report.get('APPENDICES', ''),
83
- 'sources': [
84
- source.strip()
85
- for source in processed_report.get('APPENDICES', '').split('\n')
86
- if source.strip().startswith('-')
87
- ]
88
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  # Update final progress
91
  update_progress(progress_container, 100, "Report completed!")
92
  st.success("✨ Market research report generated successfully!")
93
 
94
- return final_report
95
 
96
  except Exception as e:
97
  st.error(f"Error during research: {str(e)}")
98
  print(f"Full error details: {str(e)}") # For debugging
99
- return None
100
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  def main():
102
  st.title("🤖 AI Market Research Generator")
103
 
@@ -152,120 +203,130 @@ def main():
152
  report = st.session_state.current_report
153
  topic = st.session_state.current_topic
154
 
155
- # Display AI Disclaimer
156
- st.info("⚠️ This report was generated using AI. Please verify critical information independently.")
157
-
158
- try:
159
- # Executive Summary Section
160
- st.header(f"📊 Market Research Report: {topic}")
161
-
162
- with st.expander("Executive Summary", expanded=True):
163
- st.subheader("Key Findings")
164
- st.write(report.get('exec_summary', {}).get('summary', ''))
165
-
166
- st.subheader("Market Highlights")
167
- st.write(report.get('exec_summary', {}).get('market_highlights', ''))
168
-
169
- st.subheader("Strategic Implications")
170
- st.write(report.get('exec_summary', {}).get('strategic_implications', ''))
171
-
172
- st.subheader("Key Recommendations")
173
- st.write(report.get('exec_summary', {}).get('recommendations', ''))
174
-
175
- # Market Analysis Section
176
- with st.expander("Detailed Market Analysis", expanded=False):
177
- st.subheader("Market Overview")
178
- st.write(report.get('market_analysis', {}).get('overview', ''))
179
-
180
- st.subheader("Industry Dynamics")
181
- st.write(report.get('market_analysis', {}).get('dynamics', ''))
182
-
183
- st.subheader("Competitive Landscape")
184
- st.write(report.get('market_analysis', {}).get('competitive_landscape', ''))
185
-
186
- st.subheader("Strategic Analysis")
187
- st.write(report.get('market_analysis', {}).get('strategic_analysis', ''))
188
-
189
- # Future Outlook Section
190
- with st.expander("Future Outlook", expanded=False):
191
- st.write(report.get('future_outlook', ''))
192
-
193
- # Key Metrics Section
194
- with st.expander("Key Metrics", expanded=False):
195
- metrics = report.get('metrics', {})
196
- col1, col2 = st.columns(2)
197
-
198
- with col1:
199
- st.metric("Market Size", metrics.get('market_size', 'N/A'))
200
- st.metric("Growth Rate", metrics.get('growth_rate', 'N/A'))
201
-
202
- with col2:
203
- st.metric("Market Share", metrics.get('market_shares', 'N/A'))
204
- st.metric("Other Metrics", metrics.get('key_metrics', 'N/A'))
205
-
206
- # Sources Section
207
- with st.expander("Sources & Appendices", expanded=False):
208
- st.subheader("Sources")
209
- sources = report.get('sources', [])
210
- for source in sources:
211
- st.markdown(f"• {source}")
212
-
213
- st.subheader("Appendices")
214
- st.write(report.get('appendices', ''))
215
-
216
- # Download Full Report
217
- st.download_button(
218
- "Download Complete Report",
219
- data=f"""
220
- # Market Research Report: {topic}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
  ## Executive Summary
223
- {report.get('exec_summary', {}).get('summary', '')}
224
 
225
  ### Market Highlights
226
- {report.get('exec_summary', {}).get('market_highlights', '')}
227
 
228
  ### Strategic Implications
229
- {report.get('exec_summary', {}).get('strategic_implications', '')}
230
 
231
  ### Key Recommendations
232
- {report.get('exec_summary', {}).get('recommendations', '')}
233
 
234
- ## Detailed Market Analysis
235
 
236
  ### Market Overview
237
- {report.get('market_analysis', {}).get('overview', '')}
238
 
239
  ### Industry Dynamics
240
- {report.get('market_analysis', {}).get('dynamics', '')}
241
 
242
  ### Competitive Landscape
243
- {report.get('market_analysis', {}).get('competitive_landscape', '')}
244
 
245
  ### Strategic Analysis
246
- {report.get('market_analysis', {}).get('strategic_analysis', '')}
247
 
248
  ## Future Outlook
249
- {report.get('future_outlook', '')}
250
-
251
- ## Key Metrics
252
- - Market Size: {report.get('metrics', {}).get('market_size', 'N/A')}
253
- - Growth Rate: {report.get('metrics', {}).get('growth_rate', 'N/A')}
254
- - Market Share: {report.get('metrics', {}).get('market_shares', 'N/A')}
255
 
256
  ## Sources
257
- {chr(10).join([f"• {source}" for source in report.get('sources', [])])}
258
-
259
- ## Appendices
260
- {report.get('appendices', '')}
261
  """,
262
- file_name=f"{topic.lower().replace(' ', '_')}_market_research.md",
263
- mime="text/markdown"
264
- )
265
-
 
266
  except Exception as e:
267
  st.error(f"Error displaying report: {str(e)}")
268
  st.write("Raw report data:", report) # Debug information
 
269
 
270
  if __name__ == "__main__":
271
  main()
 
60
  else:
61
  raw_text = str(result)
62
 
63
+ # Process the raw text into sections
64
  sections = raw_text.split('===')
65
+ processed_report = {
66
+ 'exec_summary': {
67
+ 'summary': '',
68
+ 'market_highlights': '',
69
+ 'strategic_implications': '',
70
+ 'recommendations': ''
71
+ },
72
+ 'market_analysis': {
73
+ 'overview': '',
74
+ 'dynamics': '',
75
+ 'competitive_landscape': '',
76
+ 'strategic_analysis': ''
77
+ },
78
+ 'future_outlook': '',
79
+ 'appendices': '',
80
+ 'sources': []
81
+ }
82
 
83
+ # Process each section
84
  for section in sections:
85
  if not section.strip():
86
  continue
87
 
 
88
  parts = section.strip().split('\n', 1)
89
  if len(parts) == 2:
90
  section_name, content = parts
91
+ section_name = section_name.strip().upper()
92
+ content = content.strip()
93
+
94
+ if section_name == 'EXECUTIVE SUMMARY':
95
+ # Process executive summary
96
+ processed_report['exec_summary']['summary'] = content
97
+ # Extract main points for highlights
98
+ if '##' in content:
99
+ highlights = content.split('##')[1:]
100
+ processed_report['exec_summary']['market_highlights'] = highlights[0] if highlights else ''
101
+ processed_report['exec_summary']['strategic_implications'] = highlights[1] if len(highlights) > 1 else ''
102
+ processed_report['exec_summary']['recommendations'] = highlights[2] if len(highlights) > 2 else ''
103
+
104
+ elif section_name == 'MARKET ANALYSIS':
105
+ # Process market analysis section
106
+ subsections = content.split('##')
107
+ processed_report['market_analysis']['overview'] = subsections[0]
108
+ for subsection in subsections[1:]:
109
+ if 'dynamics' in subsection.lower():
110
+ processed_report['market_analysis']['dynamics'] = subsection
111
+ elif 'competitive' in subsection.lower():
112
+ processed_report['market_analysis']['competitive_landscape'] = subsection
113
+ elif 'strategic' in subsection.lower():
114
+ processed_report['market_analysis']['strategic_analysis'] = subsection
115
+
116
+ elif section_name == 'FUTURE OUTLOOK':
117
+ processed_report['future_outlook'] = content
118
+
119
+ elif section_name == 'APPENDICES':
120
+ processed_report['appendices'] = content
121
+ # Extract sources from appendices
122
+ sources = [line.strip() for line in content.split('\n')
123
+ if line.strip().startswith('-') or line.strip().startswith('•')]
124
+ processed_report['sources'] = sources
125
 
126
  # Update final progress
127
  update_progress(progress_container, 100, "Report completed!")
128
  st.success("✨ Market research report generated successfully!")
129
 
130
+ return processed_report
131
 
132
  except Exception as e:
133
  st.error(f"Error during research: {str(e)}")
134
  print(f"Full error details: {str(e)}") # For debugging
135
+ return {
136
+ 'exec_summary': {
137
+ 'summary': 'Error processing report',
138
+ 'market_highlights': '',
139
+ 'strategic_implications': '',
140
+ 'recommendations': ''
141
+ },
142
+ 'market_analysis': {
143
+ 'overview': str(raw_text) if 'raw_text' in locals() else 'Error processing analysis',
144
+ 'dynamics': '',
145
+ 'competitive_landscape': '',
146
+ 'strategic_analysis': ''
147
+ },
148
+ 'future_outlook': '',
149
+ 'appendices': '',
150
+ 'sources': []
151
+ }
152
  def main():
153
  st.title("🤖 AI Market Research Generator")
154
 
 
203
  report = st.session_state.current_report
204
  topic = st.session_state.current_topic
205
 
206
+ st.markdown("""
207
+ <div class="report-container">
208
+ <!-- AI Disclaimer -->
209
+ <div class="disclaimer">
210
+ ⚠️ This report was generated using AI. While we strive for accuracy,
211
+ please verify critical information independently before making decisions.
212
+ </div>
213
+
214
+ <!-- Report Title -->
215
+ <h1 class="section-heading">📊 Market Research Report: {}</h1>
216
+
217
+ <!-- Executive Summary -->
218
+ <div class="report-section executive-summary">
219
+ <h2 class="section-heading">Executive Summary</h2>
220
+ <div class="content-block">{}</div>
221
+
222
+ <h3 class="subsection-heading">Key Market Highlights</h3>
223
+ <div class="content-block">{}</div>
224
+
225
+ <h3 class="subsection-heading">Strategic Implications</h3>
226
+ <div class="content-block">{}</div>
227
+
228
+ <h3 class="subsection-heading">Recommendations</h3>
229
+ <div class="content-block">{}</div>
230
+ </div>
231
+
232
+ <!-- Market Analysis -->
233
+ <div class="report-section market-analysis">
234
+ <h2 class="section-heading">Market Analysis</h2>
235
+
236
+ <h3 class="subsection-heading">Market Overview</h3>
237
+ <div class="content-block">{}</div>
238
+
239
+ <h3 class="subsection-heading">Industry Dynamics</h3>
240
+ <div class="content-block">{}</div>
241
+
242
+ <h3 class="subsection-heading">Competitive Landscape</h3>
243
+ <div class="content-block">{}</div>
244
+
245
+ <h3 class="subsection-heading">Strategic Analysis</h3>
246
+ <div class="content-block">{}</div>
247
+ </div>
248
+
249
+ <!-- Future Outlook -->
250
+ <div class="report-section future-outlook">
251
+ <h2 class="section-heading">Future Outlook</h2>
252
+ <div class="content-block">{}</div>
253
+ </div>
254
+
255
+ <!-- Sources -->
256
+ <div class="report-section sources-section">
257
+ <h2 class="section-heading">Sources</h2>
258
+ {}
259
+ </div>
260
+ </div>
261
+ """.format(
262
+ topic,
263
+ report['exec_summary']['summary'],
264
+ report['exec_summary']['market_highlights'],
265
+ report['exec_summary']['strategic_implications'],
266
+ report['exec_summary']['recommendations'],
267
+ report['market_analysis']['overview'],
268
+ report['market_analysis']['dynamics'],
269
+ report['market_analysis']['competitive_landscape'],
270
+ report['market_analysis']['strategic_analysis'],
271
+ report['future_outlook'],
272
+ '\n'.join([f'<div class="source-item">• {source}</div>' for source in report['sources']])
273
+ ), unsafe_allow_html=True)
274
+
275
+ # Download button with custom styling
276
+ st.markdown("""
277
+ <div style="text-align: center; margin-top: 30px;">
278
+ <button class="download-button" onclick="alert('Use the Streamlit download button below')">
279
+ 📥 Download Complete Report
280
+ </button>
281
+ </div>
282
+ """, unsafe_allow_html=True)
283
+
284
+ # Actual download functionality (hidden but functional)
285
+ st.download_button(
286
+ "Download Report",
287
+ data=f"""# Market Research Report: {topic}
288
 
289
  ## Executive Summary
290
+ {report['exec_summary']['summary']}
291
 
292
  ### Market Highlights
293
+ {report['exec_summary']['market_highlights']}
294
 
295
  ### Strategic Implications
296
+ {report['exec_summary']['strategic_implications']}
297
 
298
  ### Key Recommendations
299
+ {report['exec_summary']['recommendations']}
300
 
301
+ ## Market Analysis
302
 
303
  ### Market Overview
304
+ {report['market_analysis']['overview']}
305
 
306
  ### Industry Dynamics
307
+ {report['market_analysis']['dynamics']}
308
 
309
  ### Competitive Landscape
310
+ {report['market_analysis']['competitive_landscape']}
311
 
312
  ### Strategic Analysis
313
+ {report['market_analysis']['strategic_analysis']}
314
 
315
  ## Future Outlook
316
+ {report['future_outlook']}
 
 
 
 
 
317
 
318
  ## Sources
319
+ {chr(10).join([f"• {source}" for source in report['sources']])}
 
 
 
320
  """,
321
+ file_name=f"{topic.lower().replace(' ', '_')}_market_research.md",
322
+ mime="text/markdown",
323
+ key='download_button',
324
+ help="Click to download the complete report",
325
+ )
326
  except Exception as e:
327
  st.error(f"Error displaying report: {str(e)}")
328
  st.write("Raw report data:", report) # Debug information
329
+
330
 
331
  if __name__ == "__main__":
332
  main()