File size: 1,433 Bytes
c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda c7cfcb9 7e13eda |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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) |