shrushhtijadhav commited on
Commit
53cb605
·
verified ·
1 Parent(s): 9d659c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -1,26 +1,33 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- classifier = pipeline("text-classification", model="j-hartmann/sms-spam-detection-model")
 
 
 
 
 
5
 
6
  def predict_spam(text):
7
  result = classifier(text)[0]
8
- label = result['label']
9
  confidence = round(result['score'] * 100, 2)
10
- return f" Result: {label.upper()}\n Confidence: {confidence}%"
11
 
 
12
  gr.Interface(
13
  fn=predict_spam,
14
- inputs=gr.Textbox(lines=4, placeholder="Enter an SMS message..."),
15
  outputs="text",
16
- title=" Spam Detector (Improved)",
17
- description="Enter a message to check if it's spam or not using a stronger BERT model.",
18
  examples=[
19
- "Congratulations! You’ve won a free cruise to the Bahamas. Reply YES to claim.",
20
- "Hey, are you coming to class today?",
21
- "Click here to get your free gift card now!",
22
- "We need to submit the project by tonight."
23
  ]
24
  ).launch()
25
 
26
 
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
5
+
6
+ label_map = {
7
+ "LABEL_0": "HAM (Not Spam)",
8
+ "LABEL_1": "SPAM"
9
+ }
10
 
11
  def predict_spam(text):
12
  result = classifier(text)[0]
13
+ label = label_map.get(result['label'], "Unknown")
14
  confidence = round(result['score'] * 100, 2)
15
+ return f" Prediction: {label}\n Confidence: {confidence}%"
16
 
17
+ # Build Gradio UI
18
  gr.Interface(
19
  fn=predict_spam,
20
+ inputs=gr.Textbox(lines=4, placeholder="Enter a message..."),
21
  outputs="text",
22
+ title=" Spam Detector",
23
+ description="Detects SPAM vs HAM using a pretrained BERT-tiny model.",
24
  examples=[
25
+ "Win a free iPhone now!",
26
+ "Hey, are we still on for dinner tonight?",
27
+ "Your OTP is 456123.",
28
+ "Click here to claim your reward."
29
  ]
30
  ).launch()
31
 
32
 
33
+