lokas commited on
Commit
8fabf6b
·
verified ·
1 Parent(s): 531301c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tensorflow.keras.models import load_model
3
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
4
+ import pickle
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # Download files from model repo
8
+ model_path = hf_hub_download("lokas/spam-emails-classifier", "model.h5")
9
+ tokenizer_path = hf_hub_download("lokas/spam-emails-classifier", "tokenizer.pkl")
10
+
11
+ # Load model and tokenizer
12
+ model = load_model(model_path)
13
+ with open(tokenizer_path, "rb") as f:
14
+ tokenizer = pickle.load(f)
15
+
16
+ SEQUENCE_LENGTH = 50 # Must match training
17
+
18
+ def predict_spam(text):
19
+ seq = tokenizer.texts_to_sequences([text])
20
+ padded = pad_sequences(seq, maxlen=SEQUENCE_LENGTH)
21
+ pred = model.predict(padded)[0][0]
22
+ return "🚫 Spam" if pred > 0.5 else "✅ Not Spam"
23
+
24
+ interface = gr.Interface(
25
+ fn=predict_spam,
26
+ inputs=gr.Textbox(lines=3, placeholder="Paste an email message..."),
27
+ outputs="text",
28
+ title="Spam Email Detector",
29
+ description="A BiLSTM-based spam classifier trained on the Enron dataset with GloVe embeddings."
30
+ )
31
+
32
+ interface.launch()