Skip to content

jcandrews2/ai-detect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Text Detection API

An AI/ML API that predicts whether text is human-written or AI-generated. The API offers multiple classification models (Logistic Regression, Random Forest, Neural Networks) paired with different text encoding methods (GloVe word embeddings or TF-IDF vectorization). All of the models are trained on a Kaggle dataset of human and AI-generated essays.

🌐 Live API: http://ec2-3-131-93-133.us-east-2.compute.amazonaws.com/api/v1/

✨ Features

  • Classification Models:

  • Logistic Regression

  • Random Forest

  • Neural Network

  • Text Encoding:

  • GloVe (Global Vectors for Word Representation)

  • TF-IDF (Term Frequency-Inverse Document Frequency)

🛠️ Technology Stack

  • Programming Language:

    • Python
  • Web Framework:

    • FastAPI (REST API)
  • Machine Learning:

    • PyTorch (Neural Networks)
    • scikit-learn (Traditional ML)
  • Data Processing:

    • Pandas (Data manipulation)
  • Deployment:

    • AWS EC2 (Cloud hosting)
  • Testing & Documentation:

    • Postman (API testing)

📋 API Documentation

🔌 Endpoints

1. Classification Endpoint

POST /api/v1/classify

Request Body:

{
"text": "Text to classify",
"encoder": "glove",  // Options: "glove", "tfidf"
"model": "logistic_regression"  // Options: "logistic_regression", "random_forest", "neural_network"
}

Response:

{
"model": "Logistic Regression",
"encoder": "glove",
"prediction": "Human",
"confidence": {
    "human": "85.50%",
    "ai": "14.50%"
  }
}

2. Info Endpoint

GET /api/v1/info

Returns model information and usage examples.

⚡ Getting Started

📋 Prerequisites

  • Python 3.12+
  • Pip package manager

💻 Installation

  1. Clone the repository
git clone https://github.com/yourusername/ai-detect.git
cd ai-detect
  1. Create and activate virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Download and prepare the dataset
  1. Train the models
  • Open src/main.py
  • Uncomment the main() function call at the bottom of the file
  • Run the training script:
python -m src.main
  • This will train all models and save them in src/models/saved/
  1. Start the API server
  • Open src/api/api.py
  • Uncomment the uvicorn line at the bottom of the file
  • Run the server:
python -m src.main

The API will be available at http://localhost:8000

📁 Project Structure

ai-detect/
├── src/
│   ├── api/           # FastAPI application
│   ├── models/        # ML model implementations
│   ├── encoders/      # Text encoding modules
│   └── data/          # Data processing utilities
├── tests/             # Unit tests
└── requirements.txt   # Project dependencies

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Jimmy Andrews

📚 Acknowledgments

About

An API that predicts whether text is human-written or AI-generated.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages