Create app.py
Browse filesprediction interface
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()
|