Priyanhsu commited on
Commit
388d90c
·
verified ·
1 Parent(s): c8dee82

Seniment.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 the pre-trained model
5
+ classifier = pipeline('sentiment-analysis')
6
+
7
+ # Define the prediction function
8
+ def predict_sentiment(text):
9
+ results = classifier(text)
10
+ return results[0]['label'], results[0]['score']
11
+
12
+ # Create the Gradio interface
13
+ iface = gr.Interface(
14
+ fn=predict_sentiment,
15
+ inputs="text",
16
+ outputs=["text", "number"],
17
+ title="Sentiment Analysis",
18
+ description="Enter text to classify its sentiment as positive or negative."
19
+ )
20
+
21
+ # Launch the interface
22
+ iface.launch()