Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from starlette.middleware.cors import CORSMiddleware | |
| from .api.v1 import upload, captions | |
| app = FastAPI( | |
| title="AI Meme Generator", | |
| description="Upload images and get funny meme captions", | |
| # docs_url="/docs", # Swagger UI at /swagger | |
| # redoc_url="/redocly" # ReDoc at /redocly | |
| ) | |
| # Register routes | |
| app.include_router(upload.router, prefix="/api/v1", tags=["upload"]) | |
| app.include_router(captions.router, prefix="/api/v1", tags=["captions"]) | |
| async def read_root(): | |
| # list_fastapi_routes(app) | |
| return {"message": "AI Meme Generator is running 🚀"} | |
| # ✅ Enable CORS so frontend can talk to backend | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["https://ai-meme-generator-pi.vercel.app"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Function to list routes | |
| def list_fastapi_routes(fastapi_app: FastAPI): | |
| print("FastAPI Routes:") | |
| for route in fastapi_app.routes: | |
| # Check if the route has a path attribute (it should for HTTP routes) | |
| if hasattr(route, "path"): | |
| print(f" Path: {route.path}, Name: {route}, Methods: {getattr(route, 'methods', 'N/A')}") | |
| else: | |
| print(f" Non-HTTP Route: {route.__class__.__name__}") | |