GitHunt
DI

Divyanshusinghrajawat/Intelligent-excuse-generator

AI-powered NLP system for context-aware excuse generation with ML believability scoring

๐ŸŽญ Intelligent Excuse Generator

An AI-powered, NLP-driven Python application that generates context-aware,
realistic and customizable excuses โ€” with believability scoring, proof
suggestions, and multi-format output.


๐Ÿ“Œ Table of Contents


๐Ÿ“– Overview

The Intelligent Excuse Generator is a Python-based AI application
that helps users generate realistic, context-aware excuses for different
life situations โ€” academic, professional, social, and emergency.

Unlike simple text generators, this system uses a hybrid approach:

  • A rule-based NLP engine (spaCy + NLTK) that understands the
    user's situation and extracts meaningful context
  • A template library of 30+ professionally written excuse templates
    mapped to category, relationship and tone
  • A scikit-learn ML classifier that scores how believable the
    generated excuse is on a scale of 1 to 10
  • A clean Jupyter Notebook UI built with ipywidgets โ€” no web
    framework needed, runs fully offline

The entire system works 100% offline โ€” no API keys, no internet
connection required after initial setup.


โœจ Features

1. Context-Aware Excuse Generation

The system does not just pick a random excuse. It analyzes your situation
text using NLP to extract keywords, detect urgency, infer what action was
missed, and selects the most appropriate template from the library.

2. NLP Preprocessing (spaCy + NLTK)

  • Named entity recognition (identifies people, places, dates)
  • Part-of-speech tagging (extracts nouns, verbs, adjectives)
  • Urgency detection (flags words like "emergency", "deadline", "ASAP")
  • VADER sentiment analysis (adjusts excuse tone based on emotional context)

3. Rule-Based Excuse Engine

  • 30+ templates organized by category and relationship type
  • Dynamic placeholder filling ({event}, {action}, {deadline} etc.)
  • Auto-generates realistic deadlines, recovery actions and events
  • Falls back gracefully when context is ambiguous

4. ML Believability Scorer

  • TF-IDF vectorizer + Logistic Regression pipeline
  • Trained on 45 labeled excuse samples (3 classes)
  • Scores excuses: Low (1โ€“4) ยท Medium (5โ€“7) ยท High (8โ€“10)
  • Gives actionable feedback tips to improve weak excuses
  • Model saved as .pkl file โ€” loads instantly on next run

5. Emergency Mode

  • Single red button โ€” no configuration needed
  • Instantly generates a professional emergency excuse
  • Works even if the situation box is empty

6. Multi-Format Output

Same excuse, three different formats:

  • Plain โ€” simple paragraph with greeting and sign-off
  • Formal Letter โ€” full letter with date, subject, recipient, closing
  • WhatsApp โ€” short, casual, emoji-friendly message

7. Proof & Evidence Suggestions

  • Suggests 1โ€“5 realistic supporting documents based on the event type
  • Detects event type automatically (medical, technical, travel, family)
  • Includes a clear ethical disclaimer

8. Quick Fill Templates

  • 16 prebuilt situation templates across all 4 categories
  • Selecting one auto-fills the situation box instantly
  • Can still be edited manually after selection
  • Quick fill options update dynamically when category changes

โš™๏ธ How It Works

User Input (situation text + dropdowns)
            โ”‚
            โ–ผ
    NLP Engine (spaCy)
    โ”œโ”€โ”€ Extract keywords (nouns, verbs, entities)
    โ”œโ”€โ”€ Detect urgency
    โ”œโ”€โ”€ Infer missed action
    โ””โ”€โ”€ Analyze sentiment
            โ”‚
            โ–ผ
    Excuse Engine (Rule-based)
    โ”œโ”€โ”€ Select category + relationship template
    โ”œโ”€โ”€ Pick fitting event + recovery action
    โ”œโ”€โ”€ Fill placeholders with NLP context
    โ””โ”€โ”€ Generate raw excuse text
            โ”‚
            โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ–ผ                                  โ–ผ
    ML Scorer (scikit-learn)          Formatter
    โ”œโ”€โ”€ TF-IDF vectorize              โ”œโ”€โ”€ Plain format
    โ”œโ”€โ”€ Predict believability class   โ”œโ”€โ”€ Formal letter
    โ”œโ”€โ”€ Map to score (1โ€“10)           โ””โ”€โ”€ WhatsApp format
    โ””โ”€โ”€ Generate feedback tip
            โ”‚
            โ–ผ
    Proof Generator
    โ”œโ”€โ”€ Detect event type (medical/technical/travel/family)
    โ””โ”€โ”€ Return relevant evidence suggestions
            โ”‚
            โ–ผ
    Jupyter Notebook UI (ipywidgets)
    โ””โ”€โ”€ Display all outputs in formatted HTML panel

๐Ÿ“ Project Structure

intelligent_excuse_generator/
โ”‚
โ”œโ”€โ”€ ๐Ÿ““ Intelligent_Excuse_Generator.ipynb   โ† Run this file
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt                     โ† All Python dependencies
โ”œโ”€โ”€ ๐Ÿ“„ README.md                            โ† You are here
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ src/                                 โ† Backend Python modules
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ nlp_engine.py        โ† spaCy NLP: keyword extraction,
โ”‚   โ”‚                           urgency detection, sentiment analysis
โ”‚   โ”œโ”€โ”€ excuse_engine.py     โ† Rule-based generation: template
โ”‚   โ”‚                           selection and placeholder filling
โ”‚   โ”œโ”€โ”€ scorer.py            โ† scikit-learn ML pipeline:
โ”‚   โ”‚                           TF-IDF + Logistic Regression
โ”‚   โ”œโ”€โ”€ formatter.py         โ† Output formatting: plain, formal
โ”‚   โ”‚                           letter, WhatsApp
โ”‚   โ””โ”€โ”€ proof_generator.py   โ† Evidence suggestions based on
โ”‚                               event type detection
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ data/                                โ† JSON data files
โ”‚   โ”œโ”€โ”€ templates.json       โ† 30+ excuse templates organized
โ”‚   โ”‚                           by category and relationship
โ”‚   โ””โ”€โ”€ training_data.json   โ† 45 labeled samples for ML
โ”‚                               believability scorer training
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ models/                              โ† Saved ML model
โ”‚   โ””โ”€โ”€ scorer_model.pkl     โ† Trained pipeline (auto-generated
โ”‚                               on first run, reused after)
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ outputs/                             โ† Exported excuse files
โ””โ”€โ”€ ๐Ÿ“ assets/                              โ† Images and styling

๐Ÿ› ๏ธ Tech Stack

Component Technology Purpose
Language Python 3.12 Core programming language
NLP spaCy en_core_web_sm Keyword extraction, POS tagging
Sentiment NLTK VADER Tone and sentiment analysis
ML Classifier scikit-learn Believability scoring pipeline
Vectorizer TF-IDF (sklearn) Text feature extraction for ML
UI Framework ipywidgets Interactive notebook UI
Notebook Jupyter Notebook Delivery format
Data Format JSON Template and training data store
Environment Python venv (.venv) Dependency isolation

โšก Setup & Installation

Prerequisites

  • Ubuntu / any Linux distro (or Windows with WSL)
  • Python 3.10 or above
  • Git (optional)

Step 1 โ€” Get the project

cd ~
# If using git:
git clone <repo-url>
# Or just navigate to the folder if already downloaded:
cd intelligent_excuse_generator

Step 2 โ€” Create virtual environment

python3 -m venv .venv
source .venv/bin/activate

You will see (.venv) at the start of your terminal โ€” this means
the environment is active.

Step 3 โ€” Install all dependencies

pip install -r requirements.txt

This installs spaCy, NLTK, scikit-learn, ipywidgets, and Jupyter.
Takes 2โ€“3 minutes on first run.

Step 4 โ€” Download spaCy language model

python -m spacy download en_core_web_sm

Step 5 โ€” Launch the notebook

jupyter notebook Intelligent_Excuse_Generator.ipynb \
  --NotebookApp.token='' --NotebookApp.password=''

The notebook will open in your browser automatically at
http://localhost:8888


๐ŸŽฎ How to Use

Once the notebook is open in your browser:

Step 1 โ€” Run all cells
Click Kernel โ†’ Restart & Run All to initialize the system.
Wait for the "โœ… System ready!" message in Cell 2.

Step 2 โ€” Select a prebuilt situation (Quick Fill)
Use the Quick Fill dropdown to pick a prebuilt situation.
The situation box auto-fills. You can edit it manually too.

Step 3 โ€” Configure your excuse

Setting Options
Category Academic ยท Professional ยท Social ยท Emergency
Recipient Teacher ยท Boss ยท Parent ยท Friend ยท Colleague ยท Client ยท Partner
Tone Formal ยท Casual
Format Plain ยท Formal Letter ยท WhatsApp
Proof tips 1 to 5 suggestions (slider)

Step 4 โ€” Generate

  • Click โœจ Generate Excuse for a tailored, context-aware excuse
  • Click ๐Ÿšจ Emergency Mode for an instant excuse with no setup

Step 5 โ€” Read your output

The output panel shows:

  • The formatted excuse (plain / letter / WhatsApp)
  • Believability score out of 10 with a color indicator
  • Feedback tip to improve the excuse if needed
  • Proof and evidence suggestions relevant to your situation

๐Ÿ“Š ML Model Details

The believability scorer is a scikit-learn pipeline trained on
synthetic excuse data.

Pipeline:
  TfidfVectorizer(ngram_range=(1,2), max_features=5000)
        โ”‚
        โ–ผ
  LogisticRegression(max_iter=1000, C=1.0, solver='lbfgs')
Detail Value
Algorithm Logistic Regression
Features TF-IDF unigrams and bigrams
Training samples 45 labeled excuse texts
Classes 0 = Low ยท 1 = Medium ยท 2 = High
Test accuracy ~77.8%
Model file models/scorer_model.pkl
First run Trains and saves model automatically
Subsequent runs Loads saved model instantly

Score Bands

Score Label Meaning
8โ€“10 High Specific, verifiable, highly convincing
5โ€“7 Medium Reasonable but could use more concrete details
1โ€“4 Low Vague or unconvincing โ€” needs improvement

๐Ÿ“ Output Formats

Plain

Respected Sir/Ma'am,

Due to an unforeseen medical emergency, I was unable to submit
the assignment on time. I have notified the relevant parties
and request a brief extension until Friday, 21 March 2026.

Thank you for your consideration. I remain fully committed
to my responsibilities.

Divyanshu

Formal Letter

=======================================================
                    FORMAL LETTER
=======================================================
Date    : 20 March 2026
To      : The Class Teacher / Professor
Subject : Explanation for Absence / Delay
-------------------------------------------------------

Respected Sir/Ma'am,

Due to an unforeseen medical emergency ...

Yours sincerely,
Divyanshu
=======================================================

WhatsApp

Sir/Ma'am really sorry to message like this ๐Ÿ™

Due to an unforeseen medical emergency, I was unable
to submit the assignment on time.

Will update you soon ๐Ÿ™

๐Ÿ”ฎ Future Scope

  • Larger training dataset โ€” more samples for higher ML accuracy
  • LLM integration โ€” plug in Anthropic/OpenAI API when online
    for dynamic, truly unique excuse generation
  • Hindi and regional language support โ€” multilingual excuses
  • PDF export โ€” download excuse as a formatted PDF document
  • Streamlit web app โ€” browser-based UI without Jupyter
  • Excuse history โ€” save and revisit previously generated excuses
  • Custom templates โ€” let users add their own excuse templates

๐Ÿ‘จโ€๐Ÿ’ป Author

Divyanshu
B.Tech Computer Science (2nd Year)

Built with Python ยท spaCy ยท NLTK ยท scikit-learn ยท ipywidgets ยท Jupyter