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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import warnings
|
| 3 |
+
import logging
|
| 4 |
+
from market_analysis_crew import get_market_analysis_crew, get_report_generator, create_reports
|
| 5 |
+
|
| 6 |
+
# Disable all warnings and telemetry
|
| 7 |
+
warnings.filterwarnings('ignore')
|
| 8 |
+
os.environ["ANONYMIZED_TELEMETRY"] = "False"
|
| 9 |
+
os.environ["OPENTELEMETRY_ENABLED"] = "False"
|
| 10 |
+
os.environ["DISABLE_TELEMETRY"] = "True"
|
| 11 |
+
|
| 12 |
+
# Configure logging
|
| 13 |
+
logging.basicConfig(
|
| 14 |
+
level=logging.INFO,
|
| 15 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 16 |
+
)
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
def get_user_input():
|
| 20 |
+
print("\n=== Report Generation Configuration ===\n")
|
| 21 |
+
|
| 22 |
+
# Show available report types
|
| 23 |
+
print("Available Report Types:")
|
| 24 |
+
print("1. Market Analysis")
|
| 25 |
+
print("2. Competitor Tracking")
|
| 26 |
+
print("3. ICP Report")
|
| 27 |
+
print("4. Gap Analysis")
|
| 28 |
+
print("5. Market Assessment")
|
| 29 |
+
print("6. Impact Assessment")
|
| 30 |
+
|
| 31 |
+
# Get report type
|
| 32 |
+
while True:
|
| 33 |
+
try:
|
| 34 |
+
report_choice = int(input("\nSelect report type (1-6): "))
|
| 35 |
+
if 1 <= report_choice <= 6:
|
| 36 |
+
report_types = {
|
| 37 |
+
1: "market_analysis",
|
| 38 |
+
2: "competitor_tracking",
|
| 39 |
+
3: "icp_report",
|
| 40 |
+
4: "gap_analysis",
|
| 41 |
+
5: "market_assessment",
|
| 42 |
+
6: "impact_assessment"
|
| 43 |
+
}
|
| 44 |
+
report_type = report_types[report_choice]
|
| 45 |
+
break
|
| 46 |
+
print("Please select a number between 1 and 6.")
|
| 47 |
+
except ValueError:
|
| 48 |
+
print("Please enter a valid number.")
|
| 49 |
+
|
| 50 |
+
# Common inputs for all report types
|
| 51 |
+
inputs = {}
|
| 52 |
+
inputs["company_name"] = input("\nEnter company name: ").strip()
|
| 53 |
+
inputs["industry"] = input("Enter industry sector (optional): ").strip()
|
| 54 |
+
inputs["time_period"] = input("Enter time period (e.g., 2024, press Enter for current): ").strip() or "2024"
|
| 55 |
+
|
| 56 |
+
# Report-specific inputs
|
| 57 |
+
if report_type == "icp_report":
|
| 58 |
+
# Business Model
|
| 59 |
+
print("\nSelect business model:")
|
| 60 |
+
print("1. B2B")
|
| 61 |
+
print("2. B2C")
|
| 62 |
+
print("3. B2B2C")
|
| 63 |
+
while True:
|
| 64 |
+
try:
|
| 65 |
+
model_choice = int(input("Select model (1-3) [1]: ") or "1")
|
| 66 |
+
if 1 <= model_choice <= 3:
|
| 67 |
+
model_map = {1: "b2b", 2: "b2c", 3: "b2b2c"}
|
| 68 |
+
inputs["business_model"] = model_map[model_choice]
|
| 69 |
+
break
|
| 70 |
+
print("Please select a valid number between 1 and 3")
|
| 71 |
+
except ValueError:
|
| 72 |
+
print("Please enter a valid number")
|
| 73 |
+
|
| 74 |
+
# Company Size
|
| 75 |
+
print("\nSelect target company size:")
|
| 76 |
+
print("1. Small (1-50 employees)")
|
| 77 |
+
print("2. Medium (51-500 employees)")
|
| 78 |
+
print("3. Large (501+ employees)")
|
| 79 |
+
print("4. All sizes")
|
| 80 |
+
while True:
|
| 81 |
+
try:
|
| 82 |
+
size_choice = int(input("Select size (1-4) [4]: ") or "4")
|
| 83 |
+
if 1 <= size_choice <= 4:
|
| 84 |
+
size_map = {1: "small", 2: "medium", 3: "large", 4: "all"}
|
| 85 |
+
inputs["company_size"] = size_map[size_choice]
|
| 86 |
+
break
|
| 87 |
+
print("Please select a valid number between 1 and 4")
|
| 88 |
+
except ValueError:
|
| 89 |
+
print("Please enter a valid number")
|
| 90 |
+
|
| 91 |
+
# Target Market
|
| 92 |
+
print("\nSelect target market:")
|
| 93 |
+
markets = ["Global", "North America", "Europe", "Asia Pacific", "Latin America"]
|
| 94 |
+
for i, market in enumerate(markets, 1):
|
| 95 |
+
print(f"{i}. {market}")
|
| 96 |
+
while True:
|
| 97 |
+
try:
|
| 98 |
+
market_choice = int(input(f"Select market (1-{len(markets)}) [1]: ") or "1")
|
| 99 |
+
if 1 <= market_choice <= len(markets):
|
| 100 |
+
inputs["target_market"] = markets[market_choice-1].lower().replace(" ", "_")
|
| 101 |
+
break
|
| 102 |
+
print(f"Please select a valid number between 1 and {len(markets)}")
|
| 103 |
+
except ValueError:
|
| 104 |
+
print("Please enter a valid number")
|
| 105 |
+
|
| 106 |
+
# Annual Revenue Range
|
| 107 |
+
print("\nSelect annual revenue range:")
|
| 108 |
+
revenue_ranges = [
|
| 109 |
+
"Under $1M",
|
| 110 |
+
"$1M - $10M",
|
| 111 |
+
"$10M - $50M",
|
| 112 |
+
"Over $50M"
|
| 113 |
+
]
|
| 114 |
+
for i, range_ in enumerate(revenue_ranges, 1):
|
| 115 |
+
print(f"{i}. {range_}")
|
| 116 |
+
while True:
|
| 117 |
+
try:
|
| 118 |
+
revenue_choice = int(input(f"Select range (1-{len(revenue_ranges)}) [2]: ") or "2")
|
| 119 |
+
if 1 <= revenue_choice <= len(revenue_ranges):
|
| 120 |
+
revenue_map = {1: "under_1m", 2: "1m_10m", 3: "10m_50m", 4: "over_50m"}
|
| 121 |
+
inputs["annual_revenue"] = revenue_map[revenue_choice]
|
| 122 |
+
break
|
| 123 |
+
print(f"Please select a valid number between 1 and {len(revenue_ranges)}")
|
| 124 |
+
except ValueError:
|
| 125 |
+
print("Please enter a valid number")
|
| 126 |
+
|
| 127 |
+
elif report_type == "competitor_tracking":
|
| 128 |
+
# Competitor inputs
|
| 129 |
+
print("\nEnter competitors (one per line, press Enter twice to finish):")
|
| 130 |
+
competitors = []
|
| 131 |
+
while True:
|
| 132 |
+
competitor = input().strip()
|
| 133 |
+
if not competitor:
|
| 134 |
+
if competitors:
|
| 135 |
+
break
|
| 136 |
+
print("Please enter at least one competitor.")
|
| 137 |
+
continue
|
| 138 |
+
competitors.append(competitor)
|
| 139 |
+
inputs["competitors"] = competitors
|
| 140 |
+
|
| 141 |
+
# Metrics selection
|
| 142 |
+
print("\nSelect metrics to track (enter numbers separated by commas):")
|
| 143 |
+
metrics = [
|
| 144 |
+
"Market Share",
|
| 145 |
+
"Product Features",
|
| 146 |
+
"Pricing Strategy",
|
| 147 |
+
"Marketing Channels",
|
| 148 |
+
"Customer Satisfaction"
|
| 149 |
+
]
|
| 150 |
+
for i, metric in enumerate(metrics, 1):
|
| 151 |
+
print(f"{i}. {metric}")
|
| 152 |
+
|
| 153 |
+
while True:
|
| 154 |
+
try:
|
| 155 |
+
selected = input("\nEnter metric numbers (e.g. 1,2,3): ").strip()
|
| 156 |
+
if selected:
|
| 157 |
+
selected_indices = [int(x.strip()) for x in selected.split(",")]
|
| 158 |
+
if all(1 <= i <= len(metrics) for i in selected_indices):
|
| 159 |
+
inputs["metrics"] = [metrics[i-1] for i in selected_indices]
|
| 160 |
+
break
|
| 161 |
+
print("Please enter valid numbers separated by commas")
|
| 162 |
+
except ValueError:
|
| 163 |
+
print("Please enter valid numbers")
|
| 164 |
+
|
| 165 |
+
# Add additional competitor-specific inputs
|
| 166 |
+
inputs["analysis_depth"] = input("\nSelect analysis depth (basic/detailed/comprehensive) [detailed]: ").strip().lower() or "detailed"
|
| 167 |
+
inputs["market_region"] = input("Enter target market region [global]: ").strip() or "global"
|
| 168 |
+
|
| 169 |
+
print("\nAdditional analysis parameters:")
|
| 170 |
+
print("1. Historical Data")
|
| 171 |
+
print("2. Current Market Position")
|
| 172 |
+
print("3. Future Projections")
|
| 173 |
+
print("4. All of the above")
|
| 174 |
+
|
| 175 |
+
while True:
|
| 176 |
+
try:
|
| 177 |
+
analysis_scope = int(input("Select analysis scope (1-4) [4]: ") or "4")
|
| 178 |
+
if 1 <= analysis_scope <= 4:
|
| 179 |
+
inputs["analysis_scope"] = analysis_scope
|
| 180 |
+
break
|
| 181 |
+
print("Please select a valid number between 1 and 4.")
|
| 182 |
+
except ValueError:
|
| 183 |
+
print("Please enter a valid number.")
|
| 184 |
+
|
| 185 |
+
elif report_type == "gap_analysis":
|
| 186 |
+
# Ensure all required fields are present
|
| 187 |
+
inputs.update({
|
| 188 |
+
"focus_areas": inputs.get("focus_areas", []),
|
| 189 |
+
"timeframe": inputs.get("time_period", "2024"),
|
| 190 |
+
"analysis_depth": inputs.get("analysis_depth", "detailed"),
|
| 191 |
+
"market_region": inputs.get("market_region", "global")
|
| 192 |
+
})
|
| 193 |
+
|
| 194 |
+
if not inputs.get("focus_areas"):
|
| 195 |
+
print("\nSelect focus areas (enter numbers separated by commas):")
|
| 196 |
+
focus_areas = [
|
| 197 |
+
"Market Size and Growth",
|
| 198 |
+
"Industry Trends",
|
| 199 |
+
"Market Segments",
|
| 200 |
+
"Geographic Distribution",
|
| 201 |
+
"Competitive Landscape"
|
| 202 |
+
]
|
| 203 |
+
for i, area in enumerate(focus_areas, 1):
|
| 204 |
+
print(f"{i}. {area}")
|
| 205 |
+
|
| 206 |
+
while True:
|
| 207 |
+
try:
|
| 208 |
+
selected = input("\nEnter focus area numbers (e.g. 1,2,3): ").strip()
|
| 209 |
+
if selected:
|
| 210 |
+
selected_indices = [int(x.strip()) for x in selected.split(",")]
|
| 211 |
+
if all(1 <= i <= len(focus_areas) for i in selected_indices):
|
| 212 |
+
inputs["focus_areas"] = [focus_areas[i-1] for i in selected_indices]
|
| 213 |
+
break
|
| 214 |
+
print("Please enter valid numbers separated by commas")
|
| 215 |
+
except ValueError:
|
| 216 |
+
print("Please enter valid numbers")
|
| 217 |
+
|
| 218 |
+
# Add analysis depth selection
|
| 219 |
+
print("\nSelect analysis depth:")
|
| 220 |
+
print("1. Basic")
|
| 221 |
+
print("2. Detailed")
|
| 222 |
+
print("3. Comprehensive")
|
| 223 |
+
|
| 224 |
+
while True:
|
| 225 |
+
try:
|
| 226 |
+
depth_choice = int(input("Select depth (1-3) [2]: ") or "2")
|
| 227 |
+
if 1 <= depth_choice <= 3:
|
| 228 |
+
depth_map = {1: "basic", 2: "detailed", 3: "comprehensive"}
|
| 229 |
+
inputs["analysis_depth"] = depth_map[depth_choice]
|
| 230 |
+
break
|
| 231 |
+
print("Please select a valid number between 1 and 3")
|
| 232 |
+
except ValueError:
|
| 233 |
+
print("Please enter a valid number")
|
| 234 |
+
|
| 235 |
+
# Add market region selection
|
| 236 |
+
print("\nSelect target market region:")
|
| 237 |
+
regions = [
|
| 238 |
+
"Global",
|
| 239 |
+
"North America",
|
| 240 |
+
"Europe",
|
| 241 |
+
"Asia Pacific"
|
| 242 |
+
]
|
| 243 |
+
for i, region in enumerate(regions, 1):
|
| 244 |
+
print(f"{i}. {region}")
|
| 245 |
+
|
| 246 |
+
while True:
|
| 247 |
+
try:
|
| 248 |
+
region_choice = int(input("\nSelect region (1-4) [1]: ") or "1")
|
| 249 |
+
if 1 <= region_choice <= len(regions):
|
| 250 |
+
inputs["market_region"] = regions[region_choice-1].lower().replace(" ", "_")
|
| 251 |
+
break
|
| 252 |
+
print(f"Please select a valid number between 1 and {len(regions)}")
|
| 253 |
+
except ValueError:
|
| 254 |
+
print("Please enter a valid number")
|
| 255 |
+
|
| 256 |
+
# Add timeframe input
|
| 257 |
+
inputs["timeframe"] = inputs["time_period"] # Use the common time_period as timeframe
|
| 258 |
+
|
| 259 |
+
return inputs, report_type.lower().replace(' ', '_')
|
| 260 |
+
|
| 261 |
+
def main():
|
| 262 |
+
try:
|
| 263 |
+
# Get user inputs
|
| 264 |
+
user_inputs, report_type = get_user_input()
|
| 265 |
+
|
| 266 |
+
print("\nInitializing analysis...")
|
| 267 |
+
print(f"Company: {user_inputs['company_name']}")
|
| 268 |
+
print(f"Report Type: {report_type}")
|
| 269 |
+
print(f"Industry: {user_inputs['industry'] or 'Not specified'}")
|
| 270 |
+
|
| 271 |
+
# Confirmation
|
| 272 |
+
confirm = input("\nProceed with analysis? (y/n): ").lower().strip()
|
| 273 |
+
if confirm != 'y':
|
| 274 |
+
print("Analysis cancelled.")
|
| 275 |
+
return
|
| 276 |
+
|
| 277 |
+
print("\nStarting analysis...")
|
| 278 |
+
print("=" * 50)
|
| 279 |
+
|
| 280 |
+
# Use the new generator
|
| 281 |
+
generator = get_report_generator()
|
| 282 |
+
result = generator.generate_report(report_type, user_inputs)
|
| 283 |
+
|
| 284 |
+
# Create reports
|
| 285 |
+
validation_file, report_file = create_reports(result, user_inputs, report_type)
|
| 286 |
+
|
| 287 |
+
print("\n" + "="*50)
|
| 288 |
+
print("ANALYSIS COMPLETE")
|
| 289 |
+
print("="*50)
|
| 290 |
+
print(f"\nReports generated:")
|
| 291 |
+
print(f"1. Validation Report: {validation_file}")
|
| 292 |
+
print(f"2. Analysis Report: {report_file}")
|
| 293 |
+
|
| 294 |
+
except KeyboardInterrupt:
|
| 295 |
+
print("\nAnalysis cancelled by user.")
|
| 296 |
+
except Exception as e:
|
| 297 |
+
print(f"\nError during analysis: {str(e)}")
|
| 298 |
+
logger.exception("Analysis failed")
|
| 299 |
+
finally:
|
| 300 |
+
print("\nThank you for using the Market Analysis Tool!")
|
| 301 |
+
|
| 302 |
+
if __name__ == "__main__":
|
| 303 |
+
main()
|
market_analysis_crew.py
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from crewai import Agent, Task, Crew, Process
|
| 2 |
+
from langchain_openai import ChatOpenAI
|
| 3 |
+
from langchain.tools import Tool
|
| 4 |
+
from langchain_community.tools import WriteFileTool
|
| 5 |
+
from langchain_community.utilities.serpapi import SerpAPIWrapper
|
| 6 |
+
import os
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
# Initialize tools and models
|
| 11 |
+
openai_model = ChatOpenAI(
|
| 12 |
+
model_name="gpt-4o-mini",
|
| 13 |
+
temperature=0.7
|
| 14 |
+
)
|
| 15 |
+
search = SerpAPIWrapper()
|
| 16 |
+
|
| 17 |
+
class ReportGenerator:
|
| 18 |
+
def __init__(self):
|
| 19 |
+
self.search_tool = Tool(
|
| 20 |
+
name="Search the internet",
|
| 21 |
+
description="Search the web for comprehensive analysis",
|
| 22 |
+
func=self.enhanced_search
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
self.write_file_tool = Tool(
|
| 26 |
+
name="Write File",
|
| 27 |
+
description="Write content to a file. Input should be a dictionary with 'file_path' and 'text' keys.",
|
| 28 |
+
func=self.write_file_tool_wrapper
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
def enhanced_search(self, query):
|
| 32 |
+
try:
|
| 33 |
+
formatted_query = f"{query} analysis OR {query} insights 2024"
|
| 34 |
+
search_results = search.run(query=formatted_query, kwargs={
|
| 35 |
+
"num": 10,
|
| 36 |
+
"time": "y",
|
| 37 |
+
})
|
| 38 |
+
return {
|
| 39 |
+
"query": formatted_query,
|
| 40 |
+
"results": search_results,
|
| 41 |
+
"timestamp": time.strftime('%Y-%m-%d %H:%M:%S')
|
| 42 |
+
}
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return {
|
| 45 |
+
"error": f"Search failed: {str(e)}",
|
| 46 |
+
"timestamp": time.strftime('%Y-%m-%d %H:%M:%S')
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
def write_file_tool_wrapper(self, file_input):
|
| 50 |
+
try:
|
| 51 |
+
if isinstance(file_input, str):
|
| 52 |
+
file_input = {"file_path": "report.md", "text": file_input}
|
| 53 |
+
return WriteFileTool().run(file_input)
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return {
|
| 56 |
+
"error": f"File write failed: {str(e)}",
|
| 57 |
+
"timestamp": time.strftime('%Y-%m-%d %H:%M:%S')
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
def create_market_analysis_crew(self, inputs):
|
| 61 |
+
analyst = Agent(
|
| 62 |
+
role='Market Research Analyst',
|
| 63 |
+
goal=f'Analyze {inputs["company_name"]} market position and trends',
|
| 64 |
+
backstory="""Expert in market research and analysis. Skilled at identifying trends
|
| 65 |
+
and opportunities in various markets.""",
|
| 66 |
+
tools=[self.search_tool],
|
| 67 |
+
verbose=True
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
writer = Agent(
|
| 71 |
+
role='Business Report Writer',
|
| 72 |
+
goal='Create comprehensive market analysis reports',
|
| 73 |
+
backstory="""Professional business writer specializing in creating clear,
|
| 74 |
+
actionable market analysis reports.""",
|
| 75 |
+
tools=[self.write_file_tool],
|
| 76 |
+
verbose=True
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
tasks = [
|
| 80 |
+
Task(
|
| 81 |
+
description=f"""Analyze market trends and position for {inputs["company_name"]}
|
| 82 |
+
Focus on: {', '.join(inputs['focus_areas'])}
|
| 83 |
+
Industry: {inputs['industry']}
|
| 84 |
+
Time Period: {inputs['time_period']}""",
|
| 85 |
+
expected_output="""A comprehensive market analysis containing:
|
| 86 |
+
- Market size and growth trends
|
| 87 |
+
- Industry analysis
|
| 88 |
+
- Key market drivers
|
| 89 |
+
- Competitive landscape
|
| 90 |
+
- Market opportunities and challenges""",
|
| 91 |
+
agent=analyst
|
| 92 |
+
),
|
| 93 |
+
Task(
|
| 94 |
+
description="Create a detailed market analysis report with findings",
|
| 95 |
+
expected_output="""A well-structured markdown report containing:
|
| 96 |
+
- Executive summary
|
| 97 |
+
- Market overview
|
| 98 |
+
- Detailed analysis
|
| 99 |
+
- Key findings
|
| 100 |
+
- Strategic recommendations""",
|
| 101 |
+
agent=writer
|
| 102 |
+
)
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
return Crew(
|
| 106 |
+
agents=[analyst, writer],
|
| 107 |
+
tasks=tasks,
|
| 108 |
+
verbose=True
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
def create_competitor_tracking_crew(self, inputs):
|
| 112 |
+
analyst = Agent(
|
| 113 |
+
role='Competitive Intelligence Analyst',
|
| 114 |
+
goal=f'Track and analyze competitors of {inputs["company_name"]}',
|
| 115 |
+
backstory="Expert in competitive analysis and market intelligence.",
|
| 116 |
+
tools=[self.search_tool],
|
| 117 |
+
verbose=True
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
writer = Agent(
|
| 121 |
+
role='Competition Report Writer',
|
| 122 |
+
goal='Create detailed competitor analysis reports',
|
| 123 |
+
backstory="Specialist in competitive intelligence reporting.",
|
| 124 |
+
tools=[self.write_file_tool],
|
| 125 |
+
verbose=True
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
tasks = [
|
| 129 |
+
Task(
|
| 130 |
+
description=f"""Analyze competitors for {inputs['company_name']} in {inputs['industry']}
|
| 131 |
+
Competitors to analyze: {', '.join(inputs['competitors'])}
|
| 132 |
+
Metrics to track: {', '.join(inputs['metrics'])}
|
| 133 |
+
Time Period: {inputs['timeframe']}
|
| 134 |
+
Analysis Depth: {inputs['analysis_depth']}
|
| 135 |
+
Market Region: {inputs['market_region']}
|
| 136 |
+
Analysis Scope: {inputs['analysis_scope']}
|
| 137 |
+
|
| 138 |
+
Provide detailed analysis including:
|
| 139 |
+
1. Competitor Overview
|
| 140 |
+
2. Market Position
|
| 141 |
+
3. Strengths and Weaknesses
|
| 142 |
+
4. Competitive Advantages
|
| 143 |
+
5. Market Strategy
|
| 144 |
+
6. Future Outlook
|
| 145 |
+
|
| 146 |
+
Focus on the selected metrics and provide actionable insights.""",
|
| 147 |
+
expected_output="""A comprehensive competitor analysis document containing:
|
| 148 |
+
- Detailed analysis of each competitor
|
| 149 |
+
- Market positioning comparison
|
| 150 |
+
- Strengths and weaknesses analysis
|
| 151 |
+
- Strategic recommendations
|
| 152 |
+
The analysis should be data-driven and actionable.""",
|
| 153 |
+
agent=analyst
|
| 154 |
+
),
|
| 155 |
+
Task(
|
| 156 |
+
description=f"""Create a comprehensive competitor analysis report including:
|
| 157 |
+
1. Executive Summary
|
| 158 |
+
2. Detailed Analysis of Each Competitor
|
| 159 |
+
3. Comparative Analysis
|
| 160 |
+
4. Strategic Recommendations
|
| 161 |
+
5. Future Considerations
|
| 162 |
+
|
| 163 |
+
Use data and insights from the analysis to create a clear, actionable report.""",
|
| 164 |
+
expected_output="""A well-structured markdown report containing:
|
| 165 |
+
- Executive summary
|
| 166 |
+
- Competitor profiles and analysis
|
| 167 |
+
- Market positioning
|
| 168 |
+
- Strategic insights
|
| 169 |
+
- Actionable recommendations
|
| 170 |
+
The report should be clear, professional, and ready for executive review.""",
|
| 171 |
+
agent=writer
|
| 172 |
+
)
|
| 173 |
+
]
|
| 174 |
+
|
| 175 |
+
return Crew(
|
| 176 |
+
agents=[analyst, writer],
|
| 177 |
+
tasks=tasks,
|
| 178 |
+
verbose=True
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
def create_icp_report_crew(self, inputs):
|
| 182 |
+
analyst = Agent(
|
| 183 |
+
role='ICP Research Analyst',
|
| 184 |
+
goal=f'Create detailed Ideal Customer Profile for {inputs["company_name"]}',
|
| 185 |
+
backstory="""Expert in customer profiling, market segmentation, and buyer persona development.
|
| 186 |
+
Skilled at identifying and analyzing ideal customer characteristics and behaviors.""",
|
| 187 |
+
tools=[self.search_tool],
|
| 188 |
+
verbose=True
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
writer = Agent(
|
| 192 |
+
role='ICP Report Writer',
|
| 193 |
+
goal='Create comprehensive ICP analysis reports',
|
| 194 |
+
backstory="""Professional report writer specializing in customer profile documentation
|
| 195 |
+
and actionable insights for business strategy.""",
|
| 196 |
+
tools=[self.write_file_tool],
|
| 197 |
+
verbose=True
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
tasks = [
|
| 201 |
+
Task(
|
| 202 |
+
description=f"""Analyze and create Ideal Customer Profile for {inputs["company_name"]}
|
| 203 |
+
Industry: {inputs['industry']}
|
| 204 |
+
Business Model: {inputs.get('business_model', 'B2B')}
|
| 205 |
+
Target Market: {inputs.get('target_market', 'Global')}
|
| 206 |
+
Company Size: {inputs.get('company_size', 'All')}
|
| 207 |
+
|
| 208 |
+
Provide detailed analysis including:
|
| 209 |
+
1. Customer Demographics
|
| 210 |
+
2. Firmographics (for B2B)
|
| 211 |
+
3. Behavioral Patterns
|
| 212 |
+
4. Pain Points
|
| 213 |
+
5. Decision Making Process
|
| 214 |
+
6. Value Propositions
|
| 215 |
+
7. Buying Criteria
|
| 216 |
+
|
| 217 |
+
Focus on creating actionable customer insights.""",
|
| 218 |
+
expected_output="""A comprehensive ICP analysis containing:
|
| 219 |
+
- Detailed customer characteristics
|
| 220 |
+
- Market segment analysis
|
| 221 |
+
- Behavioral insights
|
| 222 |
+
- Purchase patterns
|
| 223 |
+
- Decision factors
|
| 224 |
+
The analysis should be data-driven and actionable.""",
|
| 225 |
+
agent=analyst
|
| 226 |
+
),
|
| 227 |
+
Task(
|
| 228 |
+
description=f"""Create a detailed ICP report including:
|
| 229 |
+
1. Executive Summary
|
| 230 |
+
2. Ideal Customer Profile Overview
|
| 231 |
+
3. Detailed Customer Characteristics
|
| 232 |
+
4. Market Segment Analysis
|
| 233 |
+
5. Customer Journey Mapping
|
| 234 |
+
6. Engagement Strategies
|
| 235 |
+
7. Implementation Recommendations
|
| 236 |
+
|
| 237 |
+
Use insights from the analysis to create a clear, actionable report.""",
|
| 238 |
+
expected_output="""A well-structured markdown report containing:
|
| 239 |
+
- Executive summary
|
| 240 |
+
- Detailed ICP analysis
|
| 241 |
+
- Market insights
|
| 242 |
+
- Strategic recommendations
|
| 243 |
+
The report should be clear, professional, and ready for executive review.""",
|
| 244 |
+
agent=writer
|
| 245 |
+
)
|
| 246 |
+
]
|
| 247 |
+
|
| 248 |
+
return Crew(
|
| 249 |
+
agents=[analyst, writer],
|
| 250 |
+
tasks=tasks,
|
| 251 |
+
verbose=True
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
def create_gap_analysis_crew(self, inputs):
|
| 255 |
+
analyst = Agent(
|
| 256 |
+
role='Gap Analysis Specialist',
|
| 257 |
+
goal=f'Analyze gaps and opportunities for {inputs["company_name"]}',
|
| 258 |
+
backstory="""Expert in identifying and analyzing organizational gaps, market gaps,
|
| 259 |
+
and strategic opportunities. Skilled at providing actionable recommendations.""",
|
| 260 |
+
tools=[self.search_tool],
|
| 261 |
+
verbose=True
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
writer = Agent(
|
| 265 |
+
role='Gap Analysis Report Writer',
|
| 266 |
+
goal='Create comprehensive gap analysis reports',
|
| 267 |
+
backstory="""Professional report writer specializing in gap analysis documentation
|
| 268 |
+
and strategic recommendations.""",
|
| 269 |
+
tools=[self.write_file_tool],
|
| 270 |
+
verbose=True
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
tasks = [
|
| 274 |
+
Task(
|
| 275 |
+
description=f"""Conduct gap analysis for {inputs["company_name"]} in {inputs["industry"]}
|
| 276 |
+
Focus Areas: {', '.join(inputs['focus_areas'])}
|
| 277 |
+
Time Period: {inputs['timeframe']}
|
| 278 |
+
Analysis Depth: {inputs['analysis_depth']}
|
| 279 |
+
Market Region: {inputs['market_region']}
|
| 280 |
+
|
| 281 |
+
Provide detailed analysis including:
|
| 282 |
+
1. Current State Assessment
|
| 283 |
+
2. Desired Future State
|
| 284 |
+
3. Gap Identification
|
| 285 |
+
4. Root Cause Analysis
|
| 286 |
+
5. Impact Assessment
|
| 287 |
+
6. Recommendations
|
| 288 |
+
|
| 289 |
+
Focus on the selected areas and provide actionable insights.""",
|
| 290 |
+
expected_output="""A comprehensive gap analysis containing:
|
| 291 |
+
- Current state evaluation
|
| 292 |
+
- Future state definition
|
| 293 |
+
- Gap identification and analysis
|
| 294 |
+
- Strategic recommendations
|
| 295 |
+
The analysis should be data-driven and actionable.""",
|
| 296 |
+
agent=analyst
|
| 297 |
+
),
|
| 298 |
+
Task(
|
| 299 |
+
description=f"""Create a detailed gap analysis report including:
|
| 300 |
+
1. Executive Summary
|
| 301 |
+
2. Current State Analysis
|
| 302 |
+
3. Future State Vision
|
| 303 |
+
4. Gap Identification
|
| 304 |
+
5. Impact Analysis
|
| 305 |
+
6. Strategic Recommendations
|
| 306 |
+
7. Implementation Roadmap
|
| 307 |
+
|
| 308 |
+
Use insights from the analysis to create a clear, actionable report.""",
|
| 309 |
+
expected_output="""A well-structured markdown report containing:
|
| 310 |
+
- Executive summary
|
| 311 |
+
- Detailed gap analysis
|
| 312 |
+
- Strategic recommendations
|
| 313 |
+
- Implementation plan
|
| 314 |
+
The report should be clear, professional, and ready for executive review.""",
|
| 315 |
+
agent=writer
|
| 316 |
+
)
|
| 317 |
+
]
|
| 318 |
+
|
| 319 |
+
return Crew(
|
| 320 |
+
agents=[analyst, writer],
|
| 321 |
+
tasks=tasks,
|
| 322 |
+
verbose=True
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
def create_market_assessment_crew(self, inputs):
|
| 326 |
+
"""Create crew for market assessment reports"""
|
| 327 |
+
analyst = Agent(
|
| 328 |
+
role='Market Assessment Analyst',
|
| 329 |
+
goal=f'Analyze market position and opportunities for {inputs["company_name"]}',
|
| 330 |
+
backstory="""Expert in market assessment and analysis. Skilled at evaluating
|
| 331 |
+
market conditions, competitive landscapes, and growth opportunities.""",
|
| 332 |
+
tools=[self.search_tool],
|
| 333 |
+
verbose=True
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
writer = Agent(
|
| 337 |
+
role='Market Assessment Writer',
|
| 338 |
+
goal='Create comprehensive market assessment reports',
|
| 339 |
+
backstory="""Professional report writer specializing in market assessment documentation
|
| 340 |
+
and strategic insights.""",
|
| 341 |
+
tools=[self.write_file_tool],
|
| 342 |
+
verbose=True
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
tasks = [
|
| 346 |
+
Task(
|
| 347 |
+
description=f"""Conduct market assessment for {inputs["company_name"]} in {inputs["industry"]}
|
| 348 |
+
Assessment Type: {inputs["market_type"]}
|
| 349 |
+
Focus Areas: {', '.join(inputs['focus_areas'])}
|
| 350 |
+
Market Region: {inputs['market_region']}
|
| 351 |
+
Timeframe: {inputs['timeframe']}
|
| 352 |
+
Key Metrics: {', '.join(inputs['metrics'])}
|
| 353 |
+
|
| 354 |
+
Provide detailed analysis including:
|
| 355 |
+
1. Market Overview
|
| 356 |
+
2. Competitive Position
|
| 357 |
+
3. Growth Opportunities
|
| 358 |
+
4. Market Trends
|
| 359 |
+
5. Risk Assessment
|
| 360 |
+
6. Strategic Recommendations
|
| 361 |
+
|
| 362 |
+
Focus on the selected areas and metrics to provide actionable insights.""",
|
| 363 |
+
expected_output="""A comprehensive market assessment containing:
|
| 364 |
+
- Market overview and size
|
| 365 |
+
- Competitive analysis
|
| 366 |
+
- Growth opportunities
|
| 367 |
+
- Strategic recommendations
|
| 368 |
+
The analysis should be data-driven and actionable.""",
|
| 369 |
+
agent=analyst
|
| 370 |
+
),
|
| 371 |
+
Task(
|
| 372 |
+
description=f"""Create a detailed market assessment report including:
|
| 373 |
+
1. Executive Summary
|
| 374 |
+
2. Market Analysis
|
| 375 |
+
3. Competitive Position
|
| 376 |
+
4. Growth Opportunities
|
| 377 |
+
5. Risk Assessment
|
| 378 |
+
6. Strategic Recommendations
|
| 379 |
+
7. Implementation Guidelines
|
| 380 |
+
|
| 381 |
+
Use insights from the analysis to create a clear, actionable report.""",
|
| 382 |
+
expected_output="""A well-structured markdown report containing:
|
| 383 |
+
- Executive summary
|
| 384 |
+
- Detailed market assessment
|
| 385 |
+
- Strategic recommendations
|
| 386 |
+
- Implementation guidelines
|
| 387 |
+
The report should be clear, professional, and ready for executive review.""",
|
| 388 |
+
agent=writer
|
| 389 |
+
)
|
| 390 |
+
]
|
| 391 |
+
|
| 392 |
+
return Crew(
|
| 393 |
+
agents=[analyst, writer],
|
| 394 |
+
tasks=tasks,
|
| 395 |
+
verbose=True
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
def create_impact_assessment_crew(self, inputs):
|
| 399 |
+
"""Create crew for impact assessment reports"""
|
| 400 |
+
analyst = Agent(
|
| 401 |
+
role='Impact Assessment Analyst',
|
| 402 |
+
goal=f'Analyze business impact for {inputs["company_name"]}',
|
| 403 |
+
backstory="""Expert in impact analysis and assessment. Skilled at evaluating
|
| 404 |
+
social, economic, and environmental impacts of business operations.""",
|
| 405 |
+
tools=[self.search_tool],
|
| 406 |
+
verbose=True
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
writer = Agent(
|
| 410 |
+
role='Impact Assessment Writer',
|
| 411 |
+
goal='Create comprehensive impact assessment reports',
|
| 412 |
+
backstory="""Professional report writer specializing in impact assessment documentation
|
| 413 |
+
and strategic recommendations.""",
|
| 414 |
+
tools=[self.write_file_tool],
|
| 415 |
+
verbose=True
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
tasks = [
|
| 419 |
+
Task(
|
| 420 |
+
description=f"""Analyze impact for {inputs["company_name"]} in {inputs["industry"]}
|
| 421 |
+
Impact Areas: {', '.join(inputs['impact_areas'])}
|
| 422 |
+
Timeframe: {inputs['timeframe']}
|
| 423 |
+
Region: {inputs['market_region']}
|
| 424 |
+
|
| 425 |
+
Provide detailed analysis including:
|
| 426 |
+
1. Social Impact Analysis
|
| 427 |
+
2. Economic Impact Assessment
|
| 428 |
+
3. Environmental Impact
|
| 429 |
+
4. Stakeholder Impact
|
| 430 |
+
5. Long-term Sustainability
|
| 431 |
+
6. Risk Assessment
|
| 432 |
+
7. Recommendations
|
| 433 |
+
|
| 434 |
+
Focus on quantifiable metrics and actionable insights.""",
|
| 435 |
+
expected_output="""A comprehensive impact assessment containing:
|
| 436 |
+
- Social impact metrics
|
| 437 |
+
- Economic impact analysis
|
| 438 |
+
- Environmental sustainability measures
|
| 439 |
+
- Stakeholder analysis
|
| 440 |
+
- Strategic recommendations
|
| 441 |
+
The analysis should be data-driven and actionable.""",
|
| 442 |
+
agent=analyst
|
| 443 |
+
),
|
| 444 |
+
Task(
|
| 445 |
+
description=f"""Create a detailed impact assessment report including:
|
| 446 |
+
1. Executive Summary
|
| 447 |
+
2. Impact Analysis Overview
|
| 448 |
+
3. Social Impact Assessment
|
| 449 |
+
4. Economic Impact Analysis
|
| 450 |
+
5. Environmental Impact Evaluation
|
| 451 |
+
6. Stakeholder Analysis
|
| 452 |
+
7. Risk Assessment
|
| 453 |
+
8. Strategic Recommendations
|
| 454 |
+
9. Implementation Guidelines
|
| 455 |
+
|
| 456 |
+
Use insights from the analysis to create a clear, actionable report.""",
|
| 457 |
+
expected_output="""A well-structured markdown report containing:
|
| 458 |
+
- Executive summary
|
| 459 |
+
- Detailed impact assessment
|
| 460 |
+
- Key metrics and findings
|
| 461 |
+
- Strategic recommendations
|
| 462 |
+
The report should be clear, professional, and ready for executive review.""",
|
| 463 |
+
agent=writer
|
| 464 |
+
)
|
| 465 |
+
]
|
| 466 |
+
|
| 467 |
+
return Crew(
|
| 468 |
+
agents=[analyst, writer],
|
| 469 |
+
tasks=tasks,
|
| 470 |
+
verbose=True
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
def generate_report(self, report_type, inputs):
|
| 474 |
+
# Convert report type to match the crew creator function names
|
| 475 |
+
report_type = report_type.lower().replace(' ', '_')
|
| 476 |
+
|
| 477 |
+
crew_creators = {
|
| 478 |
+
'market_analysis': self.create_market_analysis_crew,
|
| 479 |
+
'competitor_tracking': self.create_competitor_tracking_crew,
|
| 480 |
+
'icp_report': self.create_icp_report_crew,
|
| 481 |
+
'gap_analysis': self.create_gap_analysis_crew,
|
| 482 |
+
'market_assessment': self.create_market_assessment_crew,
|
| 483 |
+
'impact_assessment': self.create_impact_assessment_crew
|
| 484 |
+
}
|
| 485 |
+
|
| 486 |
+
if report_type not in crew_creators:
|
| 487 |
+
raise ValueError(f"Invalid report type: {report_type}")
|
| 488 |
+
|
| 489 |
+
crew = crew_creators[report_type](inputs)
|
| 490 |
+
if crew is None:
|
| 491 |
+
raise ValueError(f"Failed to create crew for report type: {report_type}")
|
| 492 |
+
|
| 493 |
+
return crew.kickoff()
|
| 494 |
+
|
| 495 |
+
def create_reports(result, inputs, report_type):
|
| 496 |
+
timestamp = time.strftime('%Y%m%d_%H%M%S')
|
| 497 |
+
base_name = f"{inputs['company_name']}_{report_type}_{timestamp}"
|
| 498 |
+
|
| 499 |
+
validation_file = f"{base_name}_validation.txt"
|
| 500 |
+
report_file = f"{base_name}_report.md"
|
| 501 |
+
|
| 502 |
+
# Create validation report
|
| 503 |
+
with open(validation_file, 'w') as f:
|
| 504 |
+
f.write(f"Validation Report for {inputs['company_name']}\n")
|
| 505 |
+
f.write(f"Report Type: {report_type}\n")
|
| 506 |
+
f.write(f"Generated on: {time.strftime('%Y-%m-%d %H:%M:%S')}\n\n")
|
| 507 |
+
f.write(str(result))
|
| 508 |
+
|
| 509 |
+
# Create main report
|
| 510 |
+
with open(report_file, 'w') as f:
|
| 511 |
+
f.write(f"# {report_type.replace('_', ' ').title()} Report\n\n")
|
| 512 |
+
f.write(f"## Overview\n")
|
| 513 |
+
f.write(f"Company: {inputs['company_name']}\n")
|
| 514 |
+
# Add report-specific content
|
| 515 |
+
f.write(str(result))
|
| 516 |
+
|
| 517 |
+
return validation_file, report_file
|
| 518 |
+
|
| 519 |
+
def get_report_generator():
|
| 520 |
+
return ReportGenerator()
|
| 521 |
+
|
| 522 |
+
def get_market_analysis_crew(user_inputs):
|
| 523 |
+
"""Backward compatibility function for existing code"""
|
| 524 |
+
generator = ReportGenerator()
|
| 525 |
+
return generator.create_market_analysis_crew(user_inputs)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
flask-cors
|
| 3 |
+
python-dotenv
|
| 4 |
+
crewai
|
| 5 |
+
langchain
|
| 6 |
+
google-generativeai
|
| 7 |
+
serpapi
|
| 8 |
+
requests
|
| 9 |
+
beautifulsoup4
|
| 10 |
+
markdown
|
| 11 |
+
python-dotenv
|