File size: 1,172 Bytes
542254c 0bc2ca7 542254c |
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 |
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
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter a movie review here...", label="Movie Review"),
outputs=[
gr.outputs.Textbox(label="Sentiment"),
gr.outputs.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()
|