Test / app.py
Radhyah's picture
Update app.py
71c6b18 verified
raw
history blame contribute delete
779 Bytes
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()