--- 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.