Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
senti_pipeline = pipeline("sentiment-analysis") | |
senti_pipeline("I am extremely happy to share this video with all of you") | |
senti_pipeline("I am sad that you haven't subscribed to my channel yet") | |
def sentiment_gradio(input): | |
result = senti_pipeline(input) | |
if result[0]["label"] == "POSITIVE": | |
pos_score = round(result[0]["score"], 2) | |
neg_score = 1 - pos_score | |
else: | |
neg_score = round(1*result[0]["score"], 2) | |
pos_score = 1 - neg_score | |
res = {'Positive': pos_score, 'Negative': neg_score} | |
return res | |
examples = ['I am extremely happy to share this video with all of you','I am tired due to heavy work','the movie was good'] | |
sentiment_analysis_interface = gr.Interface(fn = sentiment_gradio, | |
inputs="text", | |
outputs= gr.outputs.Label(num_top_classes=2), | |
interpretation="default",examples = examples, title="SENTIMENT ANALYSIS") | |
sentiment_analysis_interface.launch(debug=True) |