Spaces:
Sleeping
Sleeping
File size: 798 Bytes
5981bca 198f981 5981bca 198f981 b770003 683da6d 5981bca 198f981 683da6d 198f981 683da6d 5981bca 683da6d |
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 32 33 34 |
import gradio as gr
import pickle
from transformers import pipeline
def load_model(selected_model):
with open(selected_model, 'rb') as file:
loaded_model = pickle.load(file)
return loaded_model
encoder = {
'negative': "Negativo",
'neutral': "Neutro",
'positive': "Positivo"
}
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
def analyze_sentiment(text):
results = classifier(text, ["positive", "negative", "neutral"], multi_label=True)
mx = max(results['scores'])
ind = results['scores'].index(mx)
result = results['labels'][ind]
return encoder[result]
demo = gr.Interface(
fn=analyze_sentiment,
inputs="text",
outputs="text",
title="Análisis de Sentimientos"
)
demo.launch(share=True)
|