Update README.md
Browse files
README.md
CHANGED
|
@@ -14,6 +14,108 @@ pinned: false
|
|
| 14 |
|
| 15 |
|
| 16 |
---
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
---
|
| 17 |
+
# AI Text Detector — FastAPI App Documentation
|
| 18 |
|
| 19 |
+
## About
|
| 20 |
+
This FastAPI application predicts whether a given text is AI-generated or human-written based on a GPT-2 model.
|
| 21 |
+
It measures the perplexity of the input text to make the decision.
|
| 22 |
|
| 23 |
+
You can access the live version here:
|
| 24 |
+
**[Public App Link](https://can-org-canspace.hf.space)**
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## API Endpoints
|
| 29 |
+
|
| 30 |
+
### `GET /`
|
| 31 |
+
- **Description**: Welcome route showing basic API information.
|
| 32 |
+
- **Response**:
|
| 33 |
+
```json
|
| 34 |
+
{
|
| 35 |
+
"message": "FastAPI API is up.",
|
| 36 |
+
"try": "/docs to test the API.",
|
| 37 |
+
"status": "OK"
|
| 38 |
+
}
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
### `GET /health`
|
| 42 |
+
- **Description**: Health check to verify if the server is running.
|
| 43 |
+
- **Response**:
|
| 44 |
+
```json
|
| 45 |
+
{
|
| 46 |
+
"status": "ok"
|
| 47 |
+
}
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
### `POST /analyze`
|
| 51 |
+
- **Description**: Analyze input text to determine if it is AI-generated or human-written.
|
| 52 |
+
- **Authorization**: Requires Bearer Token.
|
| 53 |
+
- **Request Body**:
|
| 54 |
+
```json
|
| 55 |
+
{
|
| 56 |
+
"text": "Enter your text here"
|
| 57 |
+
}
|
| 58 |
+
```
|
| 59 |
+
- **Response**:
|
| 60 |
+
```json
|
| 61 |
+
{
|
| 62 |
+
"result": "AI-generated" | "Probably AI-generated" | "Human-written",
|
| 63 |
+
"perplexity": 47.35
|
| 64 |
+
}
|
| 65 |
+
```
|
| 66 |
+
- **Important**:
|
| 67 |
+
- Input text must contain at least two words.
|
| 68 |
+
- Without a valid token, this endpoint will not work.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## Authorization Guide
|
| 73 |
+
- Open `/docs` (Swagger UI).
|
| 74 |
+
- Click the "Authorize" button at the top right.
|
| 75 |
+
- Paste your Bearer Token into the Authorization field.
|
| 76 |
+
- After authorization, you can use the `/analyze` endpoint.
|
| 77 |
+
|
| 78 |
+
Example Authorization header:
|
| 79 |
+
```
|
| 80 |
+
Authorization: Bearer YOUR_SECRET_TOKEN
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## How the AI Detection Works
|
| 86 |
+
- The app loads a fine-tuned GPT-2 model at startup.
|
| 87 |
+
- It calculates the perplexity of the input text:
|
| 88 |
+
- Perplexity less than 60 → AI-generated
|
| 89 |
+
- Perplexity between 60 and 80 → Probably AI-generated
|
| 90 |
+
- Perplexity greater than 80 → Human-written
|
| 91 |
+
|
| 92 |
+
Higher perplexity indicates the text is harder for the model to predict, usually meaning it is human-written.
|
| 93 |
+
|
| 94 |
+
---
|
| 95 |
+
|
| 96 |
+
## How to Run Locally
|
| 97 |
+
1. Clone the repository:
|
| 98 |
+
```bash
|
| 99 |
+
git clone https://huggingface.co/spaces/can-org/canspace
|
| 100 |
+
cd canspace
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
2. Install dependencies:
|
| 104 |
+
```bash
|
| 105 |
+
pip install -r requirements.txt
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
3. Start the server:
|
| 109 |
+
```bash
|
| 110 |
+
uvicorn app:app --reload
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
4. Open the API docs at:
|
| 114 |
+
[http://localhost:8000/docs](http://localhost:8000/docs)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
## Quick Reminders
|
| 119 |
+
- Always authorize first in `/docs` before using `/analyze`.
|
| 120 |
+
- Text input must contain more than two words.
|
| 121 |
+
- Public live app is available at: [https://can-org-canspace.hf.space](https://can-org-canspace.hf.space)
|