legal-doc-masker/backend
tigerenwork 51a50a3fb6 feat: 用llm生成脱敏地址 2025-08-20 10:43:53 +08:00
..
app feat: 用llm生成脱敏地址 2025-08-20 10:43:53 +08:00
docs feat: 用llm生成脱敏地址 2025-08-20 10:43:53 +08:00
tests feat: 更新替换算法,解决匹配token中有空格的问题 2025-08-19 16:08:49 +08:00
.env feat: 使用NER模型进行识别 2025-08-19 01:36:08 +08:00
Dockerfile feat: 使用NER模型进行识别 2025-08-19 01:36:08 +08:00
README.md Initial commit 2025-07-20 21:54:24 +08:00
conftest.py feat: 配置测试test runner 2025-08-17 14:11:29 +08:00
docker-compose.yml refine: 调整docker 2025-08-17 20:16:07 +08:00
package-lock.json Initial commit 2025-07-20 21:54:24 +08:00
pytest.ini feat: 配置测试test runner 2025-08-17 14:11:29 +08:00
requirements.txt feat: 使用NER模型进行识别 2025-08-19 01:36:08 +08:00
validate_refactoring.py refine:重构文档 2025-08-17 20:02:37 +08:00

README.md

Legal Document Masker API

This is the backend API for the Legal Document Masking system. It provides endpoints for file upload, processing status tracking, and file download.

Prerequisites

  • Python 3.8+
  • Redis (for Celery)

File Storage

Files are stored in the following structure:

backend/
├── storage/
│   ├── uploads/     # Original uploaded files
│   └── processed/   # Masked/processed files

Setup

Option 1: Local Development

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables: Create a .env file in the backend directory with the following variables:
SECRET_KEY=your-secret-key-here

The database (SQLite) will be automatically created when you first run the application.

  1. Start Redis (required for Celery):
redis-server
  1. Start Celery worker:
celery -A app.services.file_service worker --loglevel=info
  1. Start the FastAPI server:
uvicorn app.main:app --reload

Option 2: Docker Deployment

  1. Build and start the services:
docker-compose up --build

This will start:

  • FastAPI server on port 8000
  • Celery worker for background processing
  • Redis for task queue

API Documentation

Once the server is running, you can access:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

API Endpoints

  • POST /api/v1/files/upload - Upload a new file
  • GET /api/v1/files - List all files
  • GET /api/v1/files/{file_id} - Get file details
  • GET /api/v1/files/{file_id}/download - Download processed file
  • WS /api/v1/files/ws/status/{file_id} - WebSocket for real-time status updates

Development

Running Tests

pytest

Code Style

The project uses Black for code formatting:

black .

Docker Commands

  • Start services: docker-compose up
  • Start in background: docker-compose up -d
  • Stop services: docker-compose down
  • View logs: docker-compose logs -f
  • Rebuild: docker-compose up --build