Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, Body | |
from crewai import Crew, Process | |
from agents import SneakerAgents | |
from tasks import SneakerTasks | |
from tools.search_tools import SearchTools | |
from dotenv import load_dotenv | |
import os | |
# Load environment variables | |
dotenv_path = os.path.join(os.path.dirname(__file__), '.env') | |
load_dotenv(dotenv_path) | |
# Initialize the SearchTools, SneakerAgents, and SneakerTasks once | |
search_tools = SearchTools() | |
agents = SneakerAgents(search_tools) | |
tasks = SneakerTasks() | |
class SneakerCrew: | |
def __init__(self, brand, gender): | |
self.brand = brand | |
self.gender = gender | |
def run(self): | |
# Sequential initialization of agents | |
sneaker_expert = agents.sneaker_expert() | |
resale_expert = agents.resale_expert() | |
# Sequential creation of tasks | |
combined_task = tasks.suggest_and_fetch_upcoming_shoes(sneaker_expert, self.brand, self.gender) | |
estimate_resale_value_task = tasks.estimate_resale_value(resale_expert, self.brand) | |
# Initialize the crew sequentially | |
crew = Crew( | |
agents=[sneaker_expert, resale_expert], | |
tasks=[combined_task, estimate_resale_value_task], | |
verbose=True, | |
process=Process.sequential | |
) | |
result = crew.kickoff() | |
return result | |
app = FastAPI() | |
def sneaker_worth_finder(brand: str = Body(...), gender: str = Body(...)): | |
sneaker_crew = SneakerCrew(brand, gender) | |
result = sneaker_crew.run() | |
return result | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=8002) |