Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Carregar o modelo e o tokenizer
|
| 6 |
+
model_name = "vic35get/nhtsa_complaints_classifier"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# Função para inferência
|
| 11 |
+
def predict(text):
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
return torch.argmax(outputs.logits, dim=1).item()
|
| 16 |
+
|
| 17 |
+
# Interface Gradio
|
| 18 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs="text")
|
| 19 |
+
|
| 20 |
+
# Rodar a interface
|
| 21 |
+
iface.launch()
|