itsmemauli commited on
Commit
96a0cab
1 Parent(s): fda30f1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained sentiment analysis model
5
+ model_name = "distilbert-base-uncased-finetuned-sst-2-english"
6
+ sentiment_model = pipeline("text-classification", model=model_name)
7
+
8
+ # Define the function to analyze sentiment
9
+ def analyze_sentiment(input_text):
10
+ result = sentiment_model(input_text)[0]
11
+ label = result["label"]
12
+ score = result["score"]
13
+ return f"Sentiment: {label}, Confidence: {score:.2f}"
14
+
15
+ # Create the Gradio interface
16
+ interface = gr.Interface(
17
+ fn=analyze_sentiment,
18
+ inputs="text",
19
+ outputs="text",
20
+ title="Sentiment Analysis App",
21
+ description="Enter a sentence to analyze its sentiment (Positive or Negative).",
22
+ )
23
+
24
+ # Launch the app
25
+ interface.launch()