lack of infra, need gpu to compute, usecase is very limited
A FastAPI-based service for AI music generation using Replicate's MusicGen model.
tester@gmail.com pass@123 --user_id = 4 2June -- proj_id = 5
- Docker and Docker Compose
- Replicate API token (get one from replicate.com)
- Python 3.9+ (for local development)
- Clone this repository
- Copy the
.env.exampleto.env(if it doesn't exist already) - Update the
.envfile with your Replicate API token:REPLICATE_API_TOKEN=your_replicate_token_here REPLICATE_MODEL_ID=meta/musicgen:7a76a8258b23fae65c5a22debb8841d1d7e816b75c2f24218cd2bd8573787906 MUSICGEN_MODEL_ID=facebook/musicgen-small
Start all services with a single command:
docker-compose up -dThis will start:
- PostgreSQL database
- Redis for Celery
- FastAPI application
- Celery worker
- Flower (Celery monitoring)
To check if all services are running:
docker-compose psCheck API service logs:
docker-compose logs -f apiCheck Celery worker logs:
docker-compose logs -f celery_workerYou can test if your Replicate API token is working correctly by using the test endpoint:
curl -X POST http://localhost:8000/api/v1/test/test-replicate-connection/Or test the full audio generation:
curl -X POST http://localhost:8000/api/v1/test/test-generate/ -H "Content-Type: application/json" -d "{\"prompt\": \"Upbeat electronic music\", \"duration\": 5}"Invoke-WebRequest -Uri http://localhost:8000/api/v1/test/test-generate/ -Method POST -Headers @{"Content-Type"="application/json"} -Body '{"prompt": "Upbeat electronic music", "duration": 5}'curl -X POST http://localhost:8000/api/v1/test/test-generate/ \
-H "Content-Type: application/json" \
-d '{"prompt": "Upbeat electronic music", "duration": 5}'To verify environment variables in containers:
# Check Replicate API token (masked for security)
docker-compose exec api bash -c 'echo ${REPLICATE_API_TOKEN:0:4}...${REPLICATE_API_TOKEN:(-4)}'
# Check Replicate model ID
docker-compose exec api bash -c 'echo $REPLICATE_MODEL_ID'
# Check MusicGen model ID
docker-compose exec api bash -c 'echo $MUSICGEN_MODEL_ID'Stop all services:
docker-compose downTo stop and remove volumes (will delete database data):
docker-compose down -vFor local development without Docker:
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables:
export REPLICATE_API_TOKEN=your_token_here export RUNNING_LOCALLY=true
-
Run the API:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Run Celery worker (in a separate terminal):
celery -A app.celeryworker.worker worker -l info
Once the API is running, you can access the interactive documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
For more details, see API_DOCUMENTATION.md.