File size: 1,170 Bytes
542254c 6389bbd 542254c 90cad01 542254c 90cad01 33759e3 90cad01 542254c 90cad01 542254c 33759e3 542254c 90cad01 |
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 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from transformers import pipeline
# Initialize the sentiment analysis pipeline with your model
sentiment_pipeline = pipeline("sentiment-analysis", model="quocviethere/imdb-roberta")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
label = result['label']
score = result['score']
sentiment = "Positive π" if label == "POSITIVE" else "Negative π"
confidence = f"Confidence: {round(score * 100, 2)}%"
return sentiment, confidence
# Define the Gradio interface using the updated API
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(
lines=5,
placeholder="Enter a review here...",
label="Review"
),
outputs=[
gr.Textbox(label="Sentiment"),
gr.Textbox(label="Confidence")
],
title="Sentiment Analysis",
description="Analyze the sentiment of movie reviews using a fine-tuned RoBERTa model.",
examples=[
["I loved the cinematography and the story was captivating."],
["The movie was a complete waste of time. Poor acting and boring plot."]
],
theme="default"
)
# Launch the interface
iface.launch() |