File size: 854 Bytes
aaa9850 a19509f aaa9850 a19509f aaa9850 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
model_name = "Bittar/NLP_Emotions"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
mapping = {
0: 'negative',
1: 'positive'
}
def predict(text):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
predictions = outputs.logits
return mapping[round(predictions.item())]
iface = gr.Interface(
fn=predict,
inputs="text",
outputs="text",
layout="vertical",
title="Classificador de emoções em uma frase",
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"
)
iface.launch(share=True) |