Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
|
|
|
|
| 2 |
# app.py
|
| 3 |
import os
|
|
|
|
| 4 |
import streamlit as st
|
|
|
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
-
from crewai import Agent,
|
| 7 |
-
from crewai.
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
load_dotenv()
|
|
@@ -32,88 +37,98 @@ st.markdown("""
|
|
| 32 |
</style>
|
| 33 |
""", unsafe_allow_html=True)
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
with st.status("🤖 AI Crew working on your report...", expanded=True) as status:
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
status.update(label="🔍 Creating AI agents...")
|
| 42 |
-
# Create agents
|
| 43 |
-
researcher = Agent(
|
| 44 |
-
role='Research Analyst',
|
| 45 |
-
goal=f'Conduct thorough market research about {topic}',
|
| 46 |
-
backstory='You are an experienced market research analyst with expertise in data analysis and trend identification.',
|
| 47 |
-
verbose=True,
|
| 48 |
-
tools=[search_tool],
|
| 49 |
-
allow_delegation=True
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
analyst = Agent(
|
| 53 |
-
role='Data Analyst',
|
| 54 |
-
goal='Analyze research findings and identify key insights',
|
| 55 |
-
backstory='You are a skilled data analyst with expertise in interpreting market research and creating actionable insights.',
|
| 56 |
-
verbose=True,
|
| 57 |
-
allow_delegation=True
|
| 58 |
-
)
|
| 59 |
-
|
| 60 |
-
writer = Agent(
|
| 61 |
-
role='Report Writer',
|
| 62 |
-
goal='Create comprehensive and engaging market research reports',
|
| 63 |
-
backstory='You are a professional writer specializing in creating clear and compelling business reports.',
|
| 64 |
-
verbose=True,
|
| 65 |
-
allow_delegation=True
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
status.update(label="📋 Defining research tasks...")
|
| 69 |
-
# Define tasks
|
| 70 |
-
research_task = Task(
|
| 71 |
-
description=f"""
|
| 72 |
-
Conduct comprehensive market research on {topic}.
|
| 73 |
-
Focus on:
|
| 74 |
-
1. Current market size and growth projections
|
| 75 |
-
2. Key players and their market share
|
| 76 |
-
3. Consumer adoption trends
|
| 77 |
-
4. Regulatory environment
|
| 78 |
-
""",
|
| 79 |
-
agent=researcher
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
analysis_task = Task(
|
| 83 |
-
description=f"""
|
| 84 |
-
Analyze the research findings for {topic} and identify:
|
| 85 |
-
1. Key market opportunities
|
| 86 |
-
2. Potential challenges
|
| 87 |
-
3. Growth drivers
|
| 88 |
-
4. Competitive dynamics
|
| 89 |
-
Use the research provided by the Research Analyst.
|
| 90 |
-
""",
|
| 91 |
-
agent=analyst
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
report_task = Task(
|
| 95 |
-
description=f"""
|
| 96 |
-
Create a detailed market research report that includes:
|
| 97 |
-
1. Executive summary
|
| 98 |
-
2. Market overview
|
| 99 |
-
3. Key findings
|
| 100 |
-
4. Strategic recommendations
|
| 101 |
-
Base the report on the research and analysis provided by the other agents.
|
| 102 |
-
""",
|
| 103 |
-
agent=writer
|
| 104 |
-
)
|
| 105 |
|
| 106 |
-
status.update(label="🚀
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
result = market_research_crew.kickoff()
|
| 117 |
status.update(label="✅ Report generated successfully!", state="complete")
|
| 118 |
return result
|
| 119 |
|
|
@@ -131,8 +146,6 @@ def main():
|
|
| 131 |
- ✍️ A Report Writer who creates the final document
|
| 132 |
""")
|
| 133 |
|
| 134 |
-
# Input section
|
| 135 |
-
st.subheader("Research Topic")
|
| 136 |
topic = st.text_input(
|
| 137 |
"Enter the market or product you want to research",
|
| 138 |
placeholder="e.g., Electric Vehicles Market",
|
|
@@ -153,7 +166,6 @@ def main():
|
|
| 153 |
st.markdown(report)
|
| 154 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 155 |
|
| 156 |
-
# Add download button
|
| 157 |
st.download_button(
|
| 158 |
label="Download Report",
|
| 159 |
data=report,
|
|
|
|
| 1 |
|
| 2 |
+
|
| 3 |
# app.py
|
| 4 |
import os
|
| 5 |
+
import yaml
|
| 6 |
import streamlit as st
|
| 7 |
+
from typing import List
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
+
from crewai import Agent, Crew, Process, Task
|
| 10 |
+
from crewai.project import CrewBase, agent, crew, task
|
| 11 |
+
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
|
| 12 |
+
from pydantic import BaseModel, Field
|
| 13 |
|
| 14 |
# Load environment variables
|
| 15 |
load_dotenv()
|
|
|
|
| 37 |
</style>
|
| 38 |
""", unsafe_allow_html=True)
|
| 39 |
|
| 40 |
+
# Define output models
|
| 41 |
+
class MarketResearchReport(BaseModel):
|
| 42 |
+
"""Market research report model"""
|
| 43 |
+
title: str = Field(..., description="Title of the report")
|
| 44 |
+
executive_summary: str = Field(..., description="Executive summary of the report")
|
| 45 |
+
market_overview: str = Field(..., description="Market overview section")
|
| 46 |
+
key_findings: List[str] = Field(..., description="List of key findings")
|
| 47 |
+
recommendations: List[str] = Field(..., description="List of strategic recommendations")
|
| 48 |
+
|
| 49 |
+
@CrewBase
|
| 50 |
+
class MarketResearchCrew:
|
| 51 |
+
"""Market Research crew"""
|
| 52 |
+
agents_config = 'config/agents.yaml'
|
| 53 |
+
tasks_config = 'config/tasks.yaml'
|
| 54 |
+
|
| 55 |
+
@agent
|
| 56 |
+
def research_analyst(self) -> Agent:
|
| 57 |
+
return Agent(
|
| 58 |
+
config=self.agents_config['research_analyst'],
|
| 59 |
+
tools=[SerperDevTool(), ScrapeWebsiteTool()],
|
| 60 |
+
verbose=True,
|
| 61 |
+
memory=False,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
@agent
|
| 65 |
+
def data_analyst(self) -> Agent:
|
| 66 |
+
return Agent(
|
| 67 |
+
config=self.agents_config['data_analyst'],
|
| 68 |
+
tools=[SerperDevTool()],
|
| 69 |
+
verbose=True,
|
| 70 |
+
memory=False,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
@agent
|
| 74 |
+
def report_writer(self) -> Agent:
|
| 75 |
+
return Agent(
|
| 76 |
+
config=self.agents_config['report_writer'],
|
| 77 |
+
verbose=True,
|
| 78 |
+
memory=False,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
@task
|
| 82 |
+
def research_task(self) -> Task:
|
| 83 |
+
return Task(
|
| 84 |
+
config=self.tasks_config['research_task'],
|
| 85 |
+
agent=self.research_analyst()
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
@task
|
| 89 |
+
def analysis_task(self) -> Task:
|
| 90 |
+
return Task(
|
| 91 |
+
config=self.tasks_config['analysis_task'],
|
| 92 |
+
agent=self.data_analyst(),
|
| 93 |
+
context=[self.research_task()]
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
@task
|
| 97 |
+
def report_task(self) -> Task:
|
| 98 |
+
return Task(
|
| 99 |
+
config=self.tasks_config['report_task'],
|
| 100 |
+
agent=self.report_writer(),
|
| 101 |
+
context=[self.research_task(), self.analysis_task()],
|
| 102 |
+
output_json=MarketResearchReport
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
@crew
|
| 106 |
+
def crew(self) -> Crew:
|
| 107 |
+
"""Creates the Market Research crew"""
|
| 108 |
+
return Crew(
|
| 109 |
+
agents=self.agents,
|
| 110 |
+
tasks=self.tasks,
|
| 111 |
+
process=Process.sequential,
|
| 112 |
+
verbose=2,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
def run_market_research(topic: str):
|
| 116 |
with st.status("🤖 AI Crew working on your report...", expanded=True) as status:
|
| 117 |
try:
|
| 118 |
+
status.update(label="🔍 Initializing research crew...")
|
| 119 |
+
crew_instance = MarketResearchCrew()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
status.update(label="🚀 Starting research process...")
|
| 122 |
+
inputs = {
|
| 123 |
+
'topic': topic,
|
| 124 |
+
'project_description': f"""
|
| 125 |
+
Conduct comprehensive market research for {topic}.
|
| 126 |
+
The research should cover market size, growth projections, key players,
|
| 127 |
+
consumer trends, and regulatory environment.
|
| 128 |
+
"""
|
| 129 |
+
}
|
| 130 |
|
| 131 |
+
result = crew_instance.crew().kickoff(inputs=inputs)
|
|
|
|
| 132 |
status.update(label="✅ Report generated successfully!", state="complete")
|
| 133 |
return result
|
| 134 |
|
|
|
|
| 146 |
- ✍️ A Report Writer who creates the final document
|
| 147 |
""")
|
| 148 |
|
|
|
|
|
|
|
| 149 |
topic = st.text_input(
|
| 150 |
"Enter the market or product you want to research",
|
| 151 |
placeholder="e.g., Electric Vehicles Market",
|
|
|
|
| 166 |
st.markdown(report)
|
| 167 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 168 |
|
|
|
|
| 169 |
st.download_button(
|
| 170 |
label="Download Report",
|
| 171 |
data=report,
|