Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, Form | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from model import predict_logic | |
| import uvicorn | |
| app = FastAPI(title="Titanium Protocol API") | |
| # Enable CORS for Vercel Frontend | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # Allows all frontends (Vercel, Localhost, etc.) | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def health_check(): | |
| """Health check for Hugging Face monitoring.""" | |
| return {"status": "Titanium Protocol Online"} | |
| async def handle_prediction(book_text: str = Form(...), backstory: str = Form(...)): | |
| """The main endpoint called by your frontend.""" | |
| # This calls the logic we defined in model.py | |
| result = predict_logic(book_text, backstory) | |
| return result | |
| if __name__ == "__main__": | |
| # Standard port for Hugging Face Spaces | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |