initial commit
Browse files- app.py +32 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_name = "rafaelcarvalhoj/emotion-classifier"
|
| 6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
|
| 9 |
+
mapping = {
|
| 10 |
+
0: 'anger',
|
| 11 |
+
1: 'joy',
|
| 12 |
+
2: 'fear'
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
def predict(text):
|
| 16 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 17 |
+
|
| 18 |
+
outputs = model(**inputs)
|
| 19 |
+
predictions = outputs.logits
|
| 20 |
+
|
| 21 |
+
return mapping[round(predictions.item())]
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs="text",
|
| 26 |
+
outputs="text",
|
| 27 |
+
layout="vertical",
|
| 28 |
+
title="Classificador de emoΓ§Γ΅es em uma frase",
|
| 29 |
+
description="Este modelo analisa uma frase em inglΓͺs e diz qual sentimento mais se aproxima da frase apresentada. A frase pode ser classificada em Joy, Anger e Fear"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
|
File without changes
|