panchajanya1999 commited on
Commit
4214671
·
verified ·
1 Parent(s): cae3d9a

spam_classifier: Implement flagging function

Browse files

Signed-off-by: Panchajanya1999 <rsk52959@gmail.com>

Files changed (1) hide show
  1. spam_classifier.py +8 -3
spam_classifier.py CHANGED
@@ -1,8 +1,7 @@
1
  # import libraries
2
  import pandas as pd
3
- import numpy as np
4
- import matplotlib.pyplot as plt
5
  import gradio as gr
 
6
 
7
  # import string
8
  import string
@@ -16,6 +15,9 @@ from sklearn.model_selection import train_test_split
16
  # import multinomial naive bayes
17
  from sklearn.naive_bayes import MultinomialNB
18
 
 
 
 
19
  # read data from csv file
20
  df = pd.read_csv('dataset/spam.tsv', sep='\t', names=['label', 'message'])
21
 
@@ -69,12 +71,15 @@ def predict_spam(message):
69
  message = 'This is a spam message'
70
  return message
71
 
 
 
72
  iface = gr.Interface(
73
  fn=predict_spam,
74
  inputs=gr.Textbox(lines=2, placeholder="Enter a message to check if it is spam or ham", label="Message", info = "Enter a message"),
75
  outputs=gr.Textbox(lines=2, info="Check if the enetered message is spam or ham", label="Prediction", placeholder = "Output will be here.."),
76
  title="Spam Classifier",
77
  description="Enter a message to check if it is spam or ham",
78
- allow_flagging='never',
 
79
  examples=[['Hey, how are you doing?'], ['Congratulations! You have won a free trip to Dubai!']])
80
  iface.launch()
 
1
  # import libraries
2
  import pandas as pd
 
 
3
  import gradio as gr
4
+ import os
5
 
6
  # import string
7
  import string
 
15
  # import multinomial naive bayes
16
  from sklearn.naive_bayes import MultinomialNB
17
 
18
+ # read the variable from the environment
19
+ HF_API_TOKEN = os.getenv("HF_API_TOKEN")
20
+
21
  # read data from csv file
22
  df = pd.read_csv('dataset/spam.tsv', sep='\t', names=['label', 'message'])
23
 
 
71
  message = 'This is a spam message'
72
  return message
73
 
74
+ hf_writer = gr.HuggingFaceDatasetSaver(HF_API_TOKEN, "spam-mistakes")
75
+
76
  iface = gr.Interface(
77
  fn=predict_spam,
78
  inputs=gr.Textbox(lines=2, placeholder="Enter a message to check if it is spam or ham", label="Message", info = "Enter a message"),
79
  outputs=gr.Textbox(lines=2, info="Check if the enetered message is spam or ham", label="Prediction", placeholder = "Output will be here.."),
80
  title="Spam Classifier",
81
  description="Enter a message to check if it is spam or ham",
82
+ allow_flagging='manual',
83
+ flagging_callback=hf_writer,
84
  examples=[['Hey, how are you doing?'], ['Congratulations! You have won a free trip to Dubai!']])
85
  iface.launch()