|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from tensorflow.keras.preprocessing.sequence import pad_sequences |
|
from tensorflow.keras.preprocessing.text import Tokenizer |
|
import pickle |
|
|
|
|
|
model = pickle.load(open('model.pkl','rb')) |
|
|
|
def spam_detection(message): |
|
vocab_size = 1000 |
|
embedding_dim = 16 |
|
max_length = 100 |
|
trunc_type='post' |
|
padding_type='post' |
|
oov_tok = "<OOV>" |
|
|
|
tokenizer = Tokenizer(num_words = vocab_size, oov_token=oov_tok) |
|
sequence = tokenizer.texts_to_sequences([message]) |
|
padded_sequence = pad_sequences(sequence, maxlen=max_length, padding=padding_type, truncating=trunc_type) |
|
|
|
|
|
prediction = model.predict(padded_sequence)[0, 0] |
|
|
|
|
|
return "Spam" if prediction >= 0.4 else "Not Spam" |
|
|
|
|
|
ui = gr.Interface( |
|
fn=spam_detection, |
|
inputs=gr.Textbox(label="Enter a message:",info='Check spam or not spam msg',lines=5), |
|
outputs="text", |
|
|
|
title='π« Spam Message Detection π΅οΈββοΈ', |
|
description=""" |
|
|
|
Welcome to the Spam Message Detection appβa powerful demo designed for learning purposes. π This application employs advanced machine learning techniques to identify and flag spam messages with remarkable accuracy. π€ With a training set accuracy of 99.89% and a validation/test set accuracy of 98.39%, the model has been Trained using a comprehensive dataset. |
|
|
|
**π Key Features:** |
|
- State-of-the-art machine learning model |
|
- High accuracy: 99.89% on the training set, 98.39% on the validation/test set |
|
- Intuitive user interface for easy interaction |
|
- Ideal for educational purposes and exploring spam detection techniques |
|
|
|
**π Instructions:** |
|
1. Enter a text message in the provided input box. |
|
2. Click the "Detect" button to initiate the spam detection process. |
|
3. Receive instant feedback on whether the input message is classified as spam or not. |
|
|
|
**π Note:** |
|
|
|
This app is a demonstration and educational tool. It showcases the effectiveness of machine learning in identifying spam messages. Enjoy exploring the world of spam detection with our highly accurate model! π""" |
|
) |
|
|
|
ui.launch() |
|
|