File size: 2,046 Bytes
3e7fad6 0f8ae82 2890eda 0f8ae82 3e7fad6 2890eda 0f8ae82 988b057 0f8ae82 988b057 0f8ae82 3e7fad6 4546947 3e7fad6 4546947 53b301c 0f8ae82 988b057 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import gradio as gr
import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
# Load the trained model
model = pickle.load(open('./model_file.pkl','rb')
def spam_detection(message):
# Preprocess the input message
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.5 else "Not Spam"
# Gradio Interface
ui = gr.Interface(
fn=spam_detection,
inputs=gr.Textbox(prompt="Enter a message:"),
outputs="text",
live=True,
theme="huggingface",
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 fine-tuned 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()
|