cryogenic22 commited on
Commit
5f3b7c3
·
verified ·
1 Parent(s): e015180

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +129 -118
utils.py CHANGED
@@ -1,7 +1,8 @@
1
  from langchain_openai import ChatOpenAI
2
  import streamlit as st
3
- import json
4
- import re
 
5
 
6
  def update_progress(container, percentage, message=""):
7
  if container:
@@ -153,6 +154,98 @@ def display_report(report_data):
153
  st.error(f"Error displaying report: {str(e)}")
154
 
155
  # Add to utils.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  def apply_report_styling():
158
  return """
@@ -271,84 +364,9 @@ def display_report(report_data):
271
 
272
  # Display metrics dashboard
273
  if 'metrics' in report_data and report_data['metrics']:
274
- st.markdown('<div class="metrics-container">', unsafe_allow_html=True)
275
  st.subheader("📊 Market Metrics Dashboard")
276
- cols = st.columns(3)
277
  metrics = report_data['metrics']
278
-
279
- with cols[0]:
280
- st.metric("Market Size", metrics.get('market_size', 'N/A'))
281
- st.metric("CAGR", metrics.get('cagr', 'N/A'))
282
- with cols[1]:
283
- key_players = metrics.get('key_players', [])
284
- key_players_count = len(key_players) if isinstance(key_players, list) else 'N/A'
285
- st.metric("Market Leader Share", metrics.get('leader_share', 'N/A'))
286
- st.metric("Number of Key Players", key_players_count)
287
- with cols[2]:
288
- st.metric("Key Region", metrics.get('key_regions', 'N/A'))
289
- st.metric("Dominant Segment", metrics.get('dominant_segment', 'N/A'))
290
- st.markdown('</div>', unsafe_allow_html=True)
291
-
292
- # Display key players if available
293
- if isinstance(key_players, list) and key_players:
294
- st.markdown('<div class="key-players">', unsafe_allow_html=True)
295
- st.subheader("🏢 Key Market Players")
296
- cols = st.columns(2)
297
- for i, player in enumerate(key_players):
298
- with cols[i % 2]:
299
- st.markdown(f'<div class="player-card">{player}</div>', unsafe_allow_html=True)
300
- st.markdown('</div>', unsafe_allow_html=True)
301
-
302
- # Display the main report content with enhanced styling
303
- if 'content' in report_data and report_data['content']:
304
- sections = report_data['content'].split('#')
305
- for section in sections:
306
- if section.strip():
307
- # Split into title and content
308
- parts = section.strip().split('\n', 1)
309
- if len(parts) > 1:
310
- title, content = parts
311
- st.markdown(f'<div class="section-box">', unsafe_allow_html=True)
312
- st.markdown(f'## {title.strip()}')
313
- st.markdown(content)
314
- st.markdown('</div>', unsafe_allow_html=True)
315
-
316
- # Display agent outputs in styled expandable sections
317
- if 'agent_outputs' in report_data:
318
- st.markdown('<div class="section-box">', unsafe_allow_html=True)
319
- st.markdown("## 🤖 Detailed Agent Analysis")
320
-
321
- with st.expander("Researcher's Findings"):
322
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
323
- st.markdown(report_data['agent_outputs'].get('researcher', 'No researcher output available'))
324
- st.markdown('</div>', unsafe_allow_html=True)
325
-
326
- with st.expander("Analyst's Insights"):
327
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
328
- st.markdown(report_data['agent_outputs'].get('analyst', 'No analyst output available'))
329
- st.markdown('</div>', unsafe_allow_html=True)
330
-
331
- with st.expander("Writer's Draft"):
332
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
333
- st.markdown(report_data['agent_outputs'].get('writer', 'No writer output available'))
334
- st.markdown('</div>', unsafe_allow_html=True)
335
-
336
- st.markdown('</div>', unsafe_allow_html=True)
337
-
338
- except Exception as e:
339
- st.error(f"Error displaying report: {str(e)}")
340
-
341
- def display_report(report_data):
342
- try:
343
- # Apply custom styling
344
- st.markdown(apply_report_styling(), unsafe_allow_html=True)
345
-
346
- # Display metrics dashboard
347
- if 'metrics' in report_data and report_data['metrics']:
348
- st.markdown('<div class="metrics-container">', unsafe_allow_html=True)
349
- st.subheader("📊 Market Metrics Dashboard")
350
  cols = st.columns(3)
351
- metrics = report_data['metrics']
352
 
353
  with cols[0]:
354
  st.metric("Market Size", metrics.get('market_size', 'N/A'))
@@ -361,56 +379,49 @@ def display_report(report_data):
361
  with cols[2]:
362
  st.metric("Key Region", metrics.get('key_regions', 'N/A'))
363
  st.metric("Dominant Segment", metrics.get('dominant_segment', 'N/A'))
364
- st.markdown('</div>', unsafe_allow_html=True)
365
 
366
- # Display key players if available
367
- if isinstance(key_players, list) and key_players:
368
- st.markdown('<div class="key-players">', unsafe_allow_html=True)
369
- st.subheader("🏢 Key Market Players")
370
- cols = st.columns(2)
371
- for i, player in enumerate(key_players):
372
- with cols[i % 2]:
373
- st.markdown(f'<div class="player-card">{player}</div>', unsafe_allow_html=True)
374
- st.markdown('</div>', unsafe_allow_html=True)
375
 
376
- # Display the main report content with enhanced styling
377
- if 'content' in report_data and report_data['content']:
378
- sections = report_data['content'].split('#')
379
- for section in sections:
380
- if section.strip():
381
- # Split into title and content
382
- parts = section.strip().split('\n', 1)
383
- if len(parts) > 1:
384
- title, content = parts
385
- st.markdown(f'<div class="section-box">', unsafe_allow_html=True)
386
- st.markdown(f'## {title.strip()}')
387
- st.markdown(content)
388
- st.markdown('</div>', unsafe_allow_html=True)
389
 
390
- # Display agent outputs in styled expandable sections
391
  if 'agent_outputs' in report_data:
392
- st.markdown('<div class="section-box">', unsafe_allow_html=True)
393
- st.markdown("## 🤖 Detailed Agent Analysis")
394
 
395
- with st.expander("Researcher's Findings"):
396
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
397
- st.markdown(report_data['agent_outputs'].get('researcher', 'No researcher output available'))
398
- st.markdown('</div>', unsafe_allow_html=True)
399
-
400
- with st.expander("Analyst's Insights"):
401
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
402
- st.markdown(report_data['agent_outputs'].get('analyst', 'No analyst output available'))
403
- st.markdown('</div>', unsafe_allow_html=True)
404
-
405
- with st.expander("Writer's Draft"):
406
- st.markdown('<div class="bullet-points">', unsafe_allow_html=True)
407
- st.markdown(report_data['agent_outputs'].get('writer', 'No writer output available'))
408
- st.markdown('</div>', unsafe_allow_html=True)
409
 
410
- st.markdown('</div>', unsafe_allow_html=True)
 
 
 
 
 
411
 
 
 
 
 
 
 
 
412
  except Exception as e:
413
  st.error(f"Error displaying report: {str(e)}")
 
414
 
415
  def extract_sources(text):
416
  pattern = r'(?:Source|Reference):\s*(.*?)(?:\n|$)'
 
1
  from langchain_openai import ChatOpenAI
2
  import streamlit as st
3
+ import pandas as pd
4
+ import plotly.express as px
5
+ from datetime import datetime
6
 
7
  def update_progress(container, percentage, message=""):
8
  if container:
 
154
  st.error(f"Error displaying report: {str(e)}")
155
 
156
  # Add to utils.py
157
+ def display_market_visualizations(market_data):
158
+ """Display market visualizations using Streamlit"""
159
+ st.subheader("📊 Market Analysis Visualizations")
160
+
161
+ # Market Share Pie Chart
162
+ if 'marketShares' in market_data:
163
+ st.write("### Market Share Distribution")
164
+ share_data = pd.DataFrame(market_data['marketShares'])
165
+ fig_pie = px.pie(share_data,
166
+ values='share',
167
+ names='company',
168
+ title='Market Share Distribution')
169
+ st.plotly_chart(fig_pie, use_container_width=True)
170
+
171
+ # Growth Trend Line Chart
172
+ if 'growthTrend' in market_data:
173
+ st.write("### Growth Trend Analysis")
174
+ growth_data = pd.DataFrame(market_data['growthTrend'])
175
+ fig_line = px.line(growth_data,
176
+ x='year',
177
+ y='growth',
178
+ title='Market Growth Trend')
179
+ st.plotly_chart(fig_line, use_container_width=True)
180
+
181
+ # Regional Distribution Bar Chart
182
+ if 'regionalDistribution' in market_data:
183
+ st.write("### Regional Market Distribution")
184
+ regional_data = pd.DataFrame(market_data['regionalDistribution'])
185
+ fig_bar = px.bar(regional_data,
186
+ x='region',
187
+ y='share',
188
+ title='Regional Market Distribution')
189
+ st.plotly_chart(fig_bar, use_container_width=True)
190
+
191
+ def display_market_tables(market_data):
192
+ """Display market data tables using Streamlit"""
193
+ st.subheader("📋 Detailed Market Analysis")
194
+
195
+ # Key Players Table
196
+ if 'keyPlayers' in market_data:
197
+ st.write("### Key Players Analysis")
198
+ players_df = pd.DataFrame(market_data['keyPlayers'])
199
+ st.dataframe(
200
+ players_df,
201
+ column_config={
202
+ "company": "Company",
203
+ "marketShare": st.column_config.NumberColumn(
204
+ "Market Share (%)",
205
+ format="%.1f%%"
206
+ ),
207
+ "strengths": "Key Strengths",
208
+ "developments": "Recent Developments"
209
+ },
210
+ hide_index=True
211
+ )
212
+
213
+ # Regional Analysis Table
214
+ if 'regionalAnalysis' in market_data:
215
+ st.write("### Regional Market Analysis")
216
+ regional_df = pd.DataFrame(market_data['regionalAnalysis'])
217
+ st.dataframe(
218
+ regional_df,
219
+ column_config={
220
+ "name": "Region",
221
+ "marketSize": "Market Size",
222
+ "growthRate": st.column_config.NumberColumn(
223
+ "Growth Rate (%)",
224
+ format="%.1f%%"
225
+ ),
226
+ "trends": "Key Trends"
227
+ },
228
+ hide_index=True
229
+ )
230
+
231
+ # Technology Adoption Table
232
+ if 'techAdoption' in market_data:
233
+ st.write("### Technology Adoption Analysis")
234
+ tech_df = pd.DataFrame(market_data['techAdoption'])
235
+ st.dataframe(
236
+ tech_df,
237
+ column_config={
238
+ "name": "Technology",
239
+ "adoptionRate": st.column_config.NumberColumn(
240
+ "Adoption Rate (%)",
241
+ format="%.1f%%"
242
+ ),
243
+ "impact": "Impact",
244
+ "outlook": "Future Outlook"
245
+ },
246
+ hide_index=True
247
+ )
248
+
249
 
250
  def apply_report_styling():
251
  return """
 
364
 
365
  # Display metrics dashboard
366
  if 'metrics' in report_data and report_data['metrics']:
 
367
  st.subheader("📊 Market Metrics Dashboard")
 
368
  metrics = report_data['metrics']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  cols = st.columns(3)
 
370
 
371
  with cols[0]:
372
  st.metric("Market Size", metrics.get('market_size', 'N/A'))
 
379
  with cols[2]:
380
  st.metric("Key Region", metrics.get('key_regions', 'N/A'))
381
  st.metric("Dominant Segment", metrics.get('dominant_segment', 'N/A'))
 
382
 
383
+ # Display visualizations
384
+ if 'market_data' in report_data:
385
+ display_market_visualizations(report_data['market_data'])
 
 
 
 
 
 
386
 
387
+ # Display data tables
388
+ if 'market_data' in report_data:
389
+ display_market_tables(report_data['market_data'])
390
+
391
+ # Display main report content
392
+ if 'content' in report_data:
393
+ st.markdown("## 📑 Comprehensive Report")
394
+ st.markdown(report_data['content'])
 
 
 
 
 
395
 
396
+ # Display agent outputs
397
  if 'agent_outputs' in report_data:
398
+ st.markdown("## 🤖 Agent Analysis - Raw Feed")
399
+ tabs = st.tabs(["Researcher", "Analyst", "Writer"])
400
 
401
+ with tabs[0]:
402
+ researcher_data = report_data['agent_outputs'].get('researcher', {})
403
+ st.markdown(f"**Timestamp:** {researcher_data.get('timestamp', 'N/A')}")
404
+ st.markdown(f"**Analysis Type:** {researcher_data.get('analysis_type', 'N/A')}")
405
+ st.markdown("### Raw Output")
406
+ st.markdown(researcher_data.get('raw_output', 'No output available'))
 
 
 
 
 
 
 
 
407
 
408
+ with tabs[1]:
409
+ analyst_data = report_data['agent_outputs'].get('analyst', {})
410
+ st.markdown(f"**Timestamp:** {analyst_data.get('timestamp', 'N/A')}")
411
+ st.markdown(f"**Analysis Type:** {analyst_data.get('analysis_type', 'N/A')}")
412
+ st.markdown("### Raw Output")
413
+ st.markdown(analyst_data.get('raw_output', 'No output available'))
414
 
415
+ with tabs[2]:
416
+ writer_data = report_data['agent_outputs'].get('writer', {})
417
+ st.markdown(f"**Timestamp:** {writer_data.get('timestamp', 'N/A')}")
418
+ st.markdown(f"**Analysis Type:** {writer_data.get('analysis_type', 'N/A')}")
419
+ st.markdown("### Raw Output")
420
+ st.markdown(writer_data.get('raw_output', 'No output available'))
421
+
422
  except Exception as e:
423
  st.error(f"Error displaying report: {str(e)}")
424
+
425
 
426
  def extract_sources(text):
427
  pattern = r'(?:Source|Reference):\s*(.*?)(?:\n|$)'