hrishikesh
Create app.py
1116146
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
sentiment_analysis_interface = gr.Interface( title = 'Write a review of anything and get sentiment analysis - Built by Hrishikesh', fn = sentiment_gradio,
inputs="text",
outputs= gr.outputs.Label(num_top_classes=2),
interpretation="default")
sentiment_analysis_interface.launch(debug=True)