Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ EXPOSE 8080
ENV MUSIC_GEN_MODE=simulate
ENV PORT=8080

# Run the API server
CMD uvicorn music_generator.api:app --host 0.0.0.0 --port ${PORT}
# Run the API server using entrypoint
CMD ["music-gen-api"]
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ music-gen generate \

```bash
# Start the API server (binds to 0.0.0.0:8080 by default)
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
music-gen-api

# Or set custom port
PORT=3000 uvicorn music_generator.api:app --host 0.0.0.0 --port 3000
PORT=3000 music-gen-api

# Alternative: use uvicorn directly
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
```

Access API documentation at `http://localhost:8080/docs`
Expand Down Expand Up @@ -171,15 +174,18 @@ music-gen delete-preset my_metal

```bash
# Default (simulate mode, no auth)
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
music-gen-api

# With API key authentication
export MUSIC_GEN_API_KEY=your-secret-key
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
music-gen-api

# GCP mode
export MUSIC_GEN_MODE=gcp
export GOOGLE_CLOUD_PROJECT=your-project-id
music-gen-api

# Alternative: use uvicorn directly
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
```

Expand Down Expand Up @@ -421,7 +427,7 @@ GitHub Codespaces works out of the box:
```
4. Or start the API server:
```bash
uvicorn music_generator.api:app --host 0.0.0.0 --port 8080
music-gen-api
```

## Environment Variables
Expand Down
2 changes: 1 addition & 1 deletion run-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ echo ""
echo "Press Ctrl+C to stop"
echo ""

uvicorn music_generator.api:app --host 0.0.0.0 --port $PORT
music-gen-api
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
entry_points={
"console_scripts": [
"music-gen=music_generator.cli:main",
"music-gen-api=music_generator.api:main",
],
},
python_requires=">=3.9",
Expand Down
21 changes: 21 additions & 0 deletions src/music_generator/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi import FastAPI, HTTPException, Header, Depends, Query
from pydantic import BaseModel, Field
import logging
import uvicorn

from .models import TrackConfig, SongStructure, StyleReference, PresetConfig
from .generator import MusicGenerator
Expand Down Expand Up @@ -294,3 +295,23 @@ def health_check():
"status": "healthy",
"mode": os.getenv("MUSIC_GEN_MODE", "simulate")
}


def main():
"""Main entrypoint for running the API server."""
# Read port from environment variable (for Cloud Run compatibility)
port = int(os.getenv("PORT", "8080"))

logger.info(f"Starting Music Track Generator API on port {port}")
logger.info(f"Mode: {os.getenv('MUSIC_GEN_MODE', 'simulate')}")

uvicorn.run(
app,
host="0.0.0.0",
port=port,
log_level="info"
)


if __name__ == "__main__":
main()