resolverkatla commited on
Commit
09617b2
·
verified ·
1 Parent(s): c1a9c74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -10,10 +10,24 @@ df = pd.read_parquet(dataset_path)
10
  classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
11
 
12
  def spam_detector(text):
13
- """Detect if a message is spam or not."""
14
  result = classifier(text)
15
- label = result[0]['label'].lower()
16
- return "Spam" if label == "spam" else "Not Spam"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  # Create Gradio UI with enhanced styling
19
  app = gr.Interface(
@@ -22,11 +36,10 @@ app = gr.Interface(
22
  outputs=gr.Textbox(label="Prediction"),
23
  title="AI-Powered Spam Detector",
24
  description="Enter a message to check if it's spam or not, using a fine-tuned BERT model.",
25
- theme="huggingface"
26
  )
27
 
28
  # Run the app
29
  if __name__ == "__main__":
30
  print("Loaded dataset preview:")
31
  print(df.head())
32
- app.launch
 
10
  classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-sms-spam-detection")
11
 
12
  def spam_detector(text):
13
+ """Detect if a message is spam or not, with confidence filtering."""
14
  result = classifier(text)
15
+
16
+ # Debugging: Print the raw output from the classifier
17
+ print("Model Output:", result)
18
+
19
+ # Extract label and confidence score
20
+ label = result[0]['label'].lower().strip()
21
+ confidence = result[0]['score'] # Confidence score (0 to 1)
22
+
23
+ # Confidence threshold (adjustable, 0.5 is standard)
24
+ threshold = 0.7
25
+
26
+ # Return based on confidence
27
+ if label == "spam" and confidence >= threshold:
28
+ return f"Spam (Confidence: {confidence:.2f})"
29
+ else:
30
+ return f"Not Spam (Confidence: {confidence:.2f})"
31
 
32
  # Create Gradio UI with enhanced styling
33
  app = gr.Interface(
 
36
  outputs=gr.Textbox(label="Prediction"),
37
  title="AI-Powered Spam Detector",
38
  description="Enter a message to check if it's spam or not, using a fine-tuned BERT model.",
 
39
  )
40
 
41
  # Run the app
42
  if __name__ == "__main__":
43
  print("Loaded dataset preview:")
44
  print(df.head())
45
+ app.launch