Spaces:
Runtime error
Runtime error
File size: 3,426 Bytes
fef536a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
---
title: AI Content Classifier Server
emoji: 🐢
colorFrom: pink
colorTo: blue
sdk: gradio
sdk_version: 5.13.1
app_file: app.py
pinned: false
short_description: Classify text as human-written, AI-generated, or paraphrased
---
# AI Content Classifier API
A FastAPI backend service that classifies text as human-written, AI-generated, or paraphrased using a fine-tuned transformer model.
## Features
- **详细文本分类**: 将输入文本分类为三个类别:
- Human-Written (人类写作)
- AI-Generated (AI生成)
- Paraphrased (改写文本)
- **完整概率分布**: 返回所有类别的概率百分比
- **深度文本分析**:
- 文本统计信息(长度、词数、句数)
- AI生成指标识别
- 风险等级评估
- **智能改进建议**: 基于分析结果提供具体的改进建议
- **置信度分析**: 返回预测的置信度评分
- **RESTful API**: 清洁的REST端点和标准HTTP状态码
- **输入验证**: 验证输入文本并优雅处理错误
- **健康检查**: 服务健康状态监控端点
## Installation
1. Install dependencies:
```bash
pip install -r requirements.txt
```
2. Run the FastAPI server:
```bash
python app.py
```
The server will start on `http://localhost:7860`
## API Endpoints
### POST `/detect`
Classify text content.
**Request Body:**
```json
{
"text": "Your text to classify here"
}
```
**Response:**
```json
{
"classification": "Human-Written",
"confidence": 0.9234,
"probabilities": {
"Human-Written": 0.9234,
"AI-Generated": 0.0566,
"Paraphrased": 0.0200
},
"analysis": {
"text_length": 245,
"word_count": 42,
"sentence_count": 3,
"ai_indicators": [],
"human_indicators": ["自然语言特征", "人类写作模式"],
"risk_level": "low"
},
"suggestions": [
"保持当前的自然写作风格",
"继续保持语言的自然流畅性"
]
}
```
### GET `/health`
Health check endpoint.
**Response:**
```json
{
"status": "healthy"
}
```
### GET `/`
Root endpoint with service information.
## Usage Example
```python
import requests
response = requests.post(
"http://localhost:7860/detect",
json={"text": "This is sample text to classify"}
)
result = response.json()
# 基本结果
print(f"分类结果: {result['classification']}")
print(f"置信度: {result['confidence']:.4f}")
# 详细概率分布
print("\n概率分布:")
for category, prob in result['probabilities'].items():
print(f" {category}: {prob*100:.2f}%")
# 文本分析
analysis = result['analysis']
print(f"\n文本分析:")
print(f" 风险等级: {analysis['risk_level']}")
print(f" 词数: {analysis['word_count']}")
# 改进建议
print(f"\n改进建议:")
for i, suggestion in enumerate(result['suggestions'], 1):
print(f" {i}. {suggestion}")
```
## Testing
Run the detailed test script to verify the API is working:
```bash
python test_detailed_api.py
```
This will show you:
- 完整的分类结果和概率分布
- 详细的文本分析
- 个性化的改进建议
- 可视化的概率条形图
## Interactive Documentation
Once the server is running, visit:
- Swagger UI: `http://localhost:7860/docs`
- ReDoc: `http://localhost:7860/redoc`
## Model Information
This service uses the `vai0511/ai-content-classifier` model from Hugging Face, which is fine-tuned for content source identification.
|