Pravincoder's picture
Update app.py
984bac6 verified
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
# Load the trained model
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>"
# Preprocess the input message
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)
# Make prediction
prediction = model.predict(padded_sequence)[0, 0]
# Return the result
return "Spam" if prediction >= 0.4 else "Not Spam"
# Gradio Interface
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! πŸš€"""
)
# Launch the app
ui.launch()