AfroLogicInsect commited on
Commit
1e9a573
Β·
verified Β·
1 Parent(s): f1be52f

Create app.py

Browse files

prediction interface

Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ ## Load Pipeline
5
+ sentiment_pipeline == pipeline("sentiment-analysis",
6
+ model="AfroLogicInsect/sentiment-analysis-model")
7
+
8
+ def predict_sentiment(text):
9
+ if not text.strip():
10
+ return "Please enter some text", 0.0
11
+
12
+ result = sentiment_pipeline(text)[0]
13
+ label = "😊 Positive" if result['label'] == 'LABEL_1' else "😞 Negative"
14
+ return label, round(result['score'], 3)
15
+
16
+ iface = gr.Interface(
17
+ fn = predict_sentiment,
18
+ inputs=gr.Textbox(label="Enter text"),
19
+ outputs=[gr.Text(label="Sentiment"),
20
+ gr.Number(label="Confidence")]
21
+ )
22
+
23
+ iface.launch()