Spaces:
Sleeping
Sleeping
File size: 942 Bytes
8172812 e2aa18d 8172812 e2aa18d bfced6f e2aa18d bfced6f e2aa18d 5e4c2ef e2aa18d bfced6f e2aa18d bfced6f e2aa18d bfced6f 8172812 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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=["*"],
)
@app.get("/")
def health_check():
"""Health check for Hugging Face monitoring."""
return {"status": "Titanium Protocol Online"}
@app.post("/predict")
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) |