CoolFace
Apppublic

S-Dreamer/CodeCraftLab

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
README.md176 linesDownload Raw Back to root
1---2title: CodeCraftLab3emoji: ๐Ÿ‘4colorFrom: pink5colorTo: purple6sdk: streamlit7sdk_version: 1.57.08app_file: app.py9pinned: false10license: mit11short_description: A fine-tuning platform12datasets:13- angie-chen55/python-github-code14- sdiazlor/python-reasoning-dataset15- MatrixStudio/Codeforces-Python-Submissions16---17 18# CodeCraftLab19A production-grade platform for fine-tuning, evaluating, and serving code generation models. Built on FastAPI + React with a hardened training pipeline, structured logging, and HuggingFace Hub integration.20---21## What It Does22'''23Capability	Detail24Dataset management	Upload, validate, and preprocess Python code datasets via REST API25Fine-tuning	Configure and run training jobs with Pydantic-validated configs26Evaluation	Automated eval hooks โ€” pass@k, BLEU, execution accuracy27Model serving	Authenticated inference endpoints for trained models28HF Hub sync	Push/pull models and datasets to/from HuggingFace Hub29'''30---31## Quick Start32Requirements: Python 3.11+, Docker, CUDA-capable GPU (optional, CPU fallback available)33```bash34git clone https://github.com/your-org/codecraftlab.git35cd codecraftlab36 37# Copy and configure environment38cp .env.example .env39# Edit .env: set HF_TOKEN, SECRET_KEY, DATABASE_URL40 41# Start with Docker Compose42docker compose up --build43 44# API available at http://localhost:800045# Docs at http://localhost:8000/docs46```47### Without Docker:48```bash49pip install uv50uv sync51uv run uvicorn app:app --reload --port 800052```53---54## API Overview55All endpoints require a Bearer token. Get one via `POST /auth/token`.56```bash57# Authenticate58curl -X POST http://localhost:8000/auth/token \59  -H "Content-Type: application/json" \60  -d '{"username": "admin", "password": "your-password"}'61 62# Upload a dataset63curl -X POST http://localhost:8000/datasets/upload \64  -H "Authorization: Bearer <token>" \65  -F "file=@data/train.jsonl"66 67# Launch a training job68curl -X POST http://localhost:8000/training/jobs \69  -H "Authorization: Bearer <token>" \70  -H "Content-Type: application/json" \71  -d @configs/example_job.json72 73# Check job status74curl http://localhost:8000/training/jobs/{job_id} \75  -H "Authorization: Bearer <token>"76```77## Full interactive docs: `http://localhost:8000/docs`78---79## Training Configuration80Jobs are defined as JSON and validated against Pydantic v2 schemas:81```json82{83  "job_name": "codegen-finetune-v1",84  "base_model": "Salesforce/codegen-350M-mono",85  "dataset_id": "ds_abc123",86  "training": {87    "num_epochs": 3,88    "batch_size": 8,89    "learning_rate": 2e-5,90    "warmup_ratio": 0.1,91    "max_seq_length": 1024,92    "gradient_accumulation_steps": 493  },94  "evaluation": {95    "enabled": true,96    "strategy": "epoch",97    "metrics": ["pass_at_1", "pass_at_10", "bleu"]98  },99  "hub": {100    "push_to_hub": true,101    "repo_id": "your-org/codegen-finetune-v1"102  }103}104```105---106## Evaluation Metrics107### Metric	Description108`pass@k`	Fraction of problems solved by at least 1 of k samples109`BLEU`	N-gram overlap against reference completions110`execution_accuracy`	Fraction of generated code that runs without error111`exact_match`	Exact string match against reference outputs112Eval results are logged to structured JSON and optionally pushed to HF Hub model cards.113---114## Architecture115```116codecraftlab/117โ”œโ”€โ”€ app.py                  # FastAPI entrypoint118โ”œโ”€โ”€ routers/119โ”‚   โ”œโ”€โ”€ auth.py             # JWT auth120โ”‚   โ”œโ”€โ”€ datasets.py         # Upload, validate, preprocess121โ”‚   โ”œโ”€โ”€ training.py         # Job management122โ”‚   โ””โ”€โ”€ inference.py        # Model serving123โ”œโ”€โ”€ training/124โ”‚   โ”œโ”€โ”€ config.py           # Pydantic v2 training configs125โ”‚   โ”œโ”€โ”€ pipeline.py         # Fine-tuning pipeline + eval hooks126โ”‚   โ””โ”€โ”€ evaluators.py       # Metric implementations127โ”œโ”€โ”€ models/                 # SQLAlchemy ORM models128โ”œโ”€โ”€ core/129โ”‚   โ”œโ”€โ”€ auth.py             # JWT utils130โ”‚   โ”œโ”€โ”€ logging.py          # structlog setup131โ”‚   โ””โ”€โ”€ settings.py         # Pydantic settings132โ”œโ”€โ”€ Dockerfile133โ”œโ”€โ”€ docker-compose.yml134โ””โ”€โ”€ pyproject.toml135```136---137### HuggingFace Space Config โ€” Audit Notes138The original Space was configured as `sdk: streamlit`. This repo now runs on FastAPI via Docker:139Field	Before	After	Reason140`sdk`	`streamlit`	`docker`	FastAPI served via Uvicorn141`sdk_version`	`1.57.0`	(removed)	Not applicable for Docker SDK142`app_port`	(missing)	`8000`	Required for Docker SDK143`pinned`	`false`	`true`	Production Space, should persist144`short_description`	Generic	Specific	Better discoverability on HF Hub145`tags`	(missing)	Added	Enables HF search indexing146---147## Development148```bash149# Run tests150uv run pytest tests/ -v --cov=. --cov-report=term-missing151 152# Lint153uv run ruff check .154uv run mypy . --strict155 156# Format157uv run ruff format .158```159Test a training run locally (CPU, minimal config):160```bash161uv run python -m training.pipeline \162  --config configs/smoke_test.json \163  --dry-run164```165---166### Environment Variables167Variable	Required	Description168`SECRET_KEY`	Yes	JWT signing secret (min 32 chars)169`HF_TOKEN`	Yes	HuggingFace token with write access170`DATABASE_URL`	Yes	PostgreSQL connection string171`LOG_LEVEL`	No	`DEBUG`/`INFO`/`WARNING` (default: `INFO`)172`MAX_CONCURRENT_JOBS`	No	Max parallel training jobs (default: `2`)173`MODEL_CACHE_DIR`	No	Local model cache path (default: `./cache`)174---175## License176MIT โ€” see LICENSE