cryogenic22 commited on
Commit
5da984d
·
verified ·
1 Parent(s): b54644d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -66
app.py CHANGED
@@ -39,44 +39,49 @@ def run_market_research(topic: str, progress_container):
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 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
 
@@ -85,70 +90,59 @@ def run_market_research(topic: str, progress_container):
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
 
 
39
  # Create and run the crew
40
  crew = create_research_crew(topic)
41
 
42
+ # Update progress and show what's happening
43
+ update_progress(progress_container, 25, "Gathering market data...")
44
  st.write("🔍 Research Analyst is gathering comprehensive market data...")
45
 
46
+ update_progress(progress_container, 50, "Analyzing findings...")
 
47
  st.write("📊 Data Analyst is processing market insights...")
48
 
49
+ update_progress(progress_container, 75, "Generating report...")
 
50
  st.write("✍️ Report Writer is creating the final document...")
51
 
52
+ # Execute the crew and get result
53
  result = crew.kickoff()
54
 
55
+ # Debug print
56
+ st.write("Debug - Raw Result:", result)
57
+
58
  # Get raw text from result
59
  if hasattr(result, 'raw_output'):
60
  raw_text = str(result.raw_output)
61
  else:
62
  raw_text = str(result)
63
 
64
+ # Debug print
65
+ st.write("Debug - Raw Text:", raw_text[:500]) # Show first 500 chars
66
+
67
+ # Split the text into sections
68
  sections = raw_text.split('===')
69
+
70
+ # Initialize the processed report structure
71
  processed_report = {
72
  'exec_summary': {
73
+ 'summary': "Executive summary not available",
74
+ 'market_highlights': "Highlights not available",
75
+ 'strategic_implications': "Implications not available",
76
+ 'recommendations': "Recommendations not available"
77
  },
78
  'market_analysis': {
79
+ 'overview': "Overview not available",
80
+ 'dynamics': "Industry dynamics not available",
81
+ 'competitive_landscape': "Competitive analysis not available",
82
+ 'strategic_analysis': "Strategic analysis not available"
83
  },
84
+ 'future_outlook': "Future outlook not available",
 
85
  'sources': []
86
  }
87
 
 
90
  if not section.strip():
91
  continue
92
 
93
+ # Split section into title and content
94
  parts = section.strip().split('\n', 1)
95
  if len(parts) == 2:
96
+ section_name = parts[0].strip().upper()
97
+ content = parts[1].strip()
 
98
 
99
+ # Debug print
100
+ st.write(f"Debug - Processing section: {section_name}")
 
 
 
 
 
 
 
101
 
102
+ if "EXECUTIVE SUMMARY" in section_name:
 
103
  subsections = content.split('##')
104
+ processed_report['exec_summary']['summary'] = subsections[0].strip()
105
+
106
  for subsection in subsections[1:]:
107
+ if 'Market Highlights' in subsection:
108
+ processed_report['exec_summary']['market_highlights'] = subsection.split('\n', 1)[1].strip()
109
+ elif 'Strategic Implications' in subsection:
110
+ processed_report['exec_summary']['strategic_implications'] = subsection.split('\n', 1)[1].strip()
111
+ elif 'Recommendations' in subsection:
112
+ processed_report['exec_summary']['recommendations'] = subsection.split('\n', 1)[1].strip()
113
 
114
+ elif "MARKET ANALYSIS" in section_name:
115
+ subsections = content.split('##')
116
+ for subsection in subsections:
117
+ if 'Market Overview' in subsection:
118
+ processed_report['market_analysis']['overview'] = subsection.split('\n', 1)[1].strip()
119
+ elif 'Industry Dynamics' in subsection:
120
+ processed_report['market_analysis']['dynamics'] = subsection.split('\n', 1)[1].strip()
121
+ elif 'Competitive Landscape' in subsection:
122
+ processed_report['market_analysis']['competitive_landscape'] = subsection.split('\n', 1)[1].strip()
123
+ elif 'Strategic Analysis' in subsection:
124
+ processed_report['market_analysis']['strategic_analysis'] = subsection.split('\n', 1)[1].strip()
125
 
126
+ elif "FUTURE OUTLOOK" in section_name:
127
+ processed_report['future_outlook'] = content.strip()
128
+
129
+ elif "SOURCES" in section_name or "APPENDICES" in section_name:
130
+ sources = [line.strip() for line in content.split('\n')
131
+ if line.strip() and (line.strip().startswith('-') or
132
+ line.strip().startswith('•'))]
133
  processed_report['sources'] = sources
134
+
135
+ # Debug print
136
+ st.write("Debug - Processed Report Structure:", processed_report.keys())
137
 
 
138
  update_progress(progress_container, 100, "Report completed!")
 
 
139
  return processed_report
140
 
141
  except Exception as e:
142
  st.error(f"Error during research: {str(e)}")
143
  print(f"Full error details: {str(e)}") # For debugging
144
+ return None
145
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  def main():
147
  st.title("🤖 AI Market Research Generator")
148