cryogenic22 commited on
Commit
20e7e83
·
verified ·
1 Parent(s): 9548bae

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +55 -9
utils.py CHANGED
@@ -141,6 +141,9 @@ def process_crew_output(crew_result, topic):
141
  'analysis_type': 'Report Writing'
142
  }
143
  }
 
 
 
144
 
145
  # Extract individual agent outputs from crew_result
146
  if hasattr(crew_result, 'tasks'):
@@ -151,12 +154,41 @@ def process_crew_output(crew_result, topic):
151
  agent_outputs['analyst']['raw_output'] = task.output if task.output else "No analysis output available"
152
  elif 'writer' in task.agent.role.lower():
153
  agent_outputs['writer']['raw_output'] = task.output if task.output else "No writer output available"
154
-
155
- # Get base report
156
- base_report = str(crew_result)
157
-
158
- # Rest of the function remains the same...
159
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  return {
161
  'metrics': metrics,
162
  'content': enhanced_content,
@@ -167,12 +199,26 @@ def process_crew_output(crew_result, topic):
167
 
168
  except Exception as e:
169
  st.error(f"Error processing report: {str(e)}")
 
170
  return {
171
- 'metrics': {},
 
 
 
 
 
 
 
172
  'content': "Error generating report content",
173
- 'raw': str(crew_result),
174
  'agent_outputs': agent_outputs,
175
- 'market_data': {}
 
 
 
 
 
 
176
  }
177
 
178
  def extract_market_data(text):
 
141
  'analysis_type': 'Report Writing'
142
  }
143
  }
144
+
145
+ # Get base report
146
+ base_report = str(crew_result) if crew_result else "No report generated"
147
 
148
  # Extract individual agent outputs from crew_result
149
  if hasattr(crew_result, 'tasks'):
 
154
  agent_outputs['analyst']['raw_output'] = task.output if task.output else "No analysis output available"
155
  elif 'writer' in task.agent.role.lower():
156
  agent_outputs['writer']['raw_output'] = task.output if task.output else "No writer output available"
157
+
158
+ # Extract metrics with error handling
159
+ try:
160
+ metrics = extract_metrics(base_report)
161
+ except Exception as e:
162
+ st.warning(f"Warning extracting metrics: {str(e)}")
163
+ metrics = {
164
+ 'market_size': 'N/A',
165
+ 'cagr': 'N/A',
166
+ 'leader_share': 'N/A',
167
+ 'key_players': 'N/A',
168
+ 'key_regions': 'N/A',
169
+ 'dominant_segment': 'N/A'
170
+ }
171
+
172
+ # Generate enhanced report content
173
+ try:
174
+ enhanced_content = enhance_report_with_gpt4(base_report, topic)
175
+ except Exception as e:
176
+ st.warning(f"Warning enhancing report: {str(e)}")
177
+ enhanced_content = base_report
178
+
179
+ # Extract market data
180
+ try:
181
+ market_data = extract_market_data(base_report)
182
+ except Exception as e:
183
+ st.warning(f"Warning extracting market data: {str(e)}")
184
+ market_data = {
185
+ "marketShares": [],
186
+ "growthTrend": [],
187
+ "regionalDistribution": [],
188
+ "techAdoption": [],
189
+ "keyPlayers": []
190
+ }
191
+
192
  return {
193
  'metrics': metrics,
194
  'content': enhanced_content,
 
199
 
200
  except Exception as e:
201
  st.error(f"Error processing report: {str(e)}")
202
+ # Return default structure
203
  return {
204
+ 'metrics': {
205
+ 'market_size': 'N/A',
206
+ 'cagr': 'N/A',
207
+ 'leader_share': 'N/A',
208
+ 'key_players': 'N/A',
209
+ 'key_regions': 'N/A',
210
+ 'dominant_segment': 'N/A'
211
+ },
212
  'content': "Error generating report content",
213
+ 'raw': str(crew_result) if crew_result else "No report generated",
214
  'agent_outputs': agent_outputs,
215
+ 'market_data': {
216
+ "marketShares": [],
217
+ "growthTrend": [],
218
+ "regionalDistribution": [],
219
+ "techAdoption": [],
220
+ "keyPlayers": []
221
+ }
222
  }
223
 
224
  def extract_market_data(text):