subject_matter / app.py
pleonova's picture
Sets the TRANSFORMERS_CACHE environment variable as a fallback
7d6a1d4 verified
raw
history blame
484 Bytes
import os
from fastapi import FastAPI
from transformers import pipeline
# Set a custom Hugging Face cache directory
os.environ["TRANSFORMERS_CACHE"] = "/app/.cache"
app = FastAPI()
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
@app.post("/predict")
async def predict(data: dict):
labels = ["Mathematics", "Language Arts", "Social Studies", "Science"]
result = classifier(data["text"], labels)
return {"label": result["labels"][0]}