cryogenic22 commited on
Commit
699d379
·
verified ·
1 Parent(s): 7fb49fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -6
app.py CHANGED
@@ -31,23 +31,67 @@ def get_api_keys():
31
  st.error(f"Error loading API keys: {str(e)}")
32
  return None, None
33
 
 
 
34
  def run_market_research(topic: str, progress_container):
35
  """Run the market research process"""
36
  try:
37
  # Create and run the crew
38
  crew = create_research_crew(topic)
39
 
40
- # Update progress
41
- update_progress(progress_container, 25, "Gathering market data...")
42
- update_progress(progress_container, 50, "Analyzing findings...")
43
- update_progress(progress_container, 75, "Generating report...")
 
 
 
 
 
 
 
44
 
45
  # Execute the crew
46
  result = crew.kickoff()
47
 
48
- # Format and return the result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  update_progress(progress_container, 100, "Report completed!")
50
- return format_json_output(result)
 
 
51
 
52
  except Exception as e:
53
  st.error(f"Error during research: {str(e)}")
 
31
  st.error(f"Error loading API keys: {str(e)}")
32
  return None, None
33
 
34
+ # In app.py
35
+
36
  def run_market_research(topic: str, progress_container):
37
  """Run the market research process"""
38
  try:
39
  # Create and run the crew
40
  crew = create_research_crew(topic)
41
 
42
+ # Update progress for research phase
43
+ update_progress(progress_container, 25, "Gathering market data and research...")
44
+ st.write("🔍 Research Analyst is gathering comprehensive market data...")
45
+
46
+ # Update progress for analysis phase
47
+ update_progress(progress_container, 50, "Analyzing market findings...")
48
+ st.write("📊 Data Analyst is processing market insights...")
49
+
50
+ # Update progress for report generation
51
+ update_progress(progress_container, 75, "Compiling comprehensive report...")
52
+ st.write("✍️ Report Writer is creating the final document...")
53
 
54
  # Execute the crew
55
  result = crew.kickoff()
56
 
57
+ # Get raw text from result
58
+ if hasattr(result, 'raw_output'):
59
+ raw_text = str(result.raw_output)
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)}")