Spaces:
Sleeping
Sleeping
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 movie review here...", | |
label="Movie Review" | |
), | |
outputs=[ | |
gr.Textbox(label="Sentiment"), | |
gr.Textbox(label="Confidence") | |
], | |
title="IMDb Sentiment Analysis with RoBERTa", | |
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() |