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.
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.
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:
- Video Transcription: The audio from uploaded videos is transcribed into text using OpenAI's Whisper model.
- Toxicity Analysis: The transcribed text is then analyzed by a custom-trained NLP model to identify toxic content.
- Content Flagging: Videos that are identified as containing toxic content are flagged and separated from the main feed.
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/
To set up and run this project on your local machine, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/censorAI.git cd censorAI -
Create and activate a virtual environment:
python -m venv env source env/bin/activate # On Windows, use `env\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
(Note: A
requirements.txtfile is not yet present. I will add one in a future step.) -
Apply the database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
The application will be available at
http://127.0.0.1:8000/.
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:
toxicsevere_toxicobscenethreatinsultidentity_hate
The dataset is located in the datasets/ directory and is split into train.csv and test.csv.
To train the toxic comment classification model, you can run the ml.py script. This script will:
- Load the training data from
datasets/train.csv. - Preprocess the text data.
- Build and compile a TensorFlow/Keras model.
- Train the model on the preprocessed data.
- 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.)
The AI model is used to filter and flag videos that contain hate speech or offensive content. Here's how it works:
- Video Upload: A user uploads a video through the web interface.
- Processing: The
process.pyscript is triggered, which does the following:- Transcribe Audio: It uses the
inferml.pyscript 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.
- Transcribe Audio: It uses the
- Flagging: If the toxicity score exceeds a certain threshold, the video is flagged as
is_flagged = Truein the database. Flagged videos are not shown in the main feed.
Input: A video file (e.g., my_video.mp4) containing speech.
Processing Steps:
- The audio is transcribed to text: "This is a test video. I hope you like it."
- The text is analyzed for toxicity. For the example above, the model would likely return a low toxicity score.
- If the transcribed text was "You are a stupid idiot, I hate you", the model would return a high toxicity score for
toxicandinsult.
Output:
- If Safe: The video is saved to the database with
is_flagged = Falseand is visible to other users. - If Toxic: The video is saved to the database with
is_flagged = Trueand is hidden from the main feed.
- 🎥 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)