quocviethere
commited on
Commit
β’
542254c
1
Parent(s):
1a9839c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the sentiment analysis pipeline with your model
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model="your-username/imdb-roberta")
|
6 |
+
|
7 |
+
def analyze_sentiment(text):
|
8 |
+
result = sentiment_pipeline(text)[0]
|
9 |
+
label = result['label']
|
10 |
+
score = result['score']
|
11 |
+
sentiment = "Positive π" if label == "POSITIVE" else "Negative π"
|
12 |
+
confidence = f"Confidence: {round(score * 100, 2)}%"
|
13 |
+
return sentiment, confidence
|
14 |
+
|
15 |
+
# Define the Gradio interface
|
16 |
+
iface = gr.Interface(
|
17 |
+
fn=analyze_sentiment,
|
18 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter a movie review here...", label="Movie Review"),
|
19 |
+
outputs=[
|
20 |
+
gr.outputs.Textbox(label="Sentiment"),
|
21 |
+
gr.outputs.Textbox(label="Confidence")
|
22 |
+
],
|
23 |
+
title="IMDb Sentiment Analysis with RoBERTa",
|
24 |
+
description="Analyze the sentiment of movie reviews using a fine-tuned RoBERTa model.",
|
25 |
+
examples=[
|
26 |
+
["I loved the cinematography and the story was captivating."],
|
27 |
+
["The movie was a complete waste of time. Poor acting and boring plot."]
|
28 |
+
],
|
29 |
+
theme="default"
|
30 |
+
)
|
31 |
+
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch()
|