meetmendapara commited on
Commit
c314e1b
·
1 Parent(s): 281f29a

Refactor sentiment prediction function for improved clarity and performance

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  from transformers import BertTokenizer, BertForSequenceClassification
2
  import torch
3
  import gradio as gr
@@ -19,7 +22,7 @@ def predict_sentiment(text):
19
  sentiment = "Positive 😊" if prediction == 1 else "Negative 😠"
20
  return f"{sentiment} (Confidence: {confidence * 100:.2f}%)", probs.detach().numpy()[0]
21
 
22
- # Plotting function
23
  def plot_probs(probs):
24
  labels = ["Negative", "Positive"]
25
  fig, ax = plt.subplots()
@@ -67,5 +70,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
67
  clear_btn.click(fn=clear_all, outputs=[review_input, result_output, prob_plot])
68
 
69
  gr.Markdown("### Made with ❤️ by [Meet Mendapara](https://github.com/Meetmendapara09)")
70
- # Launch
71
- demo.launch(share=True)
 
 
1
+ # This script creates a Gradio web app for sentiment analysis of movie reviews using a pre-trained BERT model.
2
+
3
+ # Import necessary libraries
4
  from transformers import BertTokenizer, BertForSequenceClassification
5
  import torch
6
  import gradio as gr
 
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()
 
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)