shrushhtijadhav commited on
Commit
0784a7a
·
verified ·
1 Parent(s): 19d7e2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -1,33 +1,26 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- classifier = pipeline("text-classification", model="bhadresh-savani/bert-base-uncased-emotion")
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
-
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ classifier = pipeline(
5
+ "text-classification",
6
+ model="mariagrandury/roberta-base-finetuned-sms-spam-detection"
7
+ )
 
 
8
 
9
  def predict_spam(text):
10
  result = classifier(text)[0]
11
+ label = "SPAM" if result['label'].lower() == "spam" else "HAM (Not Spam)"
12
  confidence = round(result['score'] * 100, 2)
13
+ return f"Prediction: {label}\nConfidence: {confidence}%"
14
 
 
15
  gr.Interface(
16
  fn=predict_spam,
17
+ inputs=gr.Textbox(lines=4, placeholder="Enter your message..."),
18
  outputs="text",
19
+ title="Spam Detector",
20
+ description="Detects whether a message is SPAM or not using a fine-tuned RoBERTa model.",
21
  examples=[
22
+ "Congratulations! You won a prize.",
23
+ "Hi, are we meeting tomorrow?",
24
+ "Click to claim your free iPhone!"
 
25
  ]
26
  ).launch()