Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import DistilBertForSequenceClassification, DistilBertTokenizerFast
|
3 |
+
import torch
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
model = DistilBertForSequenceClassification.from_pretrained("your-username/distilbert-recommendation")
|
8 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained("your-username/distilbert-recommendation")
|
9 |
+
|
10 |
+
@app.post("/predict/")
|
11 |
+
async def predict(text: str):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
13 |
+
outputs = model(**inputs)
|
14 |
+
prediction = torch.argmax(outputs.logits, dim=-1).item()
|
15 |
+
return {"prediction": prediction}
|