Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,16 +23,35 @@ def predict(text):
|
|
| 23 |
predicted_class = torch.argmax(probs, dim=1).item()
|
| 24 |
confidence = probs[0][predicted_class].item()
|
| 25 |
|
| 26 |
-
label = "
|
| 27 |
-
|
| 28 |
-
return f"{
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
demo.launch()
|
|
|
|
| 23 |
predicted_class = torch.argmax(probs, dim=1).item()
|
| 24 |
confidence = probs[0][predicted_class].item()
|
| 25 |
|
| 26 |
+
label = "π’ Positive" if predicted_class == 1 else "π΄ Negative"
|
| 27 |
+
|
| 28 |
+
return label, f"{confidence:.2f}"
|
| 29 |
+
|
| 30 |
+
# π¨ CUSTOM UI
|
| 31 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 32 |
+
|
| 33 |
+
gr.Markdown("""
|
| 34 |
+
# π¬ AI Sentiment Analyzer
|
| 35 |
+
### Analyze emotions in text using BERT π€
|
| 36 |
+
""")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
text_input = gr.Textbox(
|
| 40 |
+
placeholder="Type your sentence here...",
|
| 41 |
+
lines=3,
|
| 42 |
+
label="Input Text"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
analyze_btn = gr.Button("Analyze Sentiment π")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
result_label = gr.Textbox(label="Prediction")
|
| 49 |
+
confidence_score = gr.Textbox(label="Confidence")
|
| 50 |
+
|
| 51 |
+
analyze_btn.click(
|
| 52 |
+
fn=predict,
|
| 53 |
+
inputs=text_input,
|
| 54 |
+
outputs=[result_label, confidence_score]
|
| 55 |
+
)
|
| 56 |
|
| 57 |
demo.launch()
|