cryogenic22 commited on
Commit
a16e269
·
verified ·
1 Parent(s): 534fb78

Update report_generator.py

Browse files
Files changed (1) hide show
  1. report_generator.py +76 -110
report_generator.py CHANGED
@@ -8,125 +8,91 @@ from reportlab.lib.units import inch
8
  import io
9
  import streamlit as st
10
 
11
- def generate_direct_report(topic, questions=None):
12
  llm = ChatOpenAI(temperature=0.7, model="gpt-4")
 
13
 
14
- # First prompt for research with more detailed requirements
15
- research_prompt = f"""Conduct comprehensive market research on: {topic}
16
-
17
- Create an extremely detailed analysis covering:
18
- 1. Current Market Overview
19
- - Detailed market size with regional breakdowns
20
- - Historical growth patterns (last 5 years)
21
- - Market segmentation analysis
22
- - Value chain analysis
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- 2. Competitive Landscape
25
- - Top 10 key players with market shares
26
- - Detailed company profiles
 
 
 
 
 
 
 
 
 
 
27
  - Competitive strategies
28
- - Recent developments and innovations
29
 
30
- 3. Market Dynamics
31
- - Comprehensive growth drivers analysis
32
- - Detailed market challenges
33
- - Opportunities in the market
34
- - Regulatory landscape
35
 
36
- 4. Regional Analysis
37
- - Market size by region
38
- - Growth rates by region
39
- - Regional market characteristics
40
- - Key regional players
41
 
42
- 5. Technology Trends
43
- - Current technology landscape
44
- - Emerging technologies
45
- - Innovation patterns
46
- - Technology adoption rates
47
 
48
- 6. Consumer Analysis
49
- - Buying patterns
50
- - Consumer preferences
51
- - Demographics
52
- - Regional variations
53
-
54
- 7. Future Outlook
55
- - 5-year projections
56
  - Growth opportunities
57
- - Potential challenges
58
- - Market evolution scenarios
59
-
60
- Provide extensive data-backed insights with specific numbers, statistics, and multiple examples for each section.
61
- Include real market data and examples where possible."""
62
-
63
- if questions:
64
- research_prompt += f"\nAdditional questions to address:\n{questions}"
65
-
66
- research_data = llm.invoke(research_prompt).content
67
-
68
- # Second prompt for comprehensive report
69
- report_prompt = f"""Create an extensive professional market research report using this research data:
70
- {research_data}
71
-
72
- Structure the report with these detailed sections:
73
-
74
- # Executive Summary
75
- - Comprehensive overview (2-3 paragraphs)
76
- - Key findings (at least 6 bullet points)
77
- - Critical market highlights (4-5 paragraphs)
78
-
79
- # Market Overview
80
- - Detailed current market size analysis (2-3 paragraphs)
81
- - Historical growth patterns (2 paragraphs)
82
- - Segmentation analysis (5-6 bullet points per segment)
83
- - Value chain breakdown (detailed list with explanations)
84
-
85
- # Competitive Landscape
86
- - Key players profiles (minimum 8-10 companies)
87
- - Market share analysis (detailed breakdown)
88
- - Competitive strategies (5-6 strategies per player)
89
- - SWOT analysis for top 3 players
90
-
91
- # Market Dynamics
92
- - Growth drivers (6-8 detailed points)
93
- - Market challenges (6-8 detailed points)
94
- - Opportunities (6-8 detailed points)
95
- - Entry barriers (4-5 detailed points)
96
-
97
- # Regional Analysis
98
- - North America (2-3 paragraphs)
99
- - Europe (2-3 paragraphs)
100
- - Asia Pacific (2-3 paragraphs)
101
- - Rest of World (2-3 paragraphs)
102
-
103
- # Industry Trends
104
- - Current technology trends (5-6 points)
105
- - Consumer behavior patterns (5-6 points)
106
- - Regulatory landscape (3-4 paragraphs)
107
- - Innovation trends (5-6 points)
108
-
109
- # Future Outlook
110
- - Market projections (2-3 paragraphs)
111
- - Growth scenarios (3 scenarios with details)
112
- - Emerging opportunities (6-8 points)
113
- - Risk factors (6-8 points)
114
-
115
- # Strategic Recommendations
116
- - Short-term strategies (5-6 detailed points)
117
- - Long-term opportunities (5-6 detailed points)
118
- - Risk mitigation strategies (5-6 points)
119
-
120
- Format in clean markdown with clear headers and bullet points.
121
- Each section should be highly detailed and comprehensive.
122
- Use specific data points, numbers, and statistics throughout the report."""
123
-
124
- final_report = llm.invoke(report_prompt).content
125
-
126
- return {
127
- 'research_data': research_data,
128
- 'final_report': final_report
129
- }
130
 
131
  def create_pdf_report(report_content, topic):
132
  # Create an in-memory bytes buffer
 
8
  import io
9
  import streamlit as st
10
 
11
+ def generate_direct_report(topic, questions):
12
  llm = ChatOpenAI(temperature=0.7, model="gpt-4")
13
+ serper = SerperDevTool()
14
 
15
+ # First, gather research data
16
+ research_prompt = f"""Research the current market status of {topic}.
17
+
18
+ Specifically focus on:
19
+ 1. Market size and recent growth
20
+ 2. Key competitors and their market shares
21
+ 3. Major trends and developments
22
+ 4. Regional analysis
23
+ 5. Future projections
24
+
25
+ Also address these specific questions:
26
+ {questions}
27
+
28
+ Use real market data and statistics."""
29
+
30
+ try:
31
+ # Use SerperDev to get real market data
32
+ search_results = serper.search(f"{topic} market size statistics trends analysis")
33
+
34
+ # Research using the search results
35
+ research_data = llm.invoke(research_prompt + f"\n\nUse this market data: {search_results}")
36
+
37
+ # Generate comprehensive report
38
+ report_prompt = f"""Create a detailed market research report for {topic} using this research data:
39
+ {research_data.content}
40
+
41
+ Address these specific questions:
42
+ {questions}
43
 
44
+ Format the report with:
45
+ # Executive Summary
46
+ [Provide 2-3 paragraphs summary with key points]
47
+
48
+ # Market Overview
49
+ - Current market size
50
+ - Growth rate
51
+ - Market segments
52
+ - Geographic distribution
53
+
54
+ # Competitive Analysis
55
+ - Key players
56
+ - Market shares
57
  - Competitive strategies
58
+ - SWOT analysis
59
 
60
+ # Market Trends
61
+ - Current trends
62
+ - Technology impacts
63
+ - Consumer behavior
64
+ - Regulatory factors
65
 
66
+ # Regional Analysis
67
+ - Key regions
68
+ - Growth by region
69
+ - Market characteristics
 
70
 
71
+ # Future Outlook
72
+ - Growth projections
73
+ - Opportunities
74
+ - Challenges
 
75
 
76
+ # Strategic Recommendations
77
+ - Key strategies
 
 
 
 
 
 
78
  - Growth opportunities
79
+ - Risk mitigation
80
+
81
+ Use specific data points and statistics throughout the report."""
82
+
83
+ final_report = llm.invoke(report_prompt)
84
+
85
+ return {
86
+ 'research_data': research_data.content,
87
+ 'final_report': final_report.content
88
+ }
89
+
90
+ except Exception as e:
91
+ st.error(f"Error generating direct report: {str(e)}")
92
+ return {
93
+ 'research_data': "Error collecting research data",
94
+ 'final_report': "Error generating report"
95
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  def create_pdf_report(report_content, topic):
98
  # Create an in-memory bytes buffer