File size: 779 Bytes
e5455aa 71c6b18 e5455aa 71c6b18 e5455aa 71c6b18 e5455aa 71c6b18 e5455aa | 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 | from transformers import pipeline
import gradio as gr
# Define the sentiment analysis pipeline
sentiment_model = pipeline("sentiment-analysis")
# Define the function to analyze sentiment
def get_sentiment(text):
result = sentiment_model(text)[0]
sentiment = result['label']
score = result['score']
return sentiment, round(score, 2)
# Build the Gradio interface
interface = gr.Interface(
fn=get_sentiment,
inputs=gr.Textbox(label="Enter the review:", placeholder="Write your review here..."),
outputs=[
gr.Textbox(label="Sentiment:"),
gr.Textbox(label="Score:")
],
title="Sentiment Analysis Prototype",
description="Enter a review and get the sentiment and confidence score."
)
# Launch the interface
interface.launch()
|