meetmendapara commited on
Commit
a8fcc07
Β·
1 Parent(s): d901f9e

Remove unused plotting function and clear button from sentiment analysis app

Browse files
Files changed (1) hide show
  1. app.py +1 -22
app.py CHANGED
@@ -4,8 +4,6 @@
4
  from transformers import BertTokenizer, BertForSequenceClassification
5
  import torch
6
  import gradio as gr
7
- import torch.nn.functional as F
8
- import matplotlib.pyplot as plt
9
 
10
  # Load saved model and tokenizer
11
  model = BertForSequenceClassification.from_pretrained("./imdb_bert_model")
@@ -22,20 +20,6 @@ def predict_sentiment(text):
22
  sentiment = "Positive 😊" if prediction == 1 else "Negative 😠"
23
  return f"{sentiment} (Confidence: {confidence * 100:.2f}%)", probs.detach().numpy()[0]
24
 
25
- # Plotting function for probabilities
26
- def plot_probs(probs):
27
- labels = ["Negative", "Positive"]
28
- fig, ax = plt.subplots()
29
- ax.bar(labels, probs, color=["red", "green"])
30
- ax.set_ylim([0, 1])
31
- ax.set_ylabel("Probability")
32
- return fig
33
-
34
- # Clear button handler
35
- def clear_all():
36
- return "", "", None
37
-
38
-
39
  # Responsive UI with gr.Blocks
40
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
41
  gr.Markdown("## 🎬 IMDB Movie Review Sentiment Analyzer")
@@ -51,10 +35,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
51
  autofocus=True
52
  )
53
  submit_btn = gr.Button("πŸ” Analyze")
54
- clear_btn = gr.Button("🧹 Clear")
55
  with gr.Column(scale=1):
56
  result_output = gr.Label(label="Predicted Sentiment")
57
- prob_plot = gr.Plot(label="Confidence Scores")
58
 
59
  gr.Examples(
60
  examples=[
@@ -66,10 +48,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
66
  inputs=[review_input]
67
  )
68
 
69
- submit_btn.click(fn=predict_sentiment, inputs=review_input, outputs=[result_output,gr.Plot(label="Confidence Scores")])
70
- clear_btn.click(fn=clear_all, outputs=[review_input, result_output, prob_plot])
71
-
72
  gr.Markdown("### Made with ❀️ by [Meet Mendapara](https://github.com/Meetmendapara09)")
73
 
74
- # Launch the app
75
  demo.launch(share=True)
 
4
  from transformers import BertTokenizer, BertForSequenceClassification
5
  import torch
6
  import gradio as gr
 
 
7
 
8
  # Load saved model and tokenizer
9
  model = BertForSequenceClassification.from_pretrained("./imdb_bert_model")
 
20
  sentiment = "Positive 😊" if prediction == 1 else "Negative 😠"
21
  return f"{sentiment} (Confidence: {confidence * 100:.2f}%)", probs.detach().numpy()[0]
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Responsive UI with gr.Blocks
24
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
25
  gr.Markdown("## 🎬 IMDB Movie Review Sentiment Analyzer")
 
35
  autofocus=True
36
  )
37
  submit_btn = gr.Button("πŸ” Analyze")
 
38
  with gr.Column(scale=1):
39
  result_output = gr.Label(label="Predicted Sentiment")
 
40
 
41
  gr.Examples(
42
  examples=[
 
48
  inputs=[review_input]
49
  )
50
 
51
+ submit_btn.click(fn=predict_sentiment, inputs=review_input, outputs=result_output)
 
 
52
  gr.Markdown("### Made with ❀️ by [Meet Mendapara](https://github.com/Meetmendapara09)")
53
 
 
54
  demo.launch(share=True)