Spaces:
Runtime error
Runtime error
File size: 812 Bytes
56263f8 5f29aa7 5a33d2c 0f499af 5f29aa7 6ec24c2 5f29aa7 6ec24c2 5f29aa7 |
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 |
from fastapi import FastAPI
from pydantic import BaseModel
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
import os
app = FastAPI()
# Set the Hugging Face token from the environment variable
token = os.getenv("token")
# Load the model and tokenizer using the token
model = AutoModelForSequenceClassification.from_pretrained(
"kmcs-casulit/hr_cate", token=token)
tokenizer = AutoTokenizer.from_pretrained(
"kmcs-casulit/hr_cate", token=token)
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
class TextInput(BaseModel):
text: str
@app.get("/")
def greet_json():
return {"message": "Hello, World!"}
@app.post("/classify/")
def classify(input: TextInput):
output = pipe(input.text)
return {"output": output[0]['label']}
|