Skip to content

About

AI-powered content moderation platform that transcribes uploaded videos with Whisper and uses NLP-based toxicity classification to detect and flag hate speech and offensive content.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🚨 Hate Speech & Offensive Content Detection in Social Media

A social media prototype that detects and flags hate speech or offensive content in uploaded videos using AI + NLP. The system ensures a safe user experience by moderating user-generated content in real time.


📌 Problem Statement

With the rise of social media, hate speech and offensive content have become a major concern. This project addresses the problem by automatically analyzing uploaded videos, detecting harmful speech, and ensuring flagged content is securely handled.


📂 Project Overview

This project is a web application that allows users to upload and watch short videos, similar to TikTok or Instagram Reels. The core of the project is an AI-powered content moderation system that automatically detects and flags videos containing hate speech or offensive language.

The system uses a multi-stage process:

  1. Video Transcription: The audio from uploaded videos is transcribed into text using OpenAI's Whisper model.
  2. Toxicity Analysis: The transcribed text is then analyzed by a custom-trained NLP model to identify toxic content.
  3. Content Flagging: Videos that are identified as containing toxic content are flagged and separated from the main feed.

🛠️ Project Architecture

The project is built with a Django backend and a simple HTML/CSS/JavaScript frontend. The main components are:

  • Django Backend:
    • censorAI: The main Django project directory.
    • store: A Django app that handles user authentication, video uploads, and other core functionalities.
    • media: Directory where uploaded videos are stored.
    • db.sqlite3: The SQLite database for the project.
  • AI/ML:
    • ml.py: A script for training the toxic comment classification model.
    • inferml.py: A script that uses the trained model to perform inference on transcribed text.
    • process.py: A script that orchestrates the video processing pipeline (transcription and inference).
    • models/: Directory where the trained model and tokenizer are saved.
    • datasets/: Directory containing the training and testing data.
  • Frontend:
    • templates/: Directory containing the HTML templates for the web pages.
    • static/: Directory containing the CSS and JavaScript files.

Due to large file size the datasets and Saved AI model, copy it directly from the drive link given below. the folders must be directly in the main folder.

https://drive.google.com/file/d/1WoGpNhltqSwVn0U_hI4UkULTnXivO0n3/view?usp=sharing

directly extract it, in the main folder

dir/datasets/ dir/saved_models/

⚙️ Installation

To set up and run this project on your local machine, follow these steps:

  1. Clone the repository:

    git clone https://github.com/your-username/censorAI.git
    cd censorAI
  2. Create and activate a virtual environment:

    python -m venv env
    source env/bin/activate  # On Windows, use `env\Scripts\activate`
  3. Install the required dependencies:

    pip install -r requirements.txt

    (Note: A requirements.txt file is not yet present. I will add one in a future step.)

  4. Apply the database migrations:

    python manage.py migrate
  5. Run the development server:

    python manage.py runserver

    The application will be available at http://127.0.0.1:8000/.


📊 Dataset

The AI model is trained on the "Toxic Comment Classification Challenge" dataset from Kaggle. This dataset contains a large number of Wikipedia comments which have been labeled by human raters for toxic behavior. The types of toxicity are:

  • toxic
  • severe_toxic
  • obscene
  • threat
  • insult
  • identity_hate

The dataset is located in the datasets/ directory and is split into train.csv and test.csv.


🧠 Training the Model

To train the toxic comment classification model, you can run the ml.py script. This script will:

  1. Load the training data from datasets/train.csv.
  2. Preprocess the text data.
  3. Build and compile a TensorFlow/Keras model.
  4. Train the model on the preprocessed data.
  5. Save the trained model and tokenizer to the models/ directory.

To run the training script:

python ml.py

(Note: The ml.py script might need to be adjusted to match the final project structure.)


🤖 Using the AI

The AI model is used to filter and flag videos that contain hate speech or offensive content. Here's how it works:

  1. Video Upload: A user uploads a video through the web interface.
  2. Processing: The process.py script is triggered, which does the following:
    • Transcribe Audio: It uses the inferml.py script to transcribe the audio from the video into text using the Whisper model.
    • Analyze Text: The transcribed text is then fed into the trained toxic comment classification model to get a toxicity score.
  3. Flagging: If the toxicity score exceeds a certain threshold, the video is flagged as is_flagged = True in the database. Flagged videos are not shown in the main feed.

📝 Examples

Input: A video file (e.g., my_video.mp4) containing speech.

Processing Steps:

  1. The audio is transcribed to text: "This is a test video. I hope you like it."
  2. The text is analyzed for toxicity. For the example above, the model would likely return a low toxicity score.
  3. If the transcribed text was "You are a stupid idiot, I hate you", the model would return a high toxicity score for toxic and insult.

Output:

  • If Safe: The video is saved to the database with is_flagged = False and is visible to other users.
  • If Toxic: The video is saved to the database with is_flagged = True and is hidden from the main feed.

🚀 Features

  • 🎥 Video upload & reel-based browsing
  • 🔑 Secure login with OTP validation
  • 🤖 Whisper + NLP pipeline for transcript analysis
  • 🚫 Automatic hate speech & offensive content detection with dynamic thresholding.
  • 👍 Like/Dislike functionality for videos.
  • 💬 Commenting functionality for videos.
  • 🔒 Secure section for flagged videos (Not Implemented Yet)

About

AI-powered content moderation platform that transcribes uploaded videos with Whisper and uses NLP-based toxicity classification to detect and flag hate speech and offensive content.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages