Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 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 |
+
def classify_text(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 10 |
+
with torch.no_grad():
|
| 11 |
+
outputs = model(**inputs)
|
| 12 |
+
prediction = torch.argmax(outputs.logits, dim=1).item()
|
| 13 |
+
return str(prediction)
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(fn=classify_text, inputs="text", outputs="text")
|
| 16 |
+
iface.launch()
|