REST API backend for Gemma Garage, built with FastAPI and deployed on Google Cloud Run.
The backend serves as the orchestration layer between the frontend and various Google Cloud services. It handles dataset management, training job submission, model downloads, and HuggingFace integration.
Frontend --> Backend (FastAPI) --> Cloud Run Jobs (GPU Training)
| |
+--> GCS (Storage) +--> Cloud Logging
+--> Gemini API
+--> HuggingFace Hub
| Route | Purpose |
|---|---|
/dataset/* |
Upload, preview, import, and augment datasets |
/finetune/* |
Submit supervised fine-tuning jobs and fetch logs |
/rl_finetune/* |
Submit reinforcement learning training jobs |
/download/* |
Generate signed URLs for model weight downloads |
/huggingface/* |
OAuth authentication and model upload to HF Hub |
/ingest/* |
Extract and process GitHub repositories |
/model/* |
Model selection |
- Dataset Augmentation: Uses Gemini API to generate synthetic QA pairs from uploaded documents
- Training Orchestration: Submits jobs to Cloud Run with GPU support and tracks progress via Cloud Logging
- HuggingFace Integration: OAuth flow for authenticating users and uploading trained models
- Signed URLs: Secure, time-limited download links for trained model weights
- Framework: FastAPI 0.115
- Server: Uvicorn (ASGI)
- Cloud Services: GCS, Cloud Run, Cloud Logging, Vertex AI
- External APIs: Gemini, HuggingFace Hub
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export GEMINI_API_KEY=your_key
export NEW_DATA_BUCKET=gs://your-bucket
# Run server
uvicorn main:app --reload --port 8080The service is automatically deployed to Cloud Run via GitHub Actions on push to main.
# Manual deployment
gcloud run deploy gemma-garage-backend \
--source . \
--region us-central1pip install -r requirements-test.txt
pytest tests/ -v| Variable | Description |
|---|---|
NEW_DATA_BUCKET |
GCS bucket for datasets |
NEW_MODEL_OUTPUT_BUCKET |
GCS bucket for trained models |
GEMINI_API_KEY |
API key for Gemini |
HUGGINGFACE_CLIENT_ID |
HuggingFace OAuth client ID |
HUGGINGFACE_CLIENT_SECRET |
HuggingFace OAuth client secret |