shrushhtijadhav commited on
Commit
9d659c3
·
verified ·
1 Parent(s): 35e1003

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -1,35 +1,26 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Load spam detection model
5
- classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
6
 
7
- # Map model labels to readable output
8
- label_map = {
9
- "LABEL_0": "HAM (Not Spam)",
10
- "LABEL_1": "SPAM"
11
- }
12
-
13
- # Define prediction function
14
  def predict_spam(text):
15
  result = classifier(text)[0]
16
- raw_label = result['label']
17
- label = label_map.get(raw_label, raw_label) # default to raw_label if not in map
18
  confidence = round(result['score'] * 100, 2)
19
- return f" Result: {label}\n Confidence: {confidence}%"
20
 
21
- # Gradio interface
22
  gr.Interface(
23
  fn=predict_spam,
24
- inputs=gr.Textbox(lines=4, placeholder="Enter a message..."),
25
  outputs="text",
26
- title=" Spam Detector",
27
- description="Enter a message to check if it's spam or not using a pretrained BERT model.",
28
  examples=[
29
- "Win a free iPhone now!",
30
- "Hey, are we still on for dinner tonight?",
31
- "Get your free prize by clicking here",
32
- "Let's submit the assignment before 11pm"
33
  ]
34
  ).launch()
35
 
 
 
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
+