Spaces:
Sleeping
Sleeping
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':'assets/negative.jpg', | |
'neutral':'assets/neutral.jpg', | |
'positive':'assets/positive.jpeg' | |
} | |
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=gr.Textbox(lines=2, placeholder="Escrbe algo para comenzar", label='Escribe algo para comenzar'), | |
outputs="image", | |
title="Analizador de Sentimientos") | |
demo.launch(share=True) |