|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from transformers import pipeline |
|
|
|
|
|
class RequestModel(BaseModel): |
|
text: str |
|
|
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
try: |
|
classifier = pipeline("text-classification", model="ShazaAly/syplyd-marbert-1") |
|
print("Model loaded successfully!") |
|
except Exception as e: |
|
classifier = None |
|
print(f"Error loading model: {e}") |
|
|
|
@app.get("/") |
|
def read_root(): |
|
return {"status": "online", "model": "ShazaAly/syplyd-marbert-1"} |
|
|
|
@app.post("/classify") |
|
def classify_intent(request: RequestModel): |
|
if not classifier: |
|
return {"error": "Model could not be loaded."}, 500 |
|
|
|
|
|
results = classifier(request.text) |
|
return results[0] |