Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,23 @@ from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
model = AutoModelForSequenceClassification.from_pretrained("my-
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained("my-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 10 |
with torch.no_grad():
|
| 11 |
outputs = model(**inputs)
|
| 12 |
-
|
| 13 |
-
return
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
model = AutoModelForSequenceClassification.from_pretrained("my-flava-model")
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("my-flava-model")
|
| 7 |
|
| 8 |
+
# Map label numbers to string categories (customize this part!)
|
| 9 |
+
label_map = {
|
| 10 |
+
0: "Spicy",
|
| 11 |
+
1: "Mild",
|
| 12 |
+
2: "Tangy",
|
| 13 |
+
3: "Salty"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def classify(text):
|
| 17 |
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 18 |
with torch.no_grad():
|
| 19 |
outputs = model(**inputs)
|
| 20 |
+
pred = torch.argmax(outputs.logits, dim=1).item()
|
| 21 |
+
return label_map[pred]
|
| 22 |
|
| 23 |
+
demo = gr.Interface(fn=classify, inputs="text", outputs="text", title="What's Your Flava?")
|
| 24 |
+
demo.launch()
|