Spaces:
Build error
Build error
| import os | |
| import sys | |
| # Ensure this folder has priority for local imports (avoids root `tools.py` conflict) | |
| THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| if THIS_DIR not in sys.path: | |
| sys.path.insert(0, THIS_DIR) | |
| from crewai import Crew, Process | |
| from agents import researcher, analyst, writer | |
| from tasks import create_tasks | |
| from tools import gather_leads | |
| def run_lead_gen(target_audience, service, sender_name): | |
| # Step 0 - improve search query to favor real business sites over directory pages | |
| search_query = f"{target_audience} official website contact" | |
| # Step 1 - gather raw leads using tools | |
| raw_leads = gather_leads(search_query) | |
| if not raw_leads: | |
| return "No leads found. Try a different target audience." | |
| # format leads for tasks | |
| leads_data = "" | |
| for i, lead in enumerate(raw_leads): | |
| leads_data += f""" | |
| Lead {i+1}: | |
| Name: {lead['name']} | |
| Website: {lead['website']} | |
| Summary: {lead['summary']} | |
| Details: {lead['details']} | |
| --- | |
| """ | |
| # Step 2 - create tasks with lead data | |
| tasks = create_tasks(leads_data, service, sender_name, target_audience) | |
| # Step 3 - assemble and run crew | |
| crew = Crew( | |
| agents=[researcher, analyst, writer], | |
| tasks=tasks, | |
| process=Process.sequential, | |
| verbose=True | |
| ) | |
| result = crew.kickoff() | |
| return str(result) | |