Spaces:
Sleeping
Sleeping
# app/main.py | |
from fastapi import FastAPI | |
from fastapi.middleware.cors import CORSMiddleware | |
from app.models.recipe import RecipeRequest, RecipeResponse | |
from app.services.recipe_generator import RecipeGenerator | |
app = FastAPI(title="Recipe Generation API") | |
# Configure CORS for Vercel frontend | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], # Update this with your Vercel app URL in production | |
allow_credentials=True, | |
allow_methods=["*"], | |
allow_headers=["*"], | |
) | |
# Initialize recipe generator service | |
recipe_generator = RecipeGenerator() | |
async def root(): | |
return {"message": "Recipe Generation API is running"} | |
async def generate_recipe(request: RecipeRequest): | |
recipe = await recipe_generator.generate(request.ingredients) | |
return RecipeResponse( | |
title=recipe["title"], | |
ingredients=recipe["ingredients"], | |
instructions=recipe["instructions"] | |
) |