quocviethere commited on
Commit
48acb5c
Β·
verified Β·
1 Parent(s): b89451b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="quocviethere/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 using the updated API
16
+ iface = gr.Interface(
17
+ fn=analyze_sentiment,
18
+ inputs=gr.Textbox(
19
+ lines=5,
20
+ placeholder="Enter a movie review here...",
21
+ label="Movie Review"
22
+ ),
23
+ outputs=[
24
+ gr.Textbox(label="Sentiment"),
25
+ gr.Textbox(label="Confidence")
26
+ ],
27
+ title="IMDb Sentiment Analysis with RoBERTa",
28
+ description="Analyze the sentiment of movie reviews using a fine-tuned RoBERTa model.",
29
+ examples=[
30
+ ["I loved the cinematography and the story was captivating."],
31
+ ["The movie was a complete waste of time. Poor acting and boring plot."]
32
+ ],
33
+ theme="default"
34
+ )
35
+
36
+ # Launch the interface
37
+ iface.launch()