Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel | |
| from main import get_analysis, AdAnalysis | |
| app = FastAPI(title="Images API", version="1.0.0") | |
| # CORS (open by default; tighten if needed) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], | |
| ) | |
| class GenerateRequest(BaseModel): | |
| img_url: str | |
| class GenerateResponse(BaseModel): | |
| analysis: AdAnalysis | |
| def health(): | |
| return {"ok": True} | |
| def generate(req: GenerateRequest): | |
| try: | |
| analysis = get_analysis(req.img_url) | |
| return {"analysis": analysis} | |
| except Exception as e: | |
| # Log in real app; return sanitized error | |
| raise HTTPException(status_code=500, detail=str(e)) | |