cryogenic22 commited on
Commit
ec07c78
Β·
verified Β·
1 Parent(s): 480be5f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +164 -0
app.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import os
3
+ import streamlit as st
4
+ from dotenv import load_dotenv
5
+ from crewai import Agent, Task, Crew, Process
6
+ from langchain.tools import DuckDuckGoSearchRun
7
+
8
+ # Load environment variables
9
+ load_dotenv()
10
+
11
+ # Set page config
12
+ st.set_page_config(
13
+ page_title="Market Research Generator",
14
+ page_icon="πŸ“Š",
15
+ layout="wide"
16
+ )
17
+
18
+ # Add custom CSS
19
+ st.markdown("""
20
+ <style>
21
+ .stButton>button {
22
+ width: 100%;
23
+ margin-top: 20px;
24
+ }
25
+ .report-container {
26
+ background-color: #f0f2f6;
27
+ padding: 20px;
28
+ border-radius: 10px;
29
+ margin-top: 20px;
30
+ }
31
+ </style>
32
+ """, unsafe_allow_html=True)
33
+
34
+ def run_market_research(topic):
35
+ with st.status("πŸ€– AI Crew working on your report...", expanded=True) as status:
36
+ try:
37
+ # Initialize the search tool
38
+ search_tool = DuckDuckGoSearchRun()
39
+
40
+ status.update(label="πŸ” Creating AI agents...")
41
+ # Create agents
42
+ researcher = Agent(
43
+ role='Research Analyst',
44
+ goal=f'Conduct thorough market research about {topic}',
45
+ backstory='You are an experienced market research analyst with expertise in data analysis and trend identification.',
46
+ verbose=True,
47
+ tools=[search_tool],
48
+ allow_delegation=True
49
+ )
50
+
51
+ analyst = Agent(
52
+ role='Data Analyst',
53
+ goal='Analyze research findings and identify key insights',
54
+ backstory='You are a skilled data analyst with expertise in interpreting market research and creating actionable insights.',
55
+ verbose=True,
56
+ allow_delegation=True
57
+ )
58
+
59
+ writer = Agent(
60
+ role='Report Writer',
61
+ goal='Create comprehensive and engaging market research reports',
62
+ backstory='You are a professional writer specializing in creating clear and compelling business reports.',
63
+ verbose=True,
64
+ allow_delegation=True
65
+ )
66
+
67
+ status.update(label="πŸ“‹ Defining research tasks...")
68
+ # Define tasks
69
+ research_task = Task(
70
+ description=f"""
71
+ Conduct comprehensive market research on {topic}.
72
+ Focus on:
73
+ 1. Current market size and growth projections
74
+ 2. Key players and their market share
75
+ 3. Consumer adoption trends
76
+ 4. Regulatory environment
77
+ """,
78
+ agent=researcher
79
+ )
80
+
81
+ analysis_task = Task(
82
+ description=f"""
83
+ Analyze the research findings for {topic} and identify:
84
+ 1. Key market opportunities
85
+ 2. Potential challenges
86
+ 3. Growth drivers
87
+ 4. Competitive dynamics
88
+ Use the research provided by the Research Analyst.
89
+ """,
90
+ agent=analyst
91
+ )
92
+
93
+ report_task = Task(
94
+ description=f"""
95
+ Create a detailed market research report that includes:
96
+ 1. Executive summary
97
+ 2. Market overview
98
+ 3. Key findings
99
+ 4. Strategic recommendations
100
+ Base the report on the research and analysis provided by the other agents.
101
+ """,
102
+ agent=writer
103
+ )
104
+
105
+ status.update(label="πŸš€ Assembling the crew and starting research...")
106
+ # Create the crew
107
+ market_research_crew = Crew(
108
+ agents=[researcher, analyst, writer],
109
+ tasks=[research_task, analysis_task, report_task],
110
+ verbose=2,
111
+ process=Process.sequential
112
+ )
113
+
114
+ # Execute the crew's tasks
115
+ result = market_research_crew.kickoff()
116
+ status.update(label="βœ… Report generated successfully!", state="complete")
117
+ return result
118
+
119
+ except Exception as e:
120
+ status.update(label=f"❌ Error: {str(e)}", state="error")
121
+ return None
122
+
123
+ def main():
124
+ st.title("πŸ€– AI Market Research Generator")
125
+ st.markdown("""
126
+ This tool uses a crew of AI agents to generate comprehensive market research reports.
127
+ Each report is created through a collaborative process involving:
128
+ - πŸ” A Research Analyst who gathers market data
129
+ - πŸ“Š A Data Analyst who processes the findings
130
+ - ✍️ A Report Writer who creates the final document
131
+ """)
132
+
133
+ # Input section
134
+ st.subheader("Research Topic")
135
+ topic = st.text_input(
136
+ "Enter the market or product you want to research",
137
+ placeholder="e.g., Electric Vehicles Market",
138
+ key="research_topic"
139
+ )
140
+
141
+ if st.button("Generate Report", type="primary"):
142
+ if not topic:
143
+ st.error("Please enter a research topic")
144
+ return
145
+
146
+ report = run_market_research(topic)
147
+
148
+ if report:
149
+ st.subheader("πŸ“‘ Generated Report")
150
+ with st.container():
151
+ st.markdown('<div class="report-container">', unsafe_allow_html=True)
152
+ st.markdown(report)
153
+ st.markdown('</div>', unsafe_allow_html=True)
154
+
155
+ # Add download button
156
+ st.download_button(
157
+ label="Download Report",
158
+ data=report,
159
+ file_name=f"market_research_{topic.lower().replace(' ', '_')}.md",
160
+ mime="text/markdown"
161
+ )
162
+
163
+ if __name__ == "__main__":
164
+ main()