Spaces:
Sleeping
Sleeping
File size: 2,547 Bytes
d1f00ad fe2e0f1 |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
---
title: Ham Or Spam
emoji: 🔥
colorFrom: yellow
colorTo: gray
sdk: gradio
sdk_version: 4.14.0
app_file: app.py
pinned: false
license: apache-2.0
---
# Ham or Spam Classifier with TensorFlow and Gradio
## Project Overview
This project presents a machine learning solution for classifying text messages into 'Ham' (non-spam) or 'Spam'. It uses TensorFlow to build a Recurrent Neural Network (RNN) and deploys a Gradio interface for easy interaction with the model.
## Key Technologies
- Python
- TensorFlow
- Gradio
- Pandas
## Installation
To get started, ensure Python is installed on your system and then install the required libraries:
```bash
pip install pandas tensorflow gradio
```
## Data Preprocessing
The dataset, assumed to be named 'spam.csv', is preprocessed as follows:
- Reading the CSV file.
- Converting the class labels to binary format (0 for 'ham', 1 for 'spam').
- Splitting the data into training and testing sets.
## Model Architecture
The TensorFlow model includes:
- TextVectorization Layer: Processes the text data.
- Embedding Layer: Converts text to dense vector embeddings.
- Bidirectional LSTM Layer: Captures the context from both directions of text sequences.
- Dense Layers: For classification output.
## Model Training
- The model is compiled with Binary Crossentropy loss and Adam optimizer.
- It is trained for 15 epochs on the training dataset and validated on the test dataset.
## Model Evaluation
After training, the model is evaluated to determine its accuracy and loss:
```
test_loss, test_acc = model.evaluate(test_dataset)
print('Test Loss:', test_loss)
print('Test Accuracy:', test_acc)
```
## Deployment with Gradio
The trained model is deployed using Gradio, which provides a user-friendly interface for real-time predictions:
```
iface = gr.Interface(
fn=predict_spam,
inputs="text",
outputs="text",
title="Ham or Spam Classifier",
description="A Ham or Spam Classifier created using TensorFlow. Input a message to see if it's classified as Ham or Spam!"
)
iface.launch(share=True)
```
## Running the Project
- Clone the project repository.
- Install the required dependencies.
- Execute the Python scripts for training the model and launching the Gradio interface.
## Conclusion
This project demonstrates the use of TensorFlow and Gradio to build and deploy a practical machine learning solution for text classification. The model effectively distinguishes between 'Ham' and 'Spam' messages, making it a useful tool for email filtering or similar applications.
|