Skip to content

Vaishnavi-vi/Comment-Toxicity-Detection

Repository files navigation

🚨 Toxic Comment Detection (Binary Classification)

This project is an end-to-end Toxic vs Non-Toxic Comment Classification System built using:

  • Deep Learning (CNN / LSTM model)
  • FastAPI for backend inference
  • Streamlit for frontend UI
  • Docker for containerized deployment

The system classifies any user comment into:

  • πŸŸ₯ Toxic
  • 🟩 Non-Toxic

πŸ“Œ Project Architecture

User β†’ Streamlit UI β†’ FastAPI API β†’ Toxicity Model β†’ Prediction

Components:

  • frontend/ – Streamlit user interface
  • fastapp/ – FastAPI backend with model inference
  • model/ – tokenizer + saved deep learning model
  • docker-compose.yml – runs both apps together

πŸš€ Features

βœ” Binary Toxic Comment Classification

Predicts:

  • 0 β†’ Non-Toxic
  • 1 β†’ Toxic

βœ” FastAPI Backend

  • /predict endpoint
  • Returns prediction + confidence
  • Handles tokenization, padding, inference

βœ” Streamlit Frontend

  • Clean textbox for entering comments
  • Color-coded output
  • Real-time classification

βœ” Dockerized Microservices

  • Run using docker-compose up
  • Streamlit + FastAPI communicate internally

πŸ”§ How to Run the Project

1️⃣ Clone Repository

git clone <repo-url>
cd Toxic-Comment-Classifier

2️⃣ Run With Docker (Recommended)

docker-compose up --build

Access:


3️⃣ Run Without Docker (Local Mode)

Start FastAPI:

uvicorn fastapp.main:app --reload 

Start Streamlit:

cd frontend
streamlit run frontend/frontend.py

🧠 Model Details

This project uses a binary deep learning classifier.

Pipeline:

  • Text cleaning
  • Tokenization
  • Sequence padding
  • Embedding layer
  • CNN
  • Dense layer with sigmoid output

Output:

  • 0 β†’ Non-Toxic
  • 1 β†’ Toxic

πŸ“‘ API Example

Request:

{
  "text": "You are so stupid!"
}

Response:

{
  "prediction": "Toxic",
  "confidence": 0.91
}

🎨 Streamlit UI

  • Simple text input
  • Classification result with confidence score
  • User-friendly layout

πŸ“¦ Tech Stack

Backend:

  • FastAPI
  • Uvicorn
  • TensorFlow / Keras
  • Pickle

Frontend:

  • Streamlit
  • Requests

DevOps:

  • Docker
  • Docker Compose

πŸ›  Future Enhancements

  • Add multi-label toxicity detection
  • Add explanation (LIME / SHAP)

About

Toxic Comment Detection is a binary text classification project that identifies whether a given comment is toxic or non-toxic. It uses a deep learning model CNN for prediction, FastAPI backend for real-time inference, and Streamlit frontend for user interaction. The system is containerized with Docker, making it easy to run and demo.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors