Views
No views yet
app.py) – loads the pretrained MusicGen model once and exposes a /generate endpoint.facebook/musicgen-medium checkpoint (requires ~4 GB VRAM for GPU, works on CPU albeit slower).librosa + matplotlib to create a spectrogram.index.html that sends a POST request to /generate and displays the audio player and spectrogram.1cd music_gen_service
2python -m venv venv
3source venv/bin/activate # on Windows use `venv\Scripts\activate`
4pip install -r requirements.txtuvicorn app:app --host 0.0.0.0 --port 8000http://localhost:8000 (or the host IP if you expose it).http://<host‑ip>:8000 in the browser on your Samsung Galaxy A16.exec (curl) or any HTTP client:1POST /generate
2Content-Type: application/json
3{
4 "prompt": "A calm, relaxing ambient instrumental track",
5 "duration": 30
6}audio_base64 – a WAV audio file you can stream (data:audio/wav;base64,...).spectrogram_base64 – a PNG image of the mel‑spectrogram.1FROM python:3.11-slim
2WORKDIR /app
3COPY requirements.txt .
4RUN pip install --no-cache-dir -r requirements.txt
5COPY . .
6EXPOSE 8000
7CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]1docker build -t music-gen .
2 docker run -p 8000:8000 music-genmodel.to("cpu") to model.to("cuda") in app.py.musicgen-small, musicgen-large) by changing the names in the processor and model loading lines.