Nemai commited on
Commit
4a95be2
·
verified ·
1 Parent(s): 343f1ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ # Define function to use in Gradio
8
+ def analyze_sentiment(text):
9
+ result = sentiment_pipeline(text)[0]
10
+ label = result['label']
11
+ score = round(result['score'], 3)
12
+ return f"Sentiment: {label} (confidence: {score})"
13
+
14
+ # Create Gradio interface
15
+ demo = gr.Interface(fn=analyze_sentiment,
16
+ inputs=gr.Textbox(lines=4, placeholder="Enter text here..."),
17
+ outputs="text",
18
+ title="Sentiment Analysis App",
19
+ description="Enter text and get the sentiment prediction using a Hugging Face transformer model.")
20
+
21
+ # Launch app
22
+ demo.launch()