Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,31 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
# Initialize the FastAPI app
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
| 4 |
+
import os
|
| 5 |
|
|
|
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Set the Hugging Face token from the environment variable
|
| 9 |
+
token = os.getenv("token")
|
| 10 |
+
|
| 11 |
+
# Load the model and tokenizer using the token
|
| 12 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 13 |
+
"kmcs-casulit/hr_cate", use_auth_token=token)
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 15 |
+
"kmcs-casulit/hr_cate", use_auth_token=token)
|
| 16 |
+
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class TextInput(BaseModel):
|
| 20 |
+
text: str
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@app.get("/")
|
| 24 |
+
def greet_json():
|
| 25 |
+
return {"message": "Hello, World!"}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@app.post("/classify/")
|
| 29 |
+
def classify(input: TextInput):
|
| 30 |
+
output = pipe(input.text)
|
| 31 |
+
return {"output": output[0]['label']}
|