--- 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](https://can-org-canspace.hf.space)** --- ## API Endpoints ### `GET /` - **Description**: Welcome route showing basic API information. - **Response**: ```json { "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**: ```json { "status": "ok" } ``` ### `POST /analyze` - **Description**: Analyze input text to determine if it is AI-generated or human-written. - **Authorization**: Requires Bearer Token. - **Request Body**: ```json { "text": "Enter your text here" } ``` - **Response**: ```json { "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 1. Clone the repository: ```bash git clone https://huggingface.co/spaces/can-org/canspace cd canspace ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` 3. Start the server: ```bash uvicorn app:app --reload ``` 4. Open the API docs at: [http://localhost:8000/docs](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](https://can-org-canspace.hf.space)