nasreshsuguru commited on
Commit
cf0f335
·
verified ·
1 Parent(s): 2051ec7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ # Define function for prediction
8
+ def analyze_sentiment(text):
9
+ result = sentiment_pipeline(text)[0]
10
+ label = result['label']
11
+ score = result['score']
12
+ return f"{label} ({score:.2f})"
13
+
14
+ # Create Gradio interface
15
+ interface = gr.Interface(fn=analyze_sentiment,
16
+ inputs="text",
17
+ outputs="text",
18
+ title="Sentiment Analyzer",
19
+ description="Type a sentence to see if it's Positive or Negative")
20
+
21
+ # Launch the app
22
+ interface.launch()