Skip to content

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.

License

Notifications You must be signed in to change notification settings

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

No packages published