AI-Generated Text Detection Using Machine Learning with SHAP Explainability Python Final Year Project with Source Code
Back to ProjectRoughly 15 to 20 minutes if your internet is behaving. Follow it in order and don't skip the virtual environment step, because that's where most of the "it worked on my friend's laptop" problems come from.
pip --version.On Windows, when the Python installer opens, tick the "Add Python to PATH" checkbox at the bottom of the first screen. Miss it and every command below throws "python is not recognized."
Extract the downloaded zip somewhere sensible, then open Command Prompt or Terminal and move into it:
cd path/to/project
Run dir on Windows or ls on macOS and Linux. You should see app.py, requirements.txt and the src folder listed. If you don't, you're one folder too high — go one level deeper.
python -m venv venv
Then activate it. macOS or Linux:
source venv/bin/activate
Windows Command Prompt:
venv\Scripts\activate
Windows PowerShell:
venv\Scripts\Activate.ps1
Your prompt should now start with (venv). That little tag is your confirmation that packages will install into the project instead of messing up your system Python.
PowerShell users sometimes get a script execution error here. Run Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass in the same window and try again.
pip install --upgrade pip
pip install -r requirements.txt
This pulls in Flask, NumPy, Pandas, scikit-learn, spaCy, textdescriptives, TensorFlow, matplotlib, seaborn, SHAP and joblib. It takes a few minutes and prints a wall of text. That's normal. Go make chai.
python -m spacy download en_core_web_sm
About 12 MB. The project needs it for tokenisation, POS tagging and dependency parsing, and the app will crash without it. Do not skip this one.
Copy the CSV into the data folder so the path looks like this:
project/data/ai_vs_human_text_2026.csv
The file needs these columns: text_id, label, source_model, domain, text_content, topic_hint, word_count, avg_sentence_length, generation_method. The label column holds either human or ai.
Two ways to do this. If your guide wants to watch the process, use the notebook:
jupyter notebook train_notebook.ipynb
Run the cells top to bottom. You get inline plots and a comparison table at the end, which looks good during a review.
If you just want it done, use the command line:
python -m src.train
Either way it loads the dataset, builds a balanced sample, extracts 32 features per text, trains all three models, prints the metrics table, and writes everything to models/ and outputs/. Expect 5 to 15 minutes for around 1,332 texts. Feature extraction is the slow part and it'll look frozen for a while. It isn't.
python app.py
Open your browser to http://127.0.0.1:5001. The landing page loads with the hero section and stats bar. Click Analyse Text Now, or just go straight to /analyse.
outputs/ folder. If confusion_matrices.png, roc_curves.png, calibration_diagram.png and the three SHAP plots are all sitting there, training completed properly and your report screenshots are ready.(venv) in the prompt, then run pip install textdescriptives.python -m spacy download en_core_web_sm with the venv active.project/data/.app.py to 5002 or 8000 and rerun.pip install --upgrade shap and make sure you're on 0.45 or newer.Still stuck after all that? Message the CodeAj team with a screenshot of the full error and we'll sort it out.
Our team is here to assist you with installation and setup.