Pravincoder's picture
Update app.py
2890eda verified
raw
history blame
2.05 kB
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()