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