from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel from transformers import pipeline import uvicorn # Initialize app app = FastAPI(title="OrcaleSeek API", version="1.0.0") # CORS for web access app.add_middleware( CORSMiddleware, allow_origins=["*"], # Change this to your website domain allow_methods=["*"], allow_headers=["*"], ) # Load model classifier = pipeline( "text-classification", model="your-username/OrcaleSeek", tokenizer="your-username/OrcaleSeek" ) class PredictionRequest(BaseModel): text: str max_length: int = 128 class PredictionResponse(BaseModel): prediction: list status: str model: str = "OrcaleSeek" @app.get("/") def home(): return {"message": "OrcaleSeek API is running! 🚀"} @app.get("/health") def health_check(): return {"status": "healthy"} @app.post("/predict", response_model=PredictionResponse) async def predict(request: PredictionRequest): try: result = classifier(request.text) return PredictionResponse( prediction=result, status="success" ) except Exception as e: return PredictionResponse( prediction=[], status=f"error: {str(e)}" ) # Run with: uvicorn api:app --host 0.0.0.0 --port 8000 --reload if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000)