| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from pydantic import BaseModel |
| from transformers import pipeline |
| import uvicorn |
|
|
| |
| app = FastAPI(title="OrcaleSeek API", version="1.0.0") |
|
|
| |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| |
| 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)}" |
| ) |
|
|
| |
| if __name__ == "__main__": |
| uvicorn.run(app, host="0.0.0.0", port=8000) |