Spaces:
Sleeping
Sleeping
File size: 700 Bytes
b022b26 8a8fd9e b022b26 dbe1640 8a8fd9e 0a9c1ca dbe1640 8a8fd9e dbe1640 8a8fd9e 3e8d9d1 dbe1640 b022b26 | 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 | import os
os.environ["HF_HOME"] = "/tmp" # ensure Hugging Face cache is writable
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import pipeline
# Load the Hugging Face model
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
# Define FastAPI app
app = FastAPI()
# Health check route
@app.get("/")
def read_root():
return {"status": "ok", "message": "API is running"}
# Define request schema
class Query(BaseModel):
text: str
# Prediction route (POST /)
@app.post("/predict")
def predict(query: Query):
result = classifier(query.text)[0]
return {"label": result["label"], "score": result["score"]}
|