metadata
title: Canspace
emoji: π¨
colorFrom: red
colorTo: purple
sdk: docker
pinned: false
AI Text Detector β FastAPI App Documentation
About
This FastAPI application predicts whether a given text is AI-generated or human-written based on a GPT-2 model.
It measures the perplexity of the input text to make the decision.
You can access the live version here:
Public App Link
API Endpoints
GET /
- Description: Welcome route showing basic API information.
- Response:
{ "message": "FastAPI API is up.", "try": "/docs to test the API.", "status": "OK" }
GET /health
- Description: Health check to verify if the server is running.
- Response:
{ "status": "ok" }
POST /analyze
- Description: Analyze input text to determine if it is AI-generated or human-written.
- Authorization: Requires Bearer Token.
- Request Body:
{ "text": "Enter your text here" }
- Response:
{ "result": "AI-generated" | "Probably AI-generated" | "Human-written", "perplexity": 47.35 }
- Important:
- Input text must contain at least two words.
- Without a valid token, this endpoint will not work.
Authorization Guide
- Open
/docs
(Swagger UI). - Click the "Authorize" button at the top right.
- Paste your Bearer Token into the Authorization field.
- After authorization, you can use the
/analyze
endpoint.
Example Authorization header:
Authorization: Bearer YOUR_SECRET_TOKEN
How the AI Detection Works
- The app loads a fine-tuned GPT-2 model at startup.
- It calculates the perplexity of the input text:
- Perplexity less than 60 β AI-generated
- Perplexity between 60 and 80 β Probably AI-generated
- Perplexity greater than 80 β Human-written
Higher perplexity indicates the text is harder for the model to predict, usually meaning it is human-written.
How to Run Locally
Clone the repository:
git clone https://huggingface.co/spaces/can-org/canspace cd canspace
Install dependencies:
pip install -r requirements.txt
Start the server:
uvicorn app:app --reload
Open the API docs at:
http://localhost:8000/docs
Quick Reminders
- Always authorize first in
/docs
before using/analyze
. - Text input must contain more than two words.
- Public live app is available at: https://can-org-canspace.hf.space