Python Backend for COCO Tool
This is the converted Python backend using Flask and SQLAlchemy.
Setup
- Create a virtual environment (recommended):
python -m venv venv
-
Activate the virtual environment:
- Windows:
venv\Scripts\activate - Linux/Mac:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
Running the Server
Option 1: Using start.py
python start.py
Option 2: Using Flask directly
python app.py
Option 3: Using Flask CLI
flask --app app run --host=0.0.0.0 --port=3000
The server will start on http://0.0.0.0:3000
Database Configuration
The database configuration is in database/database.py. Default settings:
- Host: localhost
- Database: myapp
- User: root
- Password: root
Modify app.py to change these settings.
Project Structure
backend/
├── app.py # Main Flask application
├── start.py # Startup script
├── requirements.txt # Python dependencies
├── database/
│ └── database.py # Database configuration
├── models/ # SQLAlchemy models
│ ├── __init__.py
│ ├── Annotation.py
│ ├── Images.py
│ ├── LabelStudioProject.py
│ ├── training.py
│ ├── TrainingProject.py
│ └── TrainingProjectDetails.py
├── routes/
│ └── api.py # API endpoints
└── services/ # Business logic
├── fetch_labelstudio.py
├── generate_json_yolox.py
├── generate_yolox_exp.py
├── push_yolox_exp.py
└── seed_label_studio.py
API Endpoints
All endpoints are prefixed with /api:
GET /api/seed- Seed database from Label StudioPOST /api/generate-yolox-json- Generate YOLOX training filesPOST /api/start-yolox-training- Start YOLOX trainingGET /api/training-log- Get training logsGET/POST /api/training-projects- Manage training projectsGET /api/label-studio-projects- Get Label Studio projectsGET/POST/PUT /api/training-project-details- Manage project detailsPOST /api/yolox-settings- Save YOLOX settingsGET/DELETE /api/trainings- Manage trainingsDELETE /api/training-projects/:id- Delete training project
Migration Notes
This is a direct conversion from Node.js/Express to Python/Flask:
- Express → Flask
- Sequelize ORM → SQLAlchemy ORM
- node-fetch → requests library
- Async routes maintained where needed
- All file paths and logic preserved from original
Differences from Node.js Version
- Python uses async/await differently - some routes may need adjustments
- File handling uses Python's built-in open() instead of fs module
- Subprocess calls use Python's subprocess module
- JSON handling uses Python's json module
- Path operations use os.path instead of Node's path module