Skip to content

Repository files navigation

isitAI — Enterprise Code & AI Model Detector

isitAI is a multi-language, AST-driven detection engine that analyzes source code repositories to detect whether they were generated by AI models (such as ChatGPT, Gemini, Claude, or Copilot) or written by human developers.

It leverages Abstract Syntax Tree (AST) structural metrics, token distributions, and ensemble XGBoost classifiers to perform repository-level evaluation across single projects or batch directories.


🚀 Key Features

  • Multi-Language Support: AST feature extraction engine built for Python (native AST) and Java (javalang).
  • Distribution-Based Analysis: Aggregates per-file AST metrics using Statistical Distributions (mean, std, p90) to prevent feature dilution.
  • Sub-Repository Detection: Automatically identifies container folders containing up to 50 sub-projects and analyzes each repo independently.
  • Provider Attribution: Multi-class classification to attribute detected AI code to specific LLM providers (Gemini, ChatGPT, Claude, Copilot).
  • Lightweight Deployment: Pre-trained model weights are stored in compact JSON schemas (< 5 MB), requiring zero dataset overhead for inference.

🛠️ Installation

# Clone the repository
git clone https://github.com/Akmal-Esmat/isitAI.git
cd isitAI

# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

🔍 Usage

Scan a Local Directory

python scan.py path/to/your/project

Scan a Remote GitHub Repository Directly

You can scan any public GitHub repository directly by passing its HTTPS URL:

python scan.py https://github.com/spring-projects/spring-petclinic

Scan Container Directories (Multi-Repo Batch Mode)

To scan a parent directory containing up to 50 sub-projects:

python scan.py dataset/python/ai/

Example CLI Output

============================================================
         isitAI - Enterprise Code & Model Detector        
============================================================

Cloning remote repository: [https://github.com/spring-projects/spring-petclinic](https://github.com/spring-projects/spring-petclinic) ...

--- Scan Results ---
Target Directory : /tmp/isitai_scan_8x9a2b
Primary Language : JAVA
Files Analyzed   : 32 Java files (~2,400 LOC)
Overall AI Score : 2.14%

AI Provider Attribution Breakdown:
  • CHATGPT    : 1.02% confidence
  • GEMINI     : 0.65% confidence
  • COPILOT    : 0.47% confidence

------------------------------------------------------------
VERDICT: [ PASS ] Codebase appears predominantly human-written.
------------------------------------------------------------

Scan a Single Project

To scan a specific Python or Java project:

python scan.py path/to/your/project

Scan a Parent Directory (Multi-Repo Batch Mode)

To scan a container folder holding multiple distinct projects:

python scan.py dataset/python/ai/

Example CLI Output

============================================================
         isitAI - Enterprise Code & Model Detector        
============================================================

--- Scan Results ---
Target Directory : dataset/ai/gemini/api_wrapper
Overall AI Score : 97.81%

AI Provider Attribution Breakdown:
  • GEMINI     : 85.13% confidence
  • CHATGPT    : 5.93% confidence
  • COPILOT    : 4.47% confidence

------------------------------------------------------------
VERDICT: [ HIGH RISK ] Codebase closely matches GEMINI signatures.
------------------------------------------------------------

🧠 Retraining & Dataset Collection (Optional)

If you wish to retrain the models with custom data:

  1. Collect Human Codebases:

    python collect_human.py python --count 20
    python collect_human.py java --count 20
  2. Add AI Codebases: Place AI-generated sample projects inside dataset/{language}/ai/{provider_name}/{project_name}/.

  3. Train XGBoost Models:

    python train.py

📂 Project Architecture

isitAI/
├── extractors/
│   ├── python_extractor.py     # Python AST Extractor
│   └── java_extractor.py       # Java AST Extractor
├── models/
│   ├── python_ast_model.json   # Pre-trained Python XGBoost weights
│   ├── java_ast_model.json     # Pre-trained Java XGBoost weights
│   └── ...
├── base_extractor.py           # Extractor Contract Interface
├── registry.py                 # Multi-Language Model & Extractor Registry
├── repo_analyzer.py            # Multi-Repo Feature Aggregator & Inference Engine
├── scan.py                     # CLI Entry Point
├── collect_human.py            # Automated GitHub Repo Collector
├── train.py                    # Multi-Language Model Trainer
└── requirements.txt

🐳 Docker Usage (Docker Hub)

You can run isitAI instantly using the pre-built image from Docker Hub—no Python installation required.

1. Pull the Image

docker pull akmall123/isitai:latest

2. Run Scans

  • Scan a Remote GitHub Repository:
docker run --rm akmall123/isitai:latest <github-repo-url>

(Example: docker run --rm akmall123/isitai:latest https://github.com/spring-projects/spring-petclinic)

  • Scan Current Working Directory:
docker run --rm -v $(pwd):/code akmall123/isitai:latest /code
  • Scan Any Specific Local Directory:
docker run --rm -v /path/to/your/project:/code akmall123/isitai:latest /code

Build & Run Locally (Optional)

docker build -t isitai .
docker run --rm isitai <github-repo-url>

🌐 Adding Support for New Languages

isitAI uses a modular extractor pipeline, making it easy to add support for additional programming languages (e.g., Go, C++, JavaScript, Rust).


Step 1: Create a Language Extractor

Create a new file in the extractors/ directory (for example, extractors/go_extractor.py) that inherits from BaseExtractor:

from base_extractor import BaseExtractor

class GoExtractor(BaseExtractor):
    def extract_features(self, file_path: str) -> dict:
        """
        Parse the source file and return structural/AST metrics.
        Returns a dictionary of numerical feature names to float values.
        """
        with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
            code = f.read()

        # Parse AST or extract structural metrics here
        return {
            "ast_node_count": 0.0,
            "max_nesting_depth": 0.0,
            "avg_identifier_length": 0.0,
            # Return dictionary of numeric features
        }

Step 2: Register the New Language

Update registry.py to map the new file extension and language keyword to your extractor:

from extractors.go_extractor import GoExtractor

EXTRACTOR_REGISTRY = {
    "python": PythonExtractor,
    "java": JavaExtractor,
    "go": GoExtractor,  # Add new extractor here
}

FILE_EXTENSIONS = {
    ".py": "python",
    ".java": "java",
    ".go": "go",        # Map file extensions
}

Step 3: Train the New Language Model

  1. Add search keywords for your new language to LANG_CONFIGS in collect_human.py.
  2. Place corresponding AI-generated code samples in dataset/<language>/ai/<provider>/.
  3. Run the training script to generate the model artifact (<language>_ast_model.json in models/):
python train.py

About

Containerized MLOps service for detecting AI-generated code, currently supporting Java and Python across Claude, Gemini, ChatGPT, and Copilot models.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages