sushilideaclan01's picture
refactored the files
d4a4da7
"""Info, root, and health endpoints."""
import httpx
from fastapi import APIRouter
from fastapi.responses import Response as FastAPIResponse
router = APIRouter(tags=["info"])
@router.get("/api/info")
async def api_info():
"""API info endpoint."""
return {
"name": "PsyAdGenesis",
"version": "2.0.0",
"description": "Design ads that stop the scroll. Generate high-converting ads using Angle Γ— Concept matrix system",
"endpoints": {
"POST /generate": "Generate single ad (original mode)",
"POST /generate/batch": "Generate multiple ads (original mode)",
"POST /matrix/generate": "Generate ad using Angle Γ— Concept matrix",
"POST /matrix/testing": "Generate testing matrix (30 combinations)",
"GET /matrix/angles": "List all 100 angles",
"GET /matrix/concepts": "List all 100 concepts",
"GET /matrix/angle/{key}": "Get specific angle details",
"GET /matrix/concept/{key}": "Get specific concept details",
"GET /matrix/compatible/{angle_key}": "Get compatible concepts for angle",
"POST /extensive/generate": "Generate ad using extensive (researcher β†’ creative director β†’ designer β†’ copywriter)",
"POST /api/motivator/generate": "Generate motivators from niche + angle + concept (Matrix mode)",
"POST /api/correct": "Correct image for spelling mistakes and visual issues (requires image_id)",
"POST /api/regenerate": "Regenerate image with optional model selection (requires image_id)",
"GET /api/models": "List all available image generation models",
"POST /api/creative/upload": "Upload a creative image for analysis",
"POST /api/creative/analyze": "Analyze a creative image with AI vision (via URL)",
"POST /api/creative/analyze/upload": "Analyze a creative image with AI vision (via file upload)",
"POST /api/creative/modify": "Modify a creative with new angle/concept",
"GET /api/trends/{niche}": "Get current trending topics from Google News",
"GET /api/trends/angles/{niche}": "Get auto-generated angles from trending topics",
"GET /health": "Health check",
},
"supported_niches": ["home_insurance", "glp1"],
"matrix_system": {
"total_angles": 100,
"total_concepts": 100,
"possible_combinations": 10000,
"formula": "1 Offer β†’ 5-8 Angles β†’ 3-5 Concepts per angle",
},
}
@router.get("/")
async def root():
"""Proxy root to Next.js frontend."""
try:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get("http://localhost:3000/")
return FastAPIResponse(
content=response.content,
status_code=response.status_code,
headers={k: v for k, v in response.headers.items() if k.lower() not in ["content-encoding", "transfer-encoding", "content-length"]},
media_type=response.headers.get("content-type"),
)
except httpx.RequestError:
return FastAPIResponse(
content="<html><head><meta http-equiv='refresh' content='2'></head><body><h1>Loading...</h1></body></html>",
status_code=200,
media_type="text/html",
)
@router.get("/health")
async def health():
"""Health check endpoint for Hugging Face Spaces."""
return {"status": "ok"}