|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
sentiment_pipeline = pipeline("sentiment-analysis", model="your-username/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 |
|
|
|
|
|
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" |
|
) |
|
|
|
|
|
iface.launch() |