dev1461 commited on
Commit
388d058
Β·
verified Β·
1 Parent(s): 5022fcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
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 = "Positive 😊" if predicted_class == 1 else "Negative 😑"
27
-
28
- return f"{label} (Confidence: {confidence:.2f})"
29
-
30
- demo = gr.Interface(
31
- fn=predict,
32
- inputs=gr.Textbox(lines=3, placeholder="Enter text..."),
33
- outputs="text",
34
- title="🎬 Sentiment Analyzer",
35
- description="BERT-based sentiment classifier"
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()