Spaces:
Paused
Paused
feat: move Tune Studio to Gradio on ZeroGPU
Browse files- .dockerignore +0 -9
- Dockerfile +0 -31
- README.md +14 -14
- app.py +138 -0
- server/lyrics.py → lyrics.py +0 -0
- packages.txt +1 -0
- pytest.ini +3 -0
- requirements-dev.txt +0 -3
- requirements.txt +2 -2
- server/__init__.py +0 -0
- server/audio.py +0 -55
- server/config.py +0 -16
- server/engines/__init__.py +0 -10
- server/engines/base.py +0 -17
- server/engines/yue2.py +0 -53
- server/jobs.py +0 -121
- server/main.py +0 -113
- song_engine.py +45 -0
- tests/test_api.py +0 -208
- tests/test_lyrics.py +2 -2
- web/app.js +0 -505
- web/index.html +0 -136
- web/styles.css +0 -316
.dockerignore
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
.git
|
| 2 |
-
.env
|
| 3 |
-
.venv
|
| 4 |
-
__pycache__
|
| 5 |
-
*.pyc
|
| 6 |
-
tests
|
| 7 |
-
plans
|
| 8 |
-
docs
|
| 9 |
-
.pytest_cache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dockerfile
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
# CUDA runtime with Ubuntu 22.04 (Python 3.10, which YuE2 expects). Docker SDK lets us run
|
| 2 |
-
# our own server and UI instead of the Gradio runtime.
|
| 3 |
-
FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu22.04
|
| 4 |
-
|
| 5 |
-
ENV DEBIAN_FRONTEND=noninteractive \
|
| 6 |
-
PYTHONUNBUFFERED=1 \
|
| 7 |
-
PIP_NO_CACHE_DIR=1
|
| 8 |
-
|
| 9 |
-
RUN apt-get update \
|
| 10 |
-
&& apt-get install -y --no-install-recommends python3 python3-venv python3-pip ffmpeg \
|
| 11 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
-
|
| 13 |
-
RUN useradd -m -u 1000 user
|
| 14 |
-
USER user
|
| 15 |
-
ENV HOME=/home/user \
|
| 16 |
-
VIRTUAL_ENV=/home/user/venv \
|
| 17 |
-
PATH=/home/user/venv/bin:$PATH \
|
| 18 |
-
HF_HOME=/home/user/.cache/huggingface \
|
| 19 |
-
OUTPUT_DIR=/home/user/outputs
|
| 20 |
-
|
| 21 |
-
WORKDIR /home/user/app
|
| 22 |
-
|
| 23 |
-
RUN python3 -m venv $VIRTUAL_ENV
|
| 24 |
-
COPY --chown=user requirements.txt .
|
| 25 |
-
RUN pip install --upgrade pip && pip install -r requirements.txt
|
| 26 |
-
|
| 27 |
-
COPY --chown=user server ./server
|
| 28 |
-
COPY --chown=user web ./web
|
| 29 |
-
|
| 30 |
-
EXPOSE 7860
|
| 31 |
-
CMD ["uvicorn", "server.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -3,10 +3,11 @@ title: Tune Studio
|
|
| 3 |
emoji: 🎵
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
python_version: "3.10"
|
|
|
|
| 10 |
models:
|
| 11 |
- m-a-p/YuE2-3B
|
| 12 |
license: cc-by-nc-4.0
|
|
@@ -15,7 +16,7 @@ short_description: Type a topic, get a sung song made with YuE2-3B.
|
|
| 15 |
|
| 16 |
# Tune Studio
|
| 17 |
|
| 18 |
-
Type a topic and pick a style. The app writes English lyrics with DeepSeek V4.1 Flash (via Hugging Face Inference Providers), then sings and produces the song with [YuE2-3B](https://huggingface.co/m-a-p/YuE2-3B).
|
| 19 |
|
| 20 |
## Using the app
|
| 21 |
|
|
@@ -24,12 +25,12 @@ Type a topic and pick a style. The app writes English lyrics with DeepSeek V4.1
|
|
| 24 |
|
| 25 |
## Run locally
|
| 26 |
|
| 27 |
-
Needs Linux
|
| 28 |
|
| 29 |
```bash
|
| 30 |
python -m venv .venv && source .venv/bin/activate
|
| 31 |
-
pip install -r requirements.txt
|
| 32 |
-
|
| 33 |
```
|
| 34 |
|
| 35 |
Open http://localhost:7860. The first start downloads the model weights.
|
|
@@ -37,18 +38,17 @@ Open http://localhost:7860. The first start downloads the model weights.
|
|
| 37 |
## Tests
|
| 38 |
|
| 39 |
```bash
|
| 40 |
-
pip install -r requirements
|
| 41 |
pytest
|
| 42 |
```
|
| 43 |
|
| 44 |
-
The
|
| 45 |
|
| 46 |
## Layout
|
| 47 |
|
| 48 |
-
- `
|
| 49 |
-
- `
|
| 50 |
-
|
| 51 |
-
To add a music model, implement the `Engine` protocol in `server/engines/base.py` and register it in `server/engines/__init__.py`.
|
| 52 |
|
| 53 |
## License
|
| 54 |
|
|
|
|
| 3 |
emoji: 🎵
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.24.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
python_version: "3.10.13"
|
| 10 |
+
suggested_hardware: zero-a10g
|
| 11 |
models:
|
| 12 |
- m-a-p/YuE2-3B
|
| 13 |
license: cc-by-nc-4.0
|
|
|
|
| 16 |
|
| 17 |
# Tune Studio
|
| 18 |
|
| 19 |
+
Type a topic and pick a style. The app writes English lyrics with DeepSeek V4.1 Flash (via Hugging Face Inference Providers), then sings and produces the song with [YuE2-3B](https://huggingface.co/m-a-p/YuE2-3B) on ZeroGPU.
|
| 20 |
|
| 21 |
## Using the app
|
| 22 |
|
|
|
|
| 25 |
|
| 26 |
## Run locally
|
| 27 |
|
| 28 |
+
Needs Linux, Python 3.10+, ffmpeg, and an NVIDIA GPU with about 24 GB VRAM (ZeroGPU is only available on Hugging Face).
|
| 29 |
|
| 30 |
```bash
|
| 31 |
python -m venv .venv && source .venv/bin/activate
|
| 32 |
+
pip install -r requirements.txt gradio==6.24.0
|
| 33 |
+
python app.py
|
| 34 |
```
|
| 35 |
|
| 36 |
Open http://localhost:7860. The first start downloads the model weights.
|
|
|
|
| 38 |
## Tests
|
| 39 |
|
| 40 |
```bash
|
| 41 |
+
pip install -r requirements.txt pytest httpx
|
| 42 |
pytest
|
| 43 |
```
|
| 44 |
|
| 45 |
+
The lyrics tests run without a GPU or network.
|
| 46 |
|
| 47 |
## Layout
|
| 48 |
|
| 49 |
+
- `app.py`: Gradio UI and job flow.
|
| 50 |
+
- `song_engine.py`: YuE2 pipeline, rendered inside a `@spaces.GPU` call.
|
| 51 |
+
- `lyrics.py`: lyrics client for Hugging Face Inference Providers.
|
|
|
|
| 52 |
|
| 53 |
## License
|
| 54 |
|
app.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from lyrics import HfLyricsWriter, LyricsError
|
| 6 |
+
from song_engine import render_song
|
| 7 |
+
|
| 8 |
+
STYLE_PRESETS = {
|
| 9 |
+
"Pop": "Pop, catchy hook, bright synth, tight drums, female lead vocal",
|
| 10 |
+
"Ballad": "Ballad, emotional, piano, warm strings, male lead vocal",
|
| 11 |
+
"Lo-fi": "Lo-fi hip hop, mellow, warm keys, vinyl crackle, soft female vocal",
|
| 12 |
+
"Rock": "Rock, energetic, electric guitar, live drums, bass, male lead vocal",
|
| 13 |
+
"EDM": "Electronic dance, uplifting, supersaw lead, four-on-the-floor drums, female lead vocal",
|
| 14 |
+
"R&B": "R&B, smooth, soulful, electric piano, groove bass, female lead vocal",
|
| 15 |
+
"Acoustic": "Folk, acoustic guitar, gentle, intimate, male lead vocal",
|
| 16 |
+
"Cinematic": "Cinematic pop, orchestral, epic build, choir, female lead vocal",
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
CSS = """
|
| 20 |
+
#page { max-width: 760px; margin: 0 auto; }
|
| 21 |
+
.hero { text-align: center; padding-top: 16px; }
|
| 22 |
+
.hero h1 { font-size: 2rem; margin-bottom: 4px; }
|
| 23 |
+
.hero p { opacity: 0.75; margin-top: 0; }
|
| 24 |
+
#create-btn { font-size: 1.05rem; }
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
HERO_HTML = """
|
| 28 |
+
<div class="hero">
|
| 29 |
+
<h1>Turn a topic into a song</h1>
|
| 30 |
+
<p>Describe what your song is about. We write English lyrics and sing them for you.</p>
|
| 31 |
+
</div>
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
writer = HfLyricsWriter()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def verify_token(token: str):
|
| 38 |
+
token = (token or "").strip()
|
| 39 |
+
if not token:
|
| 40 |
+
return "Paste your Hugging Face token first.", gr.skip()
|
| 41 |
+
try:
|
| 42 |
+
username = writer.verify(token)
|
| 43 |
+
except LyricsError as exc:
|
| 44 |
+
return str(exc), gr.skip()
|
| 45 |
+
return f"Connected as **{username}**. Saved in this browser.", token
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def remove_token():
|
| 49 |
+
return "", "", "Token removed from this browser."
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def create_song(topic: str, style_label: str, custom_style: str, token: str):
|
| 53 |
+
topic = (topic or "").strip()
|
| 54 |
+
token = (token or "").strip()
|
| 55 |
+
if len(topic) < 3:
|
| 56 |
+
raise gr.Error("Describe your song in at least 3 characters.")
|
| 57 |
+
if not token:
|
| 58 |
+
raise gr.Error("Add your Hugging Face token in Settings first.")
|
| 59 |
+
|
| 60 |
+
style = (custom_style or "").strip() or STYLE_PRESETS[style_label]
|
| 61 |
+
|
| 62 |
+
yield "Writing lyrics…", "", None
|
| 63 |
+
try:
|
| 64 |
+
lyrics = writer.write(topic, token)
|
| 65 |
+
except LyricsError as exc:
|
| 66 |
+
yield f"Could not write lyrics: {exc}", "", None
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
yield "Singing and producing. This usually takes a few minutes…", lyrics, None
|
| 70 |
+
audio_path = render_song(style, lyrics, random.randint(0, 2**31 - 1))
|
| 71 |
+
yield "Done. Press play or download below.", lyrics, audio_path
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
with gr.Blocks(title="Tune Studio") as demo:
|
| 75 |
+
token_state = gr.BrowserState("")
|
| 76 |
+
|
| 77 |
+
with gr.Column(elem_id="page"):
|
| 78 |
+
gr.HTML(HERO_HTML)
|
| 79 |
+
|
| 80 |
+
with gr.Accordion("Settings: Hugging Face token", open=False):
|
| 81 |
+
token_input = gr.Textbox(
|
| 82 |
+
label="Hugging Face token",
|
| 83 |
+
type="password",
|
| 84 |
+
placeholder="hf_…",
|
| 85 |
+
info="Needs the 'Make calls to Inference Providers' permission. Stored only in this browser.",
|
| 86 |
+
)
|
| 87 |
+
with gr.Row():
|
| 88 |
+
verify_button = gr.Button("Save and verify", variant="secondary")
|
| 89 |
+
remove_button = gr.Button("Remove token", variant="stop")
|
| 90 |
+
settings_status = gr.Markdown()
|
| 91 |
+
|
| 92 |
+
topic_input = gr.Textbox(
|
| 93 |
+
label="Topic",
|
| 94 |
+
placeholder="e.g. a rainy night in the city, missing someone who left",
|
| 95 |
+
lines=3,
|
| 96 |
+
max_lines=5,
|
| 97 |
+
)
|
| 98 |
+
style_input = gr.Radio(
|
| 99 |
+
choices=list(STYLE_PRESETS),
|
| 100 |
+
value="Pop",
|
| 101 |
+
label="Style",
|
| 102 |
+
)
|
| 103 |
+
with gr.Accordion("Describe your own style (optional)", open=False):
|
| 104 |
+
custom_style_input = gr.Textbox(
|
| 105 |
+
placeholder="e.g. jazz piano, smooth male vocal",
|
| 106 |
+
show_label=False,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
create_button = gr.Button("Create song", variant="primary", elem_id="create-btn")
|
| 110 |
+
status = gr.Markdown()
|
| 111 |
+
audio_output = gr.Audio(
|
| 112 |
+
label="Your song",
|
| 113 |
+
type="filepath",
|
| 114 |
+
interactive=False,
|
| 115 |
+
buttons=["download"],
|
| 116 |
+
)
|
| 117 |
+
lyrics_output = gr.Textbox(
|
| 118 |
+
label="Lyrics",
|
| 119 |
+
lines=12,
|
| 120 |
+
max_lines=24,
|
| 121 |
+
interactive=False,
|
| 122 |
+
buttons=["copy"],
|
| 123 |
+
)
|
| 124 |
+
gr.Markdown(
|
| 125 |
+
"Lyrics: DeepSeek V4.1 Flash via Hugging Face Inference Providers, billed to your account. "
|
| 126 |
+
"Music: YuE2-3B. Model weights are CC BY-NC 4.0."
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
demo.load(lambda saved: saved, token_state, token_input)
|
| 130 |
+
verify_button.click(verify_token, token_input, [settings_status, token_state])
|
| 131 |
+
remove_button.click(remove_token, None, [token_input, token_state, settings_status])
|
| 132 |
+
create_button.click(
|
| 133 |
+
create_song,
|
| 134 |
+
[topic_input, style_input, custom_style_input, token_input],
|
| 135 |
+
[status, lyrics_output, audio_output],
|
| 136 |
+
)
|
| 137 |
+
|
| 138 |
+
demo.queue(default_concurrency_limit=1).launch(theme=gr.themes.Soft(primary_hue="violet"), css=CSS)
|
server/lyrics.py → lyrics.py
RENAMED
|
File without changes
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
pytest.ini
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest]
|
| 2 |
+
pythonpath = .
|
| 3 |
+
testpaths = tests
|
requirements-dev.txt
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
-r requirements.txt
|
| 2 |
-
pytest>=8,<9
|
| 3 |
-
httpx>=0.27,<1
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
httpx>=0.27,<1
|
| 4 |
# YuE2 inference package (pins torch/torchaudio and the other song-pipeline dependencies).
|
| 5 |
yue2_infer @ https://huggingface.co/m-a-p/YuE2-3B/resolve/main/yue2_infer-0.1.5-py3-none-any.whl
|
|
|
|
| 1 |
+
# Gradio itself comes from sdk_version in README.md.
|
| 2 |
+
spaces
|
| 3 |
httpx>=0.27,<1
|
| 4 |
# YuE2 inference package (pins torch/torchaudio and the other song-pipeline dependencies).
|
| 5 |
yue2_infer @ https://huggingface.co/m-a-p/YuE2-3B/resolve/main/yue2_infer-0.1.5-py3-none-any.whl
|
server/__init__.py
DELETED
|
File without changes
|
server/audio.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
from collections.abc import Iterator
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
from fastapi import Response
|
| 5 |
-
from fastapi.responses import StreamingResponse
|
| 6 |
-
|
| 7 |
-
CHUNK_SIZE = 64 * 1024
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def serve_audio(path: Path, range_header: str | None) -> Response:
|
| 11 |
-
"""Serve an mp3 with HTTP Range support so the browser can seek and buffer."""
|
| 12 |
-
size = path.stat().st_size
|
| 13 |
-
start, end, status = 0, size - 1, 200
|
| 14 |
-
if range_header and range_header.startswith("bytes="):
|
| 15 |
-
spec = range_header[len("bytes="):].split(",")[0].strip()
|
| 16 |
-
first, _, last = spec.partition("-")
|
| 17 |
-
try:
|
| 18 |
-
if first == "":
|
| 19 |
-
start = max(size - int(last), 0)
|
| 20 |
-
else:
|
| 21 |
-
start = int(first)
|
| 22 |
-
end = int(last) if last else size - 1
|
| 23 |
-
except ValueError:
|
| 24 |
-
return Response(status_code=416, headers={"Content-Range": f"bytes */{size}"})
|
| 25 |
-
end = min(end, size - 1)
|
| 26 |
-
if start > end:
|
| 27 |
-
return Response(status_code=416, headers={"Content-Range": f"bytes */{size}"})
|
| 28 |
-
status = 206
|
| 29 |
-
|
| 30 |
-
length = end - start + 1
|
| 31 |
-
headers = {
|
| 32 |
-
"Accept-Ranges": "bytes",
|
| 33 |
-
"Content-Length": str(length),
|
| 34 |
-
"Cache-Control": "public, max-age=86400",
|
| 35 |
-
}
|
| 36 |
-
if status == 206:
|
| 37 |
-
headers["Content-Range"] = f"bytes {start}-{end}/{size}"
|
| 38 |
-
return StreamingResponse(
|
| 39 |
-
_read_range(path, start, length),
|
| 40 |
-
status_code=status,
|
| 41 |
-
media_type="audio/mpeg",
|
| 42 |
-
headers=headers,
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def _read_range(path: Path, start: int, length: int) -> Iterator[bytes]:
|
| 47 |
-
remaining = length
|
| 48 |
-
with path.open("rb") as handle:
|
| 49 |
-
handle.seek(start)
|
| 50 |
-
while remaining > 0:
|
| 51 |
-
chunk = handle.read(min(CHUNK_SIZE, remaining))
|
| 52 |
-
if not chunk:
|
| 53 |
-
break
|
| 54 |
-
remaining -= len(chunk)
|
| 55 |
-
yield chunk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/config.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from dataclasses import dataclass
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
@dataclass(frozen=True)
|
| 7 |
-
class Settings:
|
| 8 |
-
output_dir: Path
|
| 9 |
-
max_jobs: int
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def load_settings() -> Settings:
|
| 13 |
-
return Settings(
|
| 14 |
-
output_dir=Path(os.environ.get("OUTPUT_DIR", "/tmp/tune-studio/outputs")),
|
| 15 |
-
max_jobs=int(os.environ.get("MAX_JOBS", "50")),
|
| 16 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/engines/__init__.py
DELETED
|
@@ -1,10 +0,0 @@
|
|
| 1 |
-
from server.engines.base import Engine
|
| 2 |
-
from server.engines.yue2 import Yue2Engine
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def build_engines() -> dict[str, Engine]:
|
| 6 |
-
engines: list[Engine] = [Yue2Engine()]
|
| 7 |
-
return {engine.name: engine for engine in engines}
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
__all__ = ["Engine", "build_engines"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/engines/base.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
from pathlib import Path
|
| 2 |
-
from typing import Protocol
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
class Engine(Protocol):
|
| 6 |
-
"""A music model that renders lyrics and a style prompt into a song.
|
| 7 |
-
|
| 8 |
-
Implementations must be safe to call from one worker thread at a time.
|
| 9 |
-
`status` is one of: idle, loading, ready, error.
|
| 10 |
-
"""
|
| 11 |
-
|
| 12 |
-
name: str
|
| 13 |
-
status: str
|
| 14 |
-
|
| 15 |
-
def ensure_loaded(self) -> None: ...
|
| 16 |
-
|
| 17 |
-
def compose(self, style: str, lyrics: str, seed: int, out_path: Path) -> None: ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/engines/yue2.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
import subprocess
|
| 3 |
-
import tempfile
|
| 4 |
-
import threading
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
|
| 7 |
-
logger = logging.getLogger(__name__)
|
| 8 |
-
|
| 9 |
-
SONG_MODEL_ID = "m-a-p/YuE2-3B"
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
class Yue2Engine:
|
| 13 |
-
"""Renders lyrics and a style prompt into a sung song with YuE2-3B."""
|
| 14 |
-
|
| 15 |
-
name = "yue2-3b"
|
| 16 |
-
|
| 17 |
-
def __init__(self) -> None:
|
| 18 |
-
self.status = "idle"
|
| 19 |
-
self._lock = threading.Lock()
|
| 20 |
-
self._pipe = None
|
| 21 |
-
|
| 22 |
-
def ensure_loaded(self) -> None:
|
| 23 |
-
with self._lock:
|
| 24 |
-
if self.status == "ready":
|
| 25 |
-
return
|
| 26 |
-
self.status = "loading"
|
| 27 |
-
try:
|
| 28 |
-
from yue2 import YuE2Pipeline
|
| 29 |
-
|
| 30 |
-
self._pipe = YuE2Pipeline.from_pretrained(SONG_MODEL_ID, device="cuda")
|
| 31 |
-
except Exception:
|
| 32 |
-
self.status = "error"
|
| 33 |
-
logger.exception("Failed to load YuE2 engine")
|
| 34 |
-
raise
|
| 35 |
-
self.status = "ready"
|
| 36 |
-
|
| 37 |
-
def compose(self, style: str, lyrics: str, seed: int, out_path: Path) -> None:
|
| 38 |
-
import torch
|
| 39 |
-
|
| 40 |
-
song = self._pipe(style=style, lyrics=lyrics, cot="full", seed=seed)
|
| 41 |
-
with tempfile.TemporaryDirectory() as tmp:
|
| 42 |
-
flac_path = Path(tmp) / "song.flac"
|
| 43 |
-
song.save(str(flac_path))
|
| 44 |
-
subprocess.run(
|
| 45 |
-
[
|
| 46 |
-
"ffmpeg", "-y", "-loglevel", "error",
|
| 47 |
-
"-i", str(flac_path),
|
| 48 |
-
"-codec:a", "libmp3lame", "-b:a", "256k",
|
| 49 |
-
str(out_path),
|
| 50 |
-
],
|
| 51 |
-
check=True,
|
| 52 |
-
)
|
| 53 |
-
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/jobs.py
DELETED
|
@@ -1,121 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
import random
|
| 3 |
-
import threading
|
| 4 |
-
import time
|
| 5 |
-
import uuid
|
| 6 |
-
from collections import OrderedDict
|
| 7 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
-
from dataclasses import dataclass, field
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
from server.engines import Engine
|
| 12 |
-
from server.lyrics import HfLyricsWriter, LyricsError
|
| 13 |
-
|
| 14 |
-
logger = logging.getLogger(__name__)
|
| 15 |
-
|
| 16 |
-
FINISHED = ("done", "failed")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
@dataclass(frozen=True)
|
| 20 |
-
class SongRequest:
|
| 21 |
-
topic: str
|
| 22 |
-
genre: str
|
| 23 |
-
model: str
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
@dataclass
|
| 27 |
-
class Job:
|
| 28 |
-
id: str
|
| 29 |
-
request: SongRequest
|
| 30 |
-
seed: int
|
| 31 |
-
status: str = "queued"
|
| 32 |
-
lyrics: str | None = None
|
| 33 |
-
error: str | None = None
|
| 34 |
-
audio_path: Path | None = None
|
| 35 |
-
created_at: float = field(default_factory=time.time)
|
| 36 |
-
finished_at: float | None = None
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
class JobStore:
|
| 40 |
-
"""Holds jobs in memory and renders them one at a time on a single worker.
|
| 41 |
-
|
| 42 |
-
A single worker keeps one GPU from running two songs at once. The user's Hugging Face
|
| 43 |
-
token is handed to the worker for the lyrics call and is never stored on the job.
|
| 44 |
-
"""
|
| 45 |
-
|
| 46 |
-
def __init__(
|
| 47 |
-
self,
|
| 48 |
-
engines: dict[str, Engine],
|
| 49 |
-
lyrics: HfLyricsWriter,
|
| 50 |
-
output_dir: Path,
|
| 51 |
-
max_jobs: int,
|
| 52 |
-
) -> None:
|
| 53 |
-
self._engines = engines
|
| 54 |
-
self._lyrics = lyrics
|
| 55 |
-
self._output_dir = output_dir
|
| 56 |
-
self._max_jobs = max_jobs
|
| 57 |
-
self._jobs: OrderedDict[str, Job] = OrderedDict()
|
| 58 |
-
self._lock = threading.Lock()
|
| 59 |
-
self._worker = ThreadPoolExecutor(max_workers=1, thread_name_prefix="song")
|
| 60 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
| 61 |
-
|
| 62 |
-
def submit(self, request: SongRequest, token: str) -> Job:
|
| 63 |
-
job = Job(id=uuid.uuid4().hex, request=request, seed=random.randint(0, 2**31 - 1))
|
| 64 |
-
with self._lock:
|
| 65 |
-
self._jobs[job.id] = job
|
| 66 |
-
self._evict_finished()
|
| 67 |
-
self._worker.submit(self._run, job.id, token)
|
| 68 |
-
return job
|
| 69 |
-
|
| 70 |
-
def get(self, job_id: str) -> Job | None:
|
| 71 |
-
with self._lock:
|
| 72 |
-
return self._jobs.get(job_id)
|
| 73 |
-
|
| 74 |
-
def shutdown(self) -> None:
|
| 75 |
-
self._worker.shutdown(wait=False, cancel_futures=True)
|
| 76 |
-
|
| 77 |
-
def _run(self, job_id: str, token: str) -> None:
|
| 78 |
-
job = self.get(job_id)
|
| 79 |
-
if job is None:
|
| 80 |
-
return
|
| 81 |
-
request = job.request
|
| 82 |
-
try:
|
| 83 |
-
self._update(job, status="writing_lyrics")
|
| 84 |
-
lyrics = self._lyrics.write(request.topic, token)
|
| 85 |
-
self._update(job, status="composing", lyrics=lyrics)
|
| 86 |
-
engine = self._engines[request.model]
|
| 87 |
-
engine.ensure_loaded()
|
| 88 |
-
out_path = self._output_dir / f"{job.id}.mp3"
|
| 89 |
-
engine.compose(request.genre, lyrics, job.seed, out_path)
|
| 90 |
-
self._update(job, status="done", audio_path=out_path, finished_at=time.time())
|
| 91 |
-
except LyricsError as exc:
|
| 92 |
-
self._update(job, status="failed", error=str(exc), finished_at=time.time())
|
| 93 |
-
except Exception:
|
| 94 |
-
logger.exception("Song job %s failed", job_id)
|
| 95 |
-
self._update(
|
| 96 |
-
job,
|
| 97 |
-
status="failed",
|
| 98 |
-
error="Something went wrong while making the song. Please try again.",
|
| 99 |
-
finished_at=time.time(),
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
-
def _update(self, job: Job, **changes) -> None:
|
| 103 |
-
with self._lock:
|
| 104 |
-
for key, value in changes.items():
|
| 105 |
-
setattr(job, key, value)
|
| 106 |
-
|
| 107 |
-
def _evict_finished(self) -> None:
|
| 108 |
-
"""Drop the oldest finished jobs and their audio once the store is full."""
|
| 109 |
-
excess = len(self._jobs) - self._max_jobs
|
| 110 |
-
if excess <= 0:
|
| 111 |
-
return
|
| 112 |
-
for job_id in list(self._jobs):
|
| 113 |
-
if excess <= 0:
|
| 114 |
-
break
|
| 115 |
-
job = self._jobs[job_id]
|
| 116 |
-
if job.status not in FINISHED:
|
| 117 |
-
continue
|
| 118 |
-
del self._jobs[job_id]
|
| 119 |
-
if job.audio_path is not None:
|
| 120 |
-
job.audio_path.unlink(missing_ok=True)
|
| 121 |
-
excess -= 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/main.py
DELETED
|
@@ -1,113 +0,0 @@
|
|
| 1 |
-
import threading
|
| 2 |
-
from contextlib import asynccontextmanager
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
from typing import Literal
|
| 5 |
-
|
| 6 |
-
from fastapi import FastAPI, Header, HTTPException, Request
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
-
from pydantic import BaseModel, Field
|
| 9 |
-
|
| 10 |
-
from server.audio import serve_audio
|
| 11 |
-
from server.config import Settings, load_settings
|
| 12 |
-
from server.engines import Engine, build_engines
|
| 13 |
-
from server.jobs import Job, JobStore, SongRequest
|
| 14 |
-
from server.lyrics import HfLyricsWriter, LyricsError
|
| 15 |
-
|
| 16 |
-
WEB_DIR = Path(__file__).resolve().parent.parent / "web"
|
| 17 |
-
MISSING_TOKEN_MESSAGE = "Add your Hugging Face token in Settings to create songs."
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
class SongIn(BaseModel):
|
| 21 |
-
topic: str = Field(min_length=3, max_length=300)
|
| 22 |
-
genre: str = Field(min_length=3, max_length=200)
|
| 23 |
-
model: Literal["yue2-3b"] = "yue2-3b"
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def job_view(job: Job) -> dict:
|
| 27 |
-
return {
|
| 28 |
-
"id": job.id,
|
| 29 |
-
"status": job.status,
|
| 30 |
-
"topic": job.request.topic,
|
| 31 |
-
"genre": job.request.genre,
|
| 32 |
-
"lyrics": job.lyrics,
|
| 33 |
-
"error": job.error,
|
| 34 |
-
"created_at": job.created_at,
|
| 35 |
-
"finished_at": job.finished_at,
|
| 36 |
-
"audio_url": f"/api/songs/{job.id}/audio" if job.status == "done" else None,
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def require_token(token: str | None) -> str:
|
| 41 |
-
if not token or not token.strip():
|
| 42 |
-
raise HTTPException(status_code=401, detail=MISSING_TOKEN_MESSAGE)
|
| 43 |
-
return token.strip()
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def create_app(
|
| 47 |
-
engines: dict[str, Engine] | None = None,
|
| 48 |
-
settings: Settings | None = None,
|
| 49 |
-
lyrics: HfLyricsWriter | None = None,
|
| 50 |
-
) -> FastAPI:
|
| 51 |
-
settings = settings or load_settings()
|
| 52 |
-
engines = engines if engines is not None else build_engines()
|
| 53 |
-
lyrics = lyrics or HfLyricsWriter()
|
| 54 |
-
store = JobStore(engines, lyrics, settings.output_dir, settings.max_jobs)
|
| 55 |
-
|
| 56 |
-
@asynccontextmanager
|
| 57 |
-
async def lifespan(_: FastAPI):
|
| 58 |
-
# Load the music model in the background so the page is reachable during a cold start.
|
| 59 |
-
for engine in engines.values():
|
| 60 |
-
threading.Thread(target=_preload, args=(engine,), daemon=True).start()
|
| 61 |
-
yield
|
| 62 |
-
store.shutdown()
|
| 63 |
-
|
| 64 |
-
app = FastAPI(title="Tune Studio", lifespan=lifespan)
|
| 65 |
-
|
| 66 |
-
@app.get("/api/health")
|
| 67 |
-
def health() -> dict:
|
| 68 |
-
return {"models": {name: engine.status for name, engine in engines.items()}}
|
| 69 |
-
|
| 70 |
-
@app.post("/api/settings/verify-token")
|
| 71 |
-
def verify_token(x_hf_token: str | None = Header(default=None)) -> dict:
|
| 72 |
-
token = require_token(x_hf_token)
|
| 73 |
-
try:
|
| 74 |
-
return {"username": lyrics.verify(token)}
|
| 75 |
-
except LyricsError as exc:
|
| 76 |
-
raise HTTPException(status_code=401, detail=str(exc)) from exc
|
| 77 |
-
|
| 78 |
-
@app.post("/api/songs", status_code=202)
|
| 79 |
-
def create_song(
|
| 80 |
-
body: SongIn,
|
| 81 |
-
x_hf_token: str | None = Header(default=None),
|
| 82 |
-
) -> dict:
|
| 83 |
-
token = require_token(x_hf_token)
|
| 84 |
-
job = store.submit(SongRequest(topic=body.topic.strip(), genre=body.genre.strip(), model=body.model), token)
|
| 85 |
-
return job_view(job)
|
| 86 |
-
|
| 87 |
-
@app.get("/api/songs/{job_id}")
|
| 88 |
-
def get_song(job_id: str) -> dict:
|
| 89 |
-
job = store.get(job_id)
|
| 90 |
-
if job is None:
|
| 91 |
-
raise HTTPException(status_code=404, detail="Song not found")
|
| 92 |
-
return job_view(job)
|
| 93 |
-
|
| 94 |
-
@app.get("/api/songs/{job_id}/audio")
|
| 95 |
-
def get_audio(job_id: str, request: Request):
|
| 96 |
-
job = store.get(job_id)
|
| 97 |
-
if job is None or job.status != "done" or job.audio_path is None:
|
| 98 |
-
raise HTTPException(status_code=404, detail="Audio not ready")
|
| 99 |
-
return serve_audio(job.audio_path, request.headers.get("range"))
|
| 100 |
-
|
| 101 |
-
app.mount("/", StaticFiles(directory=WEB_DIR, html=True), name="web")
|
| 102 |
-
return app
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
def _preload(engine: Engine) -> None:
|
| 106 |
-
try:
|
| 107 |
-
engine.ensure_loaded()
|
| 108 |
-
except Exception:
|
| 109 |
-
# The engine already logged the error and reports status "error" on /api/health.
|
| 110 |
-
pass
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
app = create_app()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
import torch
|
| 7 |
+
from yue2 import YuE2Pipeline
|
| 8 |
+
|
| 9 |
+
SONG_MODEL_ID = "m-a-p/YuE2-3B"
|
| 10 |
+
GPU_SECONDS = 300
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _load_pipeline() -> YuE2Pipeline:
|
| 14 |
+
# ZeroGPU emulates CUDA outside @spaces.GPU calls. The pipeline's constructor queries the
|
| 15 |
+
# current device, which fails under that emulation unless the memory-fraction call is a no-op.
|
| 16 |
+
original = torch.cuda.set_per_process_memory_fraction
|
| 17 |
+
torch.cuda.set_per_process_memory_fraction = lambda *args, **kwargs: None
|
| 18 |
+
try:
|
| 19 |
+
return YuE2Pipeline.from_pretrained(SONG_MODEL_ID, device="cuda")
|
| 20 |
+
finally:
|
| 21 |
+
torch.cuda.set_per_process_memory_fraction = original
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
PIPELINE = _load_pipeline()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@spaces.GPU(duration=GPU_SECONDS)
|
| 28 |
+
def render_song(style: str, lyrics: str, seed: int) -> str:
|
| 29 |
+
"""Render lyrics and a style prompt to an mp3 file and return its path."""
|
| 30 |
+
song = PIPELINE(style=style, lyrics=lyrics, cot="full", seed=seed)
|
| 31 |
+
out_dir = Path(tempfile.mkdtemp(prefix="tune-studio-"))
|
| 32 |
+
flac_path = out_dir / "song.flac"
|
| 33 |
+
mp3_path = out_dir / "song.mp3"
|
| 34 |
+
song.save(str(flac_path))
|
| 35 |
+
subprocess.run(
|
| 36 |
+
[
|
| 37 |
+
"ffmpeg", "-y", "-loglevel", "error",
|
| 38 |
+
"-i", str(flac_path),
|
| 39 |
+
"-codec:a", "libmp3lame", "-b:a", "256k",
|
| 40 |
+
str(mp3_path),
|
| 41 |
+
],
|
| 42 |
+
check=True,
|
| 43 |
+
)
|
| 44 |
+
flac_path.unlink()
|
| 45 |
+
return str(mp3_path)
|
tests/test_api.py
DELETED
|
@@ -1,208 +0,0 @@
|
|
| 1 |
-
import time
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
|
| 4 |
-
import pytest
|
| 5 |
-
from fastapi.testclient import TestClient
|
| 6 |
-
|
| 7 |
-
from server.config import Settings
|
| 8 |
-
from server.lyrics import LyricsError
|
| 9 |
-
from server.main import create_app
|
| 10 |
-
|
| 11 |
-
FAKE_AUDIO = bytes(range(256)) * 40 # stand-in mp3 bytes; the real encoder needs the GPU image
|
| 12 |
-
TOKEN = "hf_test_token_value"
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
class StubEngine:
|
| 16 |
-
"""Stands in for YuE2 so the API and job flow can run without a GPU."""
|
| 17 |
-
|
| 18 |
-
name = "yue2-3b"
|
| 19 |
-
|
| 20 |
-
def __init__(self) -> None:
|
| 21 |
-
self.status = "ready"
|
| 22 |
-
self.composed_with: dict | None = None
|
| 23 |
-
|
| 24 |
-
def ensure_loaded(self) -> None:
|
| 25 |
-
return None
|
| 26 |
-
|
| 27 |
-
def compose(self, style: str, lyrics: str, seed: int, out_path: Path) -> None:
|
| 28 |
-
self.composed_with = {"style": style, "lyrics": lyrics, "seed": seed}
|
| 29 |
-
out_path.write_bytes(FAKE_AUDIO)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
class StubLyrics:
|
| 33 |
-
"""Stands in for the Hugging Face lyrics call."""
|
| 34 |
-
|
| 35 |
-
def __init__(self, error: str | None = None) -> None:
|
| 36 |
-
self.error = error
|
| 37 |
-
self.tokens_seen: list[str] = []
|
| 38 |
-
|
| 39 |
-
def write(self, topic: str, token: str) -> str:
|
| 40 |
-
self.tokens_seen.append(token)
|
| 41 |
-
if self.error:
|
| 42 |
-
raise LyricsError(self.error)
|
| 43 |
-
return f"[Verse]\n{topic}\n[Chorus]\nla la la"
|
| 44 |
-
|
| 45 |
-
def verify(self, token: str) -> str:
|
| 46 |
-
if token != TOKEN:
|
| 47 |
-
raise LyricsError("Hugging Face rejected this token.")
|
| 48 |
-
return "tester"
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def song_payload(**overrides) -> dict:
|
| 52 |
-
payload = {"topic": "rainy night in the city", "genre": "Lo-fi hip hop, mellow"}
|
| 53 |
-
payload.update(overrides)
|
| 54 |
-
return payload
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def auth(token: str = TOKEN) -> dict:
|
| 58 |
-
return {"X-HF-Token": token}
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def wait_for_status(client: TestClient, job_id: str, statuses: tuple[str, ...]) -> dict:
|
| 62 |
-
deadline = time.time() + 5
|
| 63 |
-
while time.time() < deadline:
|
| 64 |
-
job = client.get(f"/api/songs/{job_id}").json()
|
| 65 |
-
if job["status"] in statuses:
|
| 66 |
-
return job
|
| 67 |
-
time.sleep(0.02)
|
| 68 |
-
raise AssertionError(f"job {job_id} did not reach {statuses}")
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
@pytest.fixture
|
| 72 |
-
def make_client(tmp_path):
|
| 73 |
-
def build(engine: StubEngine, lyrics: StubLyrics | None = None, max_jobs: int = 50) -> TestClient:
|
| 74 |
-
settings = Settings(output_dir=tmp_path / "outputs", max_jobs=max_jobs)
|
| 75 |
-
app = create_app(
|
| 76 |
-
engines={engine.name: engine},
|
| 77 |
-
settings=settings,
|
| 78 |
-
lyrics=lyrics or StubLyrics(),
|
| 79 |
-
)
|
| 80 |
-
return TestClient(app)
|
| 81 |
-
|
| 82 |
-
return build
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def test_health_reports_engine_status(make_client):
|
| 86 |
-
with make_client(StubEngine()) as client:
|
| 87 |
-
response = client.get("/api/health")
|
| 88 |
-
assert response.status_code == 200
|
| 89 |
-
assert response.json() == {"models": {"yue2-3b": "ready"}}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
def test_topic_becomes_playable_song_and_token_stays_out_of_responses(make_client):
|
| 93 |
-
engine = StubEngine()
|
| 94 |
-
lyrics = StubLyrics()
|
| 95 |
-
with make_client(engine, lyrics) as client:
|
| 96 |
-
created = client.post("/api/songs", json=song_payload(), headers=auth())
|
| 97 |
-
assert created.status_code == 202
|
| 98 |
-
job_id = created.json()["id"]
|
| 99 |
-
|
| 100 |
-
job = wait_for_status(client, job_id, ("done", "failed"))
|
| 101 |
-
|
| 102 |
-
assert job["status"] == "done"
|
| 103 |
-
assert job["lyrics"].startswith("[Verse]")
|
| 104 |
-
assert job["audio_url"] == f"/api/songs/{job_id}/audio"
|
| 105 |
-
assert lyrics.tokens_seen == [TOKEN]
|
| 106 |
-
assert engine.composed_with["style"] == "Lo-fi hip hop, mellow"
|
| 107 |
-
assert engine.composed_with["lyrics"] == job["lyrics"]
|
| 108 |
-
assert TOKEN not in str(job) and TOKEN not in str(created.json())
|
| 109 |
-
|
| 110 |
-
audio = client.get(job["audio_url"])
|
| 111 |
-
assert audio.status_code == 200
|
| 112 |
-
assert audio.headers["content-type"] == "audio/mpeg"
|
| 113 |
-
assert audio.headers["accept-ranges"] == "bytes"
|
| 114 |
-
assert audio.content == FAKE_AUDIO
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
def test_range_request_returns_partial_audio(make_client):
|
| 118 |
-
with make_client(StubEngine()) as client:
|
| 119 |
-
job_id = client.post("/api/songs", json=song_payload(), headers=auth()).json()["id"]
|
| 120 |
-
wait_for_status(client, job_id, ("done",))
|
| 121 |
-
url = f"/api/songs/{job_id}/audio"
|
| 122 |
-
|
| 123 |
-
partial = client.get(url, headers={"Range": "bytes=100-199"})
|
| 124 |
-
assert partial.status_code == 206
|
| 125 |
-
assert partial.headers["content-range"] == f"bytes 100-199/{len(FAKE_AUDIO)}"
|
| 126 |
-
assert partial.content == FAKE_AUDIO[100:200]
|
| 127 |
-
|
| 128 |
-
tail = client.get(url, headers={"Range": "bytes=-50"})
|
| 129 |
-
assert tail.status_code == 206
|
| 130 |
-
assert tail.content == FAKE_AUDIO[-50:]
|
| 131 |
-
|
| 132 |
-
unsatisfiable = client.get(url, headers={"Range": f"bytes={len(FAKE_AUDIO) + 10}-"})
|
| 133 |
-
assert unsatisfiable.status_code == 416
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
def test_lyrics_error_is_shown_to_user_and_no_audio_is_made(make_client):
|
| 137 |
-
engine = StubEngine()
|
| 138 |
-
message = "Hugging Face rejected your token. Update it in Settings."
|
| 139 |
-
with make_client(engine, StubLyrics(error=message)) as client:
|
| 140 |
-
job_id = client.post("/api/songs", json=song_payload(), headers=auth()).json()["id"]
|
| 141 |
-
job = wait_for_status(client, job_id, ("done", "failed"))
|
| 142 |
-
|
| 143 |
-
assert job["status"] == "failed"
|
| 144 |
-
assert job["error"] == message
|
| 145 |
-
assert engine.composed_with is None
|
| 146 |
-
assert client.get(f"/api/songs/{job_id}/audio").status_code == 404
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
def test_missing_token_is_rejected_before_any_work(make_client):
|
| 150 |
-
lyrics = StubLyrics()
|
| 151 |
-
with make_client(StubEngine(), lyrics) as client:
|
| 152 |
-
response = client.post("/api/songs", json=song_payload())
|
| 153 |
-
blank = client.post("/api/songs", json=song_payload(), headers=auth(" "))
|
| 154 |
-
assert response.status_code == 401
|
| 155 |
-
assert "Settings" in response.json()["detail"]
|
| 156 |
-
assert blank.status_code == 401
|
| 157 |
-
assert lyrics.tokens_seen == []
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
def test_verify_token_returns_username_or_401(make_client):
|
| 161 |
-
with make_client(StubEngine()) as client:
|
| 162 |
-
good = client.post("/api/settings/verify-token", headers=auth())
|
| 163 |
-
bad = client.post("/api/settings/verify-token", headers=auth("hf_wrong"))
|
| 164 |
-
missing = client.post("/api/settings/verify-token")
|
| 165 |
-
assert good.json() == {"username": "tester"}
|
| 166 |
-
assert bad.status_code == 401
|
| 167 |
-
assert missing.status_code == 401
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
@pytest.mark.parametrize(
|
| 171 |
-
"payload",
|
| 172 |
-
[
|
| 173 |
-
song_payload(topic="hi"),
|
| 174 |
-
song_payload(genre=""),
|
| 175 |
-
song_payload(topic="x" * 301),
|
| 176 |
-
],
|
| 177 |
-
)
|
| 178 |
-
def test_invalid_song_request_is_rejected(make_client, payload):
|
| 179 |
-
with make_client(StubEngine()) as client:
|
| 180 |
-
response = client.post("/api/songs", json=payload, headers=auth())
|
| 181 |
-
assert response.status_code == 422
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def test_unknown_model_is_rejected(make_client):
|
| 185 |
-
with make_client(StubEngine()) as client:
|
| 186 |
-
response = client.post("/api/songs", json=song_payload(model="missing"), headers=auth())
|
| 187 |
-
assert response.status_code == 422
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
def test_unknown_job_returns_404(make_client):
|
| 191 |
-
with make_client(StubEngine()) as client:
|
| 192 |
-
assert client.get("/api/songs/does-not-exist").status_code == 404
|
| 193 |
-
assert client.get("/api/songs/does-not-exist/audio").status_code == 404
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
def test_oldest_finished_jobs_are_evicted_with_their_audio(make_client, tmp_path):
|
| 197 |
-
with make_client(StubEngine(), max_jobs=2) as client:
|
| 198 |
-
ids = []
|
| 199 |
-
for _ in range(3):
|
| 200 |
-
job_id = client.post("/api/songs", json=song_payload(), headers=auth()).json()["id"]
|
| 201 |
-
wait_for_status(client, job_id, ("done",))
|
| 202 |
-
ids.append(job_id)
|
| 203 |
-
|
| 204 |
-
first, second, third = ids
|
| 205 |
-
assert client.get(f"/api/songs/{first}").status_code == 404
|
| 206 |
-
assert not (tmp_path / "outputs" / f"{first}.mp3").exists()
|
| 207 |
-
assert client.get(f"/api/songs/{second}").status_code == 200
|
| 208 |
-
assert client.get(f"/api/songs/{third}").status_code == 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_lyrics.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import httpx
|
| 2 |
import pytest
|
| 3 |
|
| 4 |
-
|
| 5 |
-
from
|
| 6 |
|
| 7 |
|
| 8 |
def test_clean_lyrics_strips_reasoning_and_code_fences():
|
|
|
|
| 1 |
import httpx
|
| 2 |
import pytest
|
| 3 |
|
| 4 |
+
import lyrics as lyrics_module
|
| 5 |
+
from lyrics import HfLyricsWriter, LyricsError, clean_lyrics
|
| 6 |
|
| 7 |
|
| 8 |
def test_clean_lyrics_strips_reasoning_and_code_fences():
|
web/app.js
DELETED
|
@@ -1,505 +0,0 @@
|
|
| 1 |
-
const STYLE_PRESETS = [
|
| 2 |
-
{ label: "Pop", style: "Pop, catchy hook, bright synth, tight drums, female lead vocal" },
|
| 3 |
-
{ label: "Ballad", style: "Ballad, emotional, piano, warm strings, male lead vocal" },
|
| 4 |
-
{ label: "Lo-fi", style: "Lo-fi hip hop, mellow, warm keys, vinyl crackle, soft female vocal" },
|
| 5 |
-
{ label: "Rock", style: "Rock, energetic, electric guitar, live drums, bass, male lead vocal" },
|
| 6 |
-
{ label: "EDM", style: "Electronic dance, uplifting, supersaw lead, four-on-the-floor drums, female lead vocal" },
|
| 7 |
-
{ label: "R&B", style: "R&B, smooth, soulful, electric piano, groove bass, female lead vocal" },
|
| 8 |
-
{ label: "Acoustic", style: "Folk, acoustic guitar, gentle, intimate, male lead vocal" },
|
| 9 |
-
{ label: "Cinematic", style: "Cinematic pop, orchestral, epic build, choir, female lead vocal" },
|
| 10 |
-
];
|
| 11 |
-
|
| 12 |
-
const STATUS_LABELS = {
|
| 13 |
-
queued: "Queued…",
|
| 14 |
-
writing_lyrics: "Writing lyrics…",
|
| 15 |
-
composing: "Singing and producing. This usually takes a few minutes.",
|
| 16 |
-
done: "Done",
|
| 17 |
-
failed: "Failed",
|
| 18 |
-
};
|
| 19 |
-
const TOKEN_KEY = "tune-studio.hf-token";
|
| 20 |
-
const HISTORY_KEY = "tune-studio.history";
|
| 21 |
-
const HISTORY_LIMIT = 12;
|
| 22 |
-
const POLL_MS = 1500;
|
| 23 |
-
|
| 24 |
-
const $ = (selector) => document.querySelector(selector);
|
| 25 |
-
const form = $("#song-form");
|
| 26 |
-
const topicInput = $("#topic");
|
| 27 |
-
const customStyle = $("#custom-style");
|
| 28 |
-
const submitButton = $("#submit");
|
| 29 |
-
const formError = $("#form-error");
|
| 30 |
-
const settingsDialog = $("#settings");
|
| 31 |
-
const tokenInput = $("#token");
|
| 32 |
-
const settingsStatus = $("#settings-status");
|
| 33 |
-
const player = new Audio();
|
| 34 |
-
player.preload = "metadata";
|
| 35 |
-
|
| 36 |
-
const ui = {
|
| 37 |
-
health: $("#health"),
|
| 38 |
-
resultCard: $("#result-card"),
|
| 39 |
-
progress: $("#progress"),
|
| 40 |
-
progressText: $("#progress-text"),
|
| 41 |
-
elapsed: $("#elapsed"),
|
| 42 |
-
failure: $("#failure"),
|
| 43 |
-
song: $("#song"),
|
| 44 |
-
songTitle: $("#song-title"),
|
| 45 |
-
songMeta: $("#song-meta"),
|
| 46 |
-
lyrics: $("#lyrics"),
|
| 47 |
-
download: $("#download"),
|
| 48 |
-
play: $("#play"),
|
| 49 |
-
playIcon: $("#play-icon"),
|
| 50 |
-
seekbar: $("#seekbar"),
|
| 51 |
-
cur: $("#cur"),
|
| 52 |
-
dur: $("#dur"),
|
| 53 |
-
copy: $("#copy"),
|
| 54 |
-
historyCard: $("#history-card"),
|
| 55 |
-
history: $("#history"),
|
| 56 |
-
topicCount: $("#topic-count"),
|
| 57 |
-
};
|
| 58 |
-
|
| 59 |
-
let activeJob = null;
|
| 60 |
-
let pollTimer = null;
|
| 61 |
-
let clockTimer = null;
|
| 62 |
-
|
| 63 |
-
// ---------- Token (kept in this browser only) ----------
|
| 64 |
-
|
| 65 |
-
function readToken() {
|
| 66 |
-
try {
|
| 67 |
-
return localStorage.getItem(TOKEN_KEY) || "";
|
| 68 |
-
} catch {
|
| 69 |
-
return "";
|
| 70 |
-
}
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
function writeToken(value) {
|
| 74 |
-
try {
|
| 75 |
-
if (value) localStorage.setItem(TOKEN_KEY, value);
|
| 76 |
-
else localStorage.removeItem(TOKEN_KEY);
|
| 77 |
-
} catch {
|
| 78 |
-
// Storage is blocked; the token only lasts for this page session.
|
| 79 |
-
}
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
function openSettings(message = "") {
|
| 83 |
-
tokenInput.value = readToken();
|
| 84 |
-
settingsStatus.textContent = message;
|
| 85 |
-
settingsStatus.className = message ? "small warn-text" : "small";
|
| 86 |
-
settingsDialog.showModal();
|
| 87 |
-
tokenInput.focus();
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
$("#open-settings").addEventListener("click", () => openSettings());
|
| 91 |
-
|
| 92 |
-
$("#toggle-token").addEventListener("click", (event) => {
|
| 93 |
-
const showing = tokenInput.type === "text";
|
| 94 |
-
tokenInput.type = showing ? "password" : "text";
|
| 95 |
-
event.currentTarget.textContent = showing ? "Show" : "Hide";
|
| 96 |
-
});
|
| 97 |
-
|
| 98 |
-
$("#save-token").addEventListener("click", async (event) => {
|
| 99 |
-
const token = tokenInput.value.trim();
|
| 100 |
-
if (!token) {
|
| 101 |
-
settingsStatus.textContent = "Paste your token first.";
|
| 102 |
-
settingsStatus.className = "small warn-text";
|
| 103 |
-
return;
|
| 104 |
-
}
|
| 105 |
-
const button = event.currentTarget;
|
| 106 |
-
button.disabled = true;
|
| 107 |
-
settingsStatus.textContent = "Checking token…";
|
| 108 |
-
settingsStatus.className = "small";
|
| 109 |
-
try {
|
| 110 |
-
const response = await fetch("/api/settings/verify-token", {
|
| 111 |
-
method: "POST",
|
| 112 |
-
headers: { "X-HF-Token": token },
|
| 113 |
-
});
|
| 114 |
-
if (!response.ok) throw new Error(await errorMessage(response));
|
| 115 |
-
const { username } = await response.json();
|
| 116 |
-
writeToken(token);
|
| 117 |
-
settingsStatus.textContent = `Connected as ${username}. Saved in this browser.`;
|
| 118 |
-
settingsStatus.className = "small ok-text";
|
| 119 |
-
setTimeout(() => settingsDialog.close(), 900);
|
| 120 |
-
} catch (error) {
|
| 121 |
-
settingsStatus.textContent = error.message;
|
| 122 |
-
settingsStatus.className = "small warn-text";
|
| 123 |
-
} finally {
|
| 124 |
-
button.disabled = false;
|
| 125 |
-
}
|
| 126 |
-
});
|
| 127 |
-
|
| 128 |
-
$("#remove-token").addEventListener("click", () => {
|
| 129 |
-
writeToken("");
|
| 130 |
-
tokenInput.value = "";
|
| 131 |
-
settingsStatus.textContent = "Token removed from this browser.";
|
| 132 |
-
settingsStatus.className = "small";
|
| 133 |
-
});
|
| 134 |
-
|
| 135 |
-
// ---------- Form ----------
|
| 136 |
-
|
| 137 |
-
function renderStyleChips() {
|
| 138 |
-
const wrap = $("#style-chips");
|
| 139 |
-
STYLE_PRESETS.forEach((preset, index) => {
|
| 140 |
-
const chip = document.createElement("button");
|
| 141 |
-
chip.type = "button";
|
| 142 |
-
chip.className = "chip";
|
| 143 |
-
chip.textContent = preset.label;
|
| 144 |
-
chip.setAttribute("role", "radio");
|
| 145 |
-
chip.dataset.style = preset.style;
|
| 146 |
-
chip.setAttribute("aria-checked", String(index === 0));
|
| 147 |
-
chip.tabIndex = index === 0 ? 0 : -1;
|
| 148 |
-
chip.addEventListener("click", () => selectChip(chip));
|
| 149 |
-
wrap.append(chip);
|
| 150 |
-
});
|
| 151 |
-
}
|
| 152 |
-
|
| 153 |
-
function selectChip(chip) {
|
| 154 |
-
for (const other of document.querySelectorAll(".chip")) {
|
| 155 |
-
other.setAttribute("aria-checked", String(other === chip));
|
| 156 |
-
other.tabIndex = other === chip ? 0 : -1;
|
| 157 |
-
}
|
| 158 |
-
chip.focus();
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
function selectedStyle() {
|
| 162 |
-
const custom = customStyle.value.trim();
|
| 163 |
-
if (custom) return custom;
|
| 164 |
-
const chip = document.querySelector('.chip[aria-checked="true"]');
|
| 165 |
-
return chip ? chip.dataset.style : STYLE_PRESETS[0].style;
|
| 166 |
-
}
|
| 167 |
-
|
| 168 |
-
topicInput.addEventListener("input", () => {
|
| 169 |
-
ui.topicCount.textContent = `${topicInput.value.length}/300`;
|
| 170 |
-
});
|
| 171 |
-
|
| 172 |
-
form.addEventListener("keydown", (event) => {
|
| 173 |
-
if ((event.ctrlKey || event.metaKey) && event.key === "Enter") {
|
| 174 |
-
event.preventDefault();
|
| 175 |
-
form.requestSubmit();
|
| 176 |
-
}
|
| 177 |
-
});
|
| 178 |
-
|
| 179 |
-
form.addEventListener("submit", async (event) => {
|
| 180 |
-
event.preventDefault();
|
| 181 |
-
formError.hidden = true;
|
| 182 |
-
|
| 183 |
-
const topic = topicInput.value.trim();
|
| 184 |
-
if (topic.length < 3) return showFormError("Please describe your song in at least 3 characters.");
|
| 185 |
-
|
| 186 |
-
const token = readToken();
|
| 187 |
-
if (!token) return openSettings("Add your Hugging Face token to create songs.");
|
| 188 |
-
|
| 189 |
-
submitButton.disabled = true;
|
| 190 |
-
try {
|
| 191 |
-
const response = await fetch("/api/songs", {
|
| 192 |
-
method: "POST",
|
| 193 |
-
headers: { "Content-Type": "application/json", "X-HF-Token": token },
|
| 194 |
-
body: JSON.stringify({ topic, genre: selectedStyle(), model: "yue2-3b" }),
|
| 195 |
-
});
|
| 196 |
-
if (response.status === 401) {
|
| 197 |
-
return openSettings(await errorMessage(response));
|
| 198 |
-
}
|
| 199 |
-
if (!response.ok) throw new Error(await errorMessage(response));
|
| 200 |
-
startJob(await response.json());
|
| 201 |
-
} catch (error) {
|
| 202 |
-
showFormError(error.message || "Could not start the song. Please try again.");
|
| 203 |
-
} finally {
|
| 204 |
-
submitButton.disabled = false;
|
| 205 |
-
}
|
| 206 |
-
});
|
| 207 |
-
|
| 208 |
-
function showFormError(message) {
|
| 209 |
-
formError.textContent = message;
|
| 210 |
-
formError.hidden = false;
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
async function errorMessage(response) {
|
| 214 |
-
try {
|
| 215 |
-
const data = await response.json();
|
| 216 |
-
return typeof data.detail === "string" ? data.detail : `Request failed (${response.status}).`;
|
| 217 |
-
} catch {
|
| 218 |
-
return `Server error (${response.status}).`;
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
// ---------- Job lifecycle ----------
|
| 223 |
-
|
| 224 |
-
function startJob(job) {
|
| 225 |
-
stopPolling();
|
| 226 |
-
activeJob = { id: job.id, startedAt: Date.now() };
|
| 227 |
-
ui.resultCard.hidden = false;
|
| 228 |
-
ui.song.hidden = true;
|
| 229 |
-
showPanel("progress");
|
| 230 |
-
renderJob(job);
|
| 231 |
-
startClock();
|
| 232 |
-
scheduleNextPoll();
|
| 233 |
-
ui.resultCard.scrollIntoView({ behavior: "smooth", block: "start" });
|
| 234 |
-
}
|
| 235 |
-
|
| 236 |
-
function scheduleNextPoll() {
|
| 237 |
-
pollTimer = setTimeout(pollJob, POLL_MS);
|
| 238 |
-
}
|
| 239 |
-
|
| 240 |
-
async function pollJob() {
|
| 241 |
-
if (!activeJob) return;
|
| 242 |
-
const jobId = activeJob.id;
|
| 243 |
-
try {
|
| 244 |
-
const response = await fetch(`/api/songs/${jobId}`);
|
| 245 |
-
if (!activeJob || activeJob.id !== jobId) return;
|
| 246 |
-
if (response.status === 404) {
|
| 247 |
-
endActiveJob();
|
| 248 |
-
showFailure("The server restarted and lost this song. Please create it again.");
|
| 249 |
-
return;
|
| 250 |
-
}
|
| 251 |
-
if (!response.ok) throw new Error(await errorMessage(response));
|
| 252 |
-
const job = await response.json();
|
| 253 |
-
renderJob(job);
|
| 254 |
-
if (job.status === "done" || job.status === "failed") {
|
| 255 |
-
finishJob(job);
|
| 256 |
-
return;
|
| 257 |
-
}
|
| 258 |
-
} catch (error) {
|
| 259 |
-
ui.progressText.textContent = `Connection lost, retrying… (${error.message})`;
|
| 260 |
-
}
|
| 261 |
-
scheduleNextPoll();
|
| 262 |
-
}
|
| 263 |
-
|
| 264 |
-
function finishJob(job) {
|
| 265 |
-
endActiveJob();
|
| 266 |
-
if (job.status === "failed") {
|
| 267 |
-
showFailure(job.error || "Could not create the song.");
|
| 268 |
-
return;
|
| 269 |
-
}
|
| 270 |
-
rememberSong(job);
|
| 271 |
-
renderSong(job);
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
function endActiveJob() {
|
| 275 |
-
activeJob = null;
|
| 276 |
-
stopPolling();
|
| 277 |
-
stopClock();
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
function stopPolling() {
|
| 281 |
-
clearTimeout(pollTimer);
|
| 282 |
-
pollTimer = null;
|
| 283 |
-
}
|
| 284 |
-
|
| 285 |
-
function startClock() {
|
| 286 |
-
stopClock();
|
| 287 |
-
const tick = () => {
|
| 288 |
-
if (!activeJob) return;
|
| 289 |
-
const seconds = Math.floor((Date.now() - activeJob.startedAt) / 1000);
|
| 290 |
-
ui.elapsed.textContent = `Elapsed ${formatTime(seconds)}`;
|
| 291 |
-
};
|
| 292 |
-
tick();
|
| 293 |
-
clockTimer = setInterval(tick, 1000);
|
| 294 |
-
}
|
| 295 |
-
|
| 296 |
-
function stopClock() {
|
| 297 |
-
clearInterval(clockTimer);
|
| 298 |
-
clockTimer = null;
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
function renderJob(job) {
|
| 302 |
-
ui.progressText.textContent = STATUS_LABELS[job.status] || job.status;
|
| 303 |
-
const order = ["writing_lyrics", "composing", "done"];
|
| 304 |
-
const current = order.indexOf(job.status);
|
| 305 |
-
for (const step of document.querySelectorAll(".steps li")) {
|
| 306 |
-
const index = order.indexOf(step.dataset.step);
|
| 307 |
-
step.dataset.active = String(index === current);
|
| 308 |
-
step.dataset.done = String(current > index);
|
| 309 |
-
}
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
// ---------- Result ----------
|
| 313 |
-
|
| 314 |
-
function showPanel(name) {
|
| 315 |
-
ui.progress.hidden = name !== "progress";
|
| 316 |
-
ui.failure.hidden = true;
|
| 317 |
-
}
|
| 318 |
-
|
| 319 |
-
function showFailure(message) {
|
| 320 |
-
ui.progress.hidden = true;
|
| 321 |
-
ui.song.hidden = true;
|
| 322 |
-
ui.failure.textContent = message;
|
| 323 |
-
ui.failure.hidden = false;
|
| 324 |
-
}
|
| 325 |
-
|
| 326 |
-
function renderSong(job) {
|
| 327 |
-
ui.resultCard.hidden = false;
|
| 328 |
-
ui.progress.hidden = true;
|
| 329 |
-
ui.failure.hidden = true;
|
| 330 |
-
ui.song.hidden = false;
|
| 331 |
-
|
| 332 |
-
ui.songTitle.textContent = job.topic;
|
| 333 |
-
ui.songMeta.replaceChildren(
|
| 334 |
-
...[job.genre].map((text) => {
|
| 335 |
-
const tag = document.createElement("span");
|
| 336 |
-
tag.textContent = text;
|
| 337 |
-
return tag;
|
| 338 |
-
}),
|
| 339 |
-
);
|
| 340 |
-
ui.lyrics.textContent = job.lyrics || "";
|
| 341 |
-
setTrack(job.audio_url, `${slug(job.topic)}.mp3`);
|
| 342 |
-
}
|
| 343 |
-
|
| 344 |
-
// Replace the audio source in one place so the previous track stops and the new one loads cleanly.
|
| 345 |
-
function setTrack(url, downloadName) {
|
| 346 |
-
player.pause();
|
| 347 |
-
player.src = url;
|
| 348 |
-
player.load();
|
| 349 |
-
ui.download.href = url;
|
| 350 |
-
ui.download.download = downloadName;
|
| 351 |
-
ui.seekbar.value = 0;
|
| 352 |
-
ui.cur.textContent = "0:00";
|
| 353 |
-
ui.dur.textContent = "0:00";
|
| 354 |
-
setPlayIcon(false);
|
| 355 |
-
}
|
| 356 |
-
|
| 357 |
-
function setPlayIcon(playing) {
|
| 358 |
-
ui.playIcon.setAttribute("d", playing ? "M7 5h4v14H7zm6 0h4v14h-4z" : "M8 5v14l11-7z");
|
| 359 |
-
ui.play.setAttribute("aria-label", playing ? "Pause" : "Play");
|
| 360 |
-
}
|
| 361 |
-
|
| 362 |
-
ui.play.addEventListener("click", () => {
|
| 363 |
-
if (!player.src) return;
|
| 364 |
-
if (player.paused) player.play();
|
| 365 |
-
else player.pause();
|
| 366 |
-
});
|
| 367 |
-
player.addEventListener("play", () => setPlayIcon(true));
|
| 368 |
-
player.addEventListener("pause", () => setPlayIcon(false));
|
| 369 |
-
player.addEventListener("ended", () => setPlayIcon(false));
|
| 370 |
-
player.addEventListener("loadedmetadata", () => {
|
| 371 |
-
ui.dur.textContent = formatTime(player.duration);
|
| 372 |
-
});
|
| 373 |
-
player.addEventListener("timeupdate", () => {
|
| 374 |
-
ui.cur.textContent = formatTime(player.currentTime);
|
| 375 |
-
if (player.duration) {
|
| 376 |
-
ui.seekbar.value = String((player.currentTime / player.duration) * 1000);
|
| 377 |
-
}
|
| 378 |
-
});
|
| 379 |
-
ui.seekbar.addEventListener("input", () => {
|
| 380 |
-
if (player.duration) {
|
| 381 |
-
player.currentTime = (Number(ui.seekbar.value) / 1000) * player.duration;
|
| 382 |
-
}
|
| 383 |
-
});
|
| 384 |
-
|
| 385 |
-
ui.copy.addEventListener("click", async () => {
|
| 386 |
-
try {
|
| 387 |
-
await navigator.clipboard.writeText(ui.lyrics.textContent);
|
| 388 |
-
ui.copy.textContent = "Copied";
|
| 389 |
-
setTimeout(() => (ui.copy.textContent = "Copy"), 1500);
|
| 390 |
-
} catch {
|
| 391 |
-
ui.copy.textContent = "Copy failed";
|
| 392 |
-
}
|
| 393 |
-
});
|
| 394 |
-
|
| 395 |
-
// ---------- History (per-browser convenience only) ----------
|
| 396 |
-
|
| 397 |
-
function readHistory() {
|
| 398 |
-
try {
|
| 399 |
-
return JSON.parse(localStorage.getItem(HISTORY_KEY) || "[]");
|
| 400 |
-
} catch {
|
| 401 |
-
return [];
|
| 402 |
-
}
|
| 403 |
-
}
|
| 404 |
-
|
| 405 |
-
function writeHistory(items) {
|
| 406 |
-
try {
|
| 407 |
-
localStorage.setItem(HISTORY_KEY, JSON.stringify(items));
|
| 408 |
-
} catch {
|
| 409 |
-
// Storage is blocked; the list simply will not persist.
|
| 410 |
-
}
|
| 411 |
-
}
|
| 412 |
-
|
| 413 |
-
function rememberSong(job) {
|
| 414 |
-
const items = readHistory().filter((item) => item.id !== job.id);
|
| 415 |
-
items.unshift({ id: job.id, topic: job.topic, genre: job.genre });
|
| 416 |
-
writeHistory(items.slice(0, HISTORY_LIMIT));
|
| 417 |
-
renderHistory();
|
| 418 |
-
}
|
| 419 |
-
|
| 420 |
-
function renderHistory() {
|
| 421 |
-
const items = readHistory();
|
| 422 |
-
ui.historyCard.hidden = items.length === 0;
|
| 423 |
-
ui.history.replaceChildren(
|
| 424 |
-
...items.map((item) => {
|
| 425 |
-
const li = document.createElement("li");
|
| 426 |
-
const button = document.createElement("button");
|
| 427 |
-
button.type = "button";
|
| 428 |
-
const title = document.createElement("span");
|
| 429 |
-
title.className = "t";
|
| 430 |
-
title.textContent = item.topic;
|
| 431 |
-
const sub = document.createElement("span");
|
| 432 |
-
sub.className = "s";
|
| 433 |
-
sub.textContent = item.genre;
|
| 434 |
-
button.append(title, sub);
|
| 435 |
-
button.addEventListener("click", () => openHistoryItem(item.id));
|
| 436 |
-
li.append(button);
|
| 437 |
-
return li;
|
| 438 |
-
}),
|
| 439 |
-
);
|
| 440 |
-
}
|
| 441 |
-
|
| 442 |
-
async function openHistoryItem(id) {
|
| 443 |
-
endActiveJob();
|
| 444 |
-
ui.resultCard.hidden = false;
|
| 445 |
-
try {
|
| 446 |
-
const response = await fetch(`/api/songs/${id}`);
|
| 447 |
-
if (response.status === 404) {
|
| 448 |
-
writeHistory(readHistory().filter((item) => item.id !== id));
|
| 449 |
-
renderHistory();
|
| 450 |
-
showFailure("This song expired on the server. Create it again to hear it.");
|
| 451 |
-
return;
|
| 452 |
-
}
|
| 453 |
-
if (!response.ok) throw new Error(await errorMessage(response));
|
| 454 |
-
const job = await response.json();
|
| 455 |
-
if (job.status === "done") renderSong(job);
|
| 456 |
-
} catch (error) {
|
| 457 |
-
showFailure(error.message);
|
| 458 |
-
}
|
| 459 |
-
ui.resultCard.scrollIntoView({ behavior: "smooth", block: "start" });
|
| 460 |
-
}
|
| 461 |
-
|
| 462 |
-
// ---------- Health ----------
|
| 463 |
-
|
| 464 |
-
async function checkHealth() {
|
| 465 |
-
try {
|
| 466 |
-
const response = await fetch("/api/health");
|
| 467 |
-
const data = await response.json();
|
| 468 |
-
const states = Object.values(data.models);
|
| 469 |
-
if (states.length && states.every((state) => state === "ready")) {
|
| 470 |
-
setHealth("ready", "Ready");
|
| 471 |
-
return;
|
| 472 |
-
}
|
| 473 |
-
if (states.includes("error")) {
|
| 474 |
-
setHealth("error", "Music model failed to load");
|
| 475 |
-
return;
|
| 476 |
-
}
|
| 477 |
-
setHealth("loading", "Loading music model…");
|
| 478 |
-
} catch {
|
| 479 |
-
setHealth("error", "Server unreachable");
|
| 480 |
-
}
|
| 481 |
-
setTimeout(checkHealth, 4000);
|
| 482 |
-
}
|
| 483 |
-
|
| 484 |
-
function setHealth(state, text) {
|
| 485 |
-
ui.health.dataset.state = state;
|
| 486 |
-
ui.health.textContent = text;
|
| 487 |
-
}
|
| 488 |
-
|
| 489 |
-
// ---------- Helpers ----------
|
| 490 |
-
|
| 491 |
-
function formatTime(totalSeconds) {
|
| 492 |
-
if (!Number.isFinite(totalSeconds)) return "0:00";
|
| 493 |
-
const seconds = Math.floor(totalSeconds);
|
| 494 |
-
const minutes = Math.floor(seconds / 60);
|
| 495 |
-
return `${minutes}:${String(seconds % 60).padStart(2, "0")}`;
|
| 496 |
-
}
|
| 497 |
-
|
| 498 |
-
function slug(text) {
|
| 499 |
-
return text.replace(/đ/g, "d").replace(/Đ/g, "D").toLowerCase().normalize("NFD")
|
| 500 |
-
.replace(/[̀-ͯ]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "song";
|
| 501 |
-
}
|
| 502 |
-
|
| 503 |
-
renderStyleChips();
|
| 504 |
-
renderHistory();
|
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+0,0 @@
|
|
| 1 |
-
<!doctype html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="utf-8" />
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
| 6 |
-
<title>Tune Studio</title>
|
| 7 |
-
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23a78bfa' d='M9 18V5l12-2v13'/%3E%3Ccircle cx='6' cy='18' r='3' fill='%23a78bfa'/%3E%3Ccircle cx='18' cy='16' r='3' fill='%23a78bfa'/%3E%3C/svg%3E" />
|
| 8 |
-
<link rel="stylesheet" href="/styles.css" />
|
| 9 |
-
</head>
|
| 10 |
-
<body>
|
| 11 |
-
<header class="topbar">
|
| 12 |
-
<div class="brand">
|
| 13 |
-
<span class="brand-mark" aria-hidden="true"></span>
|
| 14 |
-
<span>Tune Studio</span>
|
| 15 |
-
</div>
|
| 16 |
-
<div class="topbar-right">
|
| 17 |
-
<div id="health" class="pill" data-state="checking">Checking…</div>
|
| 18 |
-
<button id="open-settings" type="button" class="ghost small">Settings</button>
|
| 19 |
-
</div>
|
| 20 |
-
</header>
|
| 21 |
-
|
| 22 |
-
<main class="layout">
|
| 23 |
-
<section class="card create" aria-labelledby="create-title">
|
| 24 |
-
<h1 id="create-title">Turn a topic into a song</h1>
|
| 25 |
-
<p class="muted">Describe what your song is about. We write the lyrics and sing them for you.</p>
|
| 26 |
-
|
| 27 |
-
<form id="song-form" novalidate>
|
| 28 |
-
<label class="field">
|
| 29 |
-
<span class="label-row">
|
| 30 |
-
<span>Topic</span>
|
| 31 |
-
<span id="topic-count" class="muted small">0/300</span>
|
| 32 |
-
</span>
|
| 33 |
-
<textarea id="topic" name="topic" rows="3" maxlength="300" required
|
| 34 |
-
placeholder="e.g. a rainy night in the city, missing someone who left"></textarea>
|
| 35 |
-
</label>
|
| 36 |
-
|
| 37 |
-
<div class="field">
|
| 38 |
-
<span class="label-row"><span>Style</span></span>
|
| 39 |
-
<div id="style-chips" class="chips" role="radiogroup" aria-label="Music style"></div>
|
| 40 |
-
<details class="custom-style">
|
| 41 |
-
<summary>Describe your own style</summary>
|
| 42 |
-
<input id="custom-style" type="text" maxlength="200"
|
| 43 |
-
placeholder="e.g. jazz piano, smooth male vocal" />
|
| 44 |
-
</details>
|
| 45 |
-
</div>
|
| 46 |
-
|
| 47 |
-
<button id="submit" type="submit" class="primary">
|
| 48 |
-
<span>Create song</span>
|
| 49 |
-
<kbd>Ctrl ↵</kbd>
|
| 50 |
-
</button>
|
| 51 |
-
<p id="form-hint" class="muted small">Uses your Hugging Face token. Songs take about 2 to 5 minutes.</p>
|
| 52 |
-
<p id="form-error" class="error" role="alert" hidden></p>
|
| 53 |
-
</form>
|
| 54 |
-
</section>
|
| 55 |
-
|
| 56 |
-
<section class="card result" aria-live="polite" aria-labelledby="result-title" id="result-card" hidden>
|
| 57 |
-
<h2 id="result-title">Your song</h2>
|
| 58 |
-
|
| 59 |
-
<div id="progress" class="progress" hidden>
|
| 60 |
-
<ol class="steps">
|
| 61 |
-
<li data-step="writing_lyrics"><span class="dot"></span>Writing lyrics</li>
|
| 62 |
-
<li data-step="composing"><span class="dot"></span>Singing and producing</li>
|
| 63 |
-
<li data-step="done"><span class="dot"></span>Done</li>
|
| 64 |
-
</ol>
|
| 65 |
-
<p class="muted small" id="progress-text">Queued…</p>
|
| 66 |
-
<p class="muted small mono" id="elapsed"></p>
|
| 67 |
-
</div>
|
| 68 |
-
|
| 69 |
-
<div id="failure" class="error" role="alert" hidden></div>
|
| 70 |
-
|
| 71 |
-
<article id="song" class="song" hidden>
|
| 72 |
-
<h3 id="song-title"></h3>
|
| 73 |
-
<div id="song-meta" class="meta"></div>
|
| 74 |
-
|
| 75 |
-
<div class="player">
|
| 76 |
-
<button id="play" type="button" class="icon-btn" aria-label="Play">
|
| 77 |
-
<svg viewBox="0 0 24 24" aria-hidden="true"><path id="play-icon" d="M8 5v14l11-7z" fill="currentColor"/></svg>
|
| 78 |
-
</button>
|
| 79 |
-
<div class="seek">
|
| 80 |
-
<input id="seekbar" type="range" min="0" max="1000" value="0" aria-label="Seek" />
|
| 81 |
-
<div class="times mono small"><span id="cur">0:00</span><span id="dur">0:00</span></div>
|
| 82 |
-
</div>
|
| 83 |
-
<a id="download" class="icon-btn" href="#" download aria-label="Download MP3">
|
| 84 |
-
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3v12m0 0l-4-4m4 4l4-4M5 21h14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
| 85 |
-
</a>
|
| 86 |
-
</div>
|
| 87 |
-
|
| 88 |
-
<div class="lyrics-head">
|
| 89 |
-
<span class="label-row"><span>Lyrics</span></span>
|
| 90 |
-
<button id="copy" type="button" class="ghost small">Copy</button>
|
| 91 |
-
</div>
|
| 92 |
-
<pre id="lyrics" class="lyrics"></pre>
|
| 93 |
-
</article>
|
| 94 |
-
</section>
|
| 95 |
-
|
| 96 |
-
<section class="card history" aria-labelledby="history-title" id="history-card" hidden>
|
| 97 |
-
<h2 id="history-title">Recent songs</h2>
|
| 98 |
-
<ul id="history" class="history-list"></ul>
|
| 99 |
-
</section>
|
| 100 |
-
</main>
|
| 101 |
-
|
| 102 |
-
<dialog id="settings" aria-labelledby="settings-title">
|
| 103 |
-
<form method="dialog" class="settings-form" id="settings-form">
|
| 104 |
-
<div class="dialog-head">
|
| 105 |
-
<h2 id="settings-title">Settings</h2>
|
| 106 |
-
<button type="submit" class="ghost small" value="close" aria-label="Close">✕</button>
|
| 107 |
-
</div>
|
| 108 |
-
|
| 109 |
-
<label class="field">
|
| 110 |
-
<span class="label-row"><span>Hugging Face token</span></span>
|
| 111 |
-
<div class="token-row">
|
| 112 |
-
<input id="token" type="password" autocomplete="off" spellcheck="false"
|
| 113 |
-
placeholder="hf_…" />
|
| 114 |
-
<button id="toggle-token" type="button" class="ghost small">Show</button>
|
| 115 |
-
</div>
|
| 116 |
-
</label>
|
| 117 |
-
|
| 118 |
-
<p class="muted small">
|
| 119 |
-
Lyrics are written by DeepSeek V4.1 Flash through Hugging Face Inference Providers, billed to your account.
|
| 120 |
-
Your token is stored only in this browser and sent only to Hugging Face and this app's server.
|
| 121 |
-
<a href="https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained"
|
| 122 |
-
target="_blank" rel="noopener">Create a token with Inference permission</a>.
|
| 123 |
-
</p>
|
| 124 |
-
|
| 125 |
-
<p id="settings-status" class="small" role="status"></p>
|
| 126 |
-
|
| 127 |
-
<div class="dialog-actions">
|
| 128 |
-
<button id="remove-token" type="button" class="ghost">Remove token</button>
|
| 129 |
-
<button id="save-token" type="button" class="primary compact">Save and verify</button>
|
| 130 |
-
</div>
|
| 131 |
-
</form>
|
| 132 |
-
</dialog>
|
| 133 |
-
|
| 134 |
-
<script src="/app.js" type="module"></script>
|
| 135 |
-
</body>
|
| 136 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/styles.css
DELETED
|
@@ -1,316 +0,0 @@
|
|
| 1 |
-
:root {
|
| 2 |
-
--bg: #0d0d14;
|
| 3 |
-
--panel: #161623;
|
| 4 |
-
--panel-2: #1e1e30;
|
| 5 |
-
--line: #2a2a40;
|
| 6 |
-
--text: #ecebf7;
|
| 7 |
-
--muted: #8d8ca8;
|
| 8 |
-
--accent: #a78bfa;
|
| 9 |
-
--accent-2: #60a5fa;
|
| 10 |
-
--ok: #34d399;
|
| 11 |
-
--warn: #fbbf24;
|
| 12 |
-
--danger: #f87171;
|
| 13 |
-
--radius: 16px;
|
| 14 |
-
--gutter: 16px;
|
| 15 |
-
color-scheme: dark;
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
* { box-sizing: border-box; }
|
| 19 |
-
|
| 20 |
-
body {
|
| 21 |
-
margin: 0;
|
| 22 |
-
min-height: 100vh;
|
| 23 |
-
background:
|
| 24 |
-
radial-gradient(900px 500px at 10% -10%, rgba(167, 139, 250, 0.16), transparent 60%),
|
| 25 |
-
radial-gradient(800px 500px at 110% 0%, rgba(96, 165, 250, 0.12), transparent 55%),
|
| 26 |
-
var(--bg);
|
| 27 |
-
color: var(--text);
|
| 28 |
-
font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
h1, h2, h3 { margin: 0; line-height: 1.25; }
|
| 32 |
-
h1 { font-size: 1.6rem; margin-bottom: 6px; }
|
| 33 |
-
h2 { font-size: 1.05rem; margin-bottom: 14px; }
|
| 34 |
-
h3 { font-size: 1.25rem; margin-bottom: 6px; }
|
| 35 |
-
p { margin: 0; }
|
| 36 |
-
button, input, textarea { font: inherit; color: inherit; }
|
| 37 |
-
[hidden] { display: none !important; }
|
| 38 |
-
|
| 39 |
-
.muted { color: var(--muted); }
|
| 40 |
-
.small { font-size: 0.85rem; }
|
| 41 |
-
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
|
| 42 |
-
.error { color: var(--danger); margin-top: 10px; }
|
| 43 |
-
|
| 44 |
-
/* Top bar */
|
| 45 |
-
.topbar {
|
| 46 |
-
display: flex;
|
| 47 |
-
align-items: center;
|
| 48 |
-
justify-content: space-between;
|
| 49 |
-
gap: 12px;
|
| 50 |
-
padding: 16px var(--gutter);
|
| 51 |
-
max-width: 720px;
|
| 52 |
-
margin: 0 auto;
|
| 53 |
-
}
|
| 54 |
-
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.02em; }
|
| 55 |
-
.brand-mark {
|
| 56 |
-
width: 26px; height: 26px; border-radius: 8px;
|
| 57 |
-
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
| 58 |
-
box-shadow: 0 0 24px rgba(167, 139, 250, 0.45);
|
| 59 |
-
}
|
| 60 |
-
.pill {
|
| 61 |
-
font-size: 0.82rem;
|
| 62 |
-
padding: 6px 12px;
|
| 63 |
-
border-radius: 999px;
|
| 64 |
-
border: 1px solid var(--line);
|
| 65 |
-
background: var(--panel);
|
| 66 |
-
color: var(--muted);
|
| 67 |
-
}
|
| 68 |
-
.pill[data-state="ready"] { color: var(--ok); border-color: rgba(52, 211, 153, 0.35); }
|
| 69 |
-
.pill[data-state="loading"] { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
|
| 70 |
-
.pill[data-state="error"] { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
|
| 71 |
-
|
| 72 |
-
/* Layout */
|
| 73 |
-
.layout {
|
| 74 |
-
display: grid;
|
| 75 |
-
grid-template-columns: minmax(0, 1fr);
|
| 76 |
-
gap: 20px;
|
| 77 |
-
max-width: 720px;
|
| 78 |
-
margin: 0 auto;
|
| 79 |
-
padding: 0 var(--gutter) 48px;
|
| 80 |
-
align-items: start;
|
| 81 |
-
}
|
| 82 |
-
.history { grid-column: 1 / -1; }
|
| 83 |
-
|
| 84 |
-
.card {
|
| 85 |
-
background: linear-gradient(180deg, var(--panel), #12121c);
|
| 86 |
-
border: 1px solid var(--line);
|
| 87 |
-
border-radius: var(--radius);
|
| 88 |
-
padding: 24px;
|
| 89 |
-
min-width: 0;
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/* Form */
|
| 93 |
-
form { display: grid; gap: 18px; margin-top: 18px; }
|
| 94 |
-
.field { display: grid; gap: 8px; margin: 0; }
|
| 95 |
-
.label-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: 0.92rem; }
|
| 96 |
-
|
| 97 |
-
textarea, input[type="text"], input[type="number"] {
|
| 98 |
-
width: 100%;
|
| 99 |
-
background: var(--panel-2);
|
| 100 |
-
border: 1px solid var(--line);
|
| 101 |
-
border-radius: 12px;
|
| 102 |
-
padding: 11px 13px;
|
| 103 |
-
outline: none;
|
| 104 |
-
resize: vertical;
|
| 105 |
-
transition: border-color 0.15s, box-shadow 0.15s;
|
| 106 |
-
}
|
| 107 |
-
textarea:focus, input:focus-visible {
|
| 108 |
-
border-color: var(--accent);
|
| 109 |
-
box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
|
| 110 |
-
}
|
| 111 |
-
|
| 112 |
-
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
|
| 113 |
-
.chip {
|
| 114 |
-
border: 1px solid var(--line);
|
| 115 |
-
background: var(--panel-2);
|
| 116 |
-
color: var(--muted);
|
| 117 |
-
padding: 6px 12px;
|
| 118 |
-
border-radius: 999px;
|
| 119 |
-
cursor: pointer;
|
| 120 |
-
font-size: 0.86rem;
|
| 121 |
-
transition: all 0.15s;
|
| 122 |
-
}
|
| 123 |
-
.chip:hover { color: var(--text); border-color: #3d3d5c; }
|
| 124 |
-
.chip[aria-checked="true"] {
|
| 125 |
-
color: #0d0d14;
|
| 126 |
-
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
| 127 |
-
border-color: transparent;
|
| 128 |
-
font-weight: 600;
|
| 129 |
-
}
|
| 130 |
-
|
| 131 |
-
.segmented {
|
| 132 |
-
display: grid;
|
| 133 |
-
grid-auto-flow: column;
|
| 134 |
-
grid-auto-columns: 1fr;
|
| 135 |
-
gap: 4px;
|
| 136 |
-
padding: 4px;
|
| 137 |
-
background: var(--panel-2);
|
| 138 |
-
border: 1px solid var(--line);
|
| 139 |
-
border-radius: 12px;
|
| 140 |
-
}
|
| 141 |
-
.segmented label { position: relative; }
|
| 142 |
-
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
|
| 143 |
-
.segmented span {
|
| 144 |
-
display: block;
|
| 145 |
-
text-align: center;
|
| 146 |
-
padding: 8px 6px;
|
| 147 |
-
border-radius: 9px;
|
| 148 |
-
color: var(--muted);
|
| 149 |
-
cursor: pointer;
|
| 150 |
-
font-size: 0.9rem;
|
| 151 |
-
white-space: nowrap;
|
| 152 |
-
}
|
| 153 |
-
.segmented input:checked + span { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
|
| 154 |
-
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
|
| 155 |
-
|
| 156 |
-
.advanced summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
|
| 157 |
-
.advanced .field { margin-top: 12px; }
|
| 158 |
-
|
| 159 |
-
.primary {
|
| 160 |
-
display: flex;
|
| 161 |
-
justify-content: space-between;
|
| 162 |
-
align-items: center;
|
| 163 |
-
width: 100%;
|
| 164 |
-
border: 0;
|
| 165 |
-
border-radius: 14px;
|
| 166 |
-
padding: 14px 18px;
|
| 167 |
-
font-weight: 700;
|
| 168 |
-
font-size: 1rem;
|
| 169 |
-
color: #0d0d14;
|
| 170 |
-
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
| 171 |
-
cursor: pointer;
|
| 172 |
-
box-shadow: 0 10px 30px -12px rgba(167, 139, 250, 0.7);
|
| 173 |
-
transition: transform 0.1s, opacity 0.15s;
|
| 174 |
-
}
|
| 175 |
-
.primary:hover { transform: translateY(-1px); }
|
| 176 |
-
.primary:disabled { opacity: 0.55; cursor: progress; transform: none; }
|
| 177 |
-
kbd {
|
| 178 |
-
font: 600 0.75rem ui-monospace, Consolas, monospace;
|
| 179 |
-
padding: 3px 7px;
|
| 180 |
-
border-radius: 6px;
|
| 181 |
-
background: rgba(13, 13, 20, 0.18);
|
| 182 |
-
}
|
| 183 |
-
|
| 184 |
-
.ghost {
|
| 185 |
-
border: 1px solid var(--line);
|
| 186 |
-
background: transparent;
|
| 187 |
-
color: var(--muted);
|
| 188 |
-
padding: 6px 12px;
|
| 189 |
-
border-radius: 10px;
|
| 190 |
-
cursor: pointer;
|
| 191 |
-
}
|
| 192 |
-
.ghost:hover { color: var(--text); border-color: #3d3d5c; }
|
| 193 |
-
.small.ghost { font-size: 0.82rem; }
|
| 194 |
-
|
| 195 |
-
/* Result */
|
| 196 |
-
.empty {
|
| 197 |
-
display: grid;
|
| 198 |
-
justify-items: center;
|
| 199 |
-
gap: 14px;
|
| 200 |
-
text-align: center;
|
| 201 |
-
padding: 40px 12px;
|
| 202 |
-
color: var(--muted);
|
| 203 |
-
}
|
| 204 |
-
.empty-art {
|
| 205 |
-
width: 84px; height: 84px; border-radius: 50%;
|
| 206 |
-
background:
|
| 207 |
-
radial-gradient(circle at 50% 50%, var(--bg) 0 14px, transparent 15px),
|
| 208 |
-
repeating-radial-gradient(circle at 50% 50%, #23233a 0 3px, #15151f 3px 6px);
|
| 209 |
-
border: 1px solid var(--line);
|
| 210 |
-
}
|
| 211 |
-
|
| 212 |
-
.progress { display: grid; gap: 10px; padding: 8px 0 4px; }
|
| 213 |
-
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
|
| 214 |
-
.steps li {
|
| 215 |
-
display: flex; align-items: center; gap: 8px;
|
| 216 |
-
font-size: 0.88rem; color: var(--muted);
|
| 217 |
-
padding: 10px 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
|
| 218 |
-
}
|
| 219 |
-
.steps .dot { width: 9px; height: 9px; border-radius: 50%; background: #3a3a55; flex: none; }
|
| 220 |
-
.steps li[data-active="true"] { color: var(--text); border-color: var(--accent); }
|
| 221 |
-
.steps li[data-active="true"] .dot { background: var(--warn); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2); animation: pulse 1.2s infinite; }
|
| 222 |
-
.steps li[data-done="true"] { color: var(--ok); }
|
| 223 |
-
.steps li[data-done="true"] .dot { background: var(--ok); }
|
| 224 |
-
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(251, 191, 36, 0); } }
|
| 225 |
-
|
| 226 |
-
.song { display: grid; gap: 14px; margin-top: 18px; }
|
| 227 |
-
.meta { display: flex; flex-wrap: wrap; gap: 6px; }
|
| 228 |
-
.meta span {
|
| 229 |
-
font-size: 0.8rem; color: var(--muted);
|
| 230 |
-
padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
.player {
|
| 234 |
-
display: grid;
|
| 235 |
-
grid-template-columns: auto 1fr auto;
|
| 236 |
-
align-items: center;
|
| 237 |
-
gap: 14px;
|
| 238 |
-
padding: 14px;
|
| 239 |
-
border-radius: 14px;
|
| 240 |
-
background: var(--panel-2);
|
| 241 |
-
border: 1px solid var(--line);
|
| 242 |
-
}
|
| 243 |
-
.icon-btn {
|
| 244 |
-
width: 46px; height: 46px; display: grid; place-items: center;
|
| 245 |
-
border-radius: 50%; border: 0; cursor: pointer;
|
| 246 |
-
background: linear-gradient(135deg, var(--accent), var(--accent-2));
|
| 247 |
-
color: #0d0d14;
|
| 248 |
-
text-decoration: none;
|
| 249 |
-
}
|
| 250 |
-
.icon-btn svg { width: 20px; height: 20px; }
|
| 251 |
-
.icon-btn:disabled { opacity: 0.5; cursor: default; }
|
| 252 |
-
.seek { display: grid; gap: 4px; min-width: 0; }
|
| 253 |
-
.seek input[type="range"] { width: 100%; accent-color: var(--accent); }
|
| 254 |
-
.times { display: flex; justify-content: space-between; color: var(--muted); }
|
| 255 |
-
|
| 256 |
-
.lyrics-head { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
|
| 257 |
-
.lyrics {
|
| 258 |
-
margin: 0;
|
| 259 |
-
white-space: pre-wrap;
|
| 260 |
-
max-height: 360px;
|
| 261 |
-
overflow: auto;
|
| 262 |
-
padding: 16px;
|
| 263 |
-
border-radius: 12px;
|
| 264 |
-
background: var(--panel-2);
|
| 265 |
-
border: 1px solid var(--line);
|
| 266 |
-
font: 0.92rem/1.7 "Inter", system-ui, sans-serif;
|
| 267 |
-
}
|
| 268 |
-
|
| 269 |
-
/* History */
|
| 270 |
-
.history-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
|
| 271 |
-
.history-list button {
|
| 272 |
-
width: 100%; text-align: left; cursor: pointer;
|
| 273 |
-
padding: 12px 14px; border-radius: 12px;
|
| 274 |
-
background: var(--panel-2); border: 1px solid var(--line);
|
| 275 |
-
}
|
| 276 |
-
.history-list button:hover { border-color: #3d3d5c; }
|
| 277 |
-
.history-list .t { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 278 |
-
.history-list .s { display: block; color: var(--muted); font-size: 0.82rem; }
|
| 279 |
-
|
| 280 |
-
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
| 281 |
-
|
| 282 |
-
.topbar-right { display: flex; align-items: center; gap: 10px; }
|
| 283 |
-
.custom-style { margin-top: 2px; }
|
| 284 |
-
.custom-style summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
|
| 285 |
-
.custom-style input { margin-top: 8px; }
|
| 286 |
-
.primary.compact { width: auto; padding: 10px 16px; font-size: 0.92rem; justify-content: center; }
|
| 287 |
-
.ok-text { color: var(--ok); }
|
| 288 |
-
.warn-text { color: var(--warn); }
|
| 289 |
-
|
| 290 |
-
/* Settings dialog */
|
| 291 |
-
dialog {
|
| 292 |
-
width: min(480px, calc(100vw - 32px));
|
| 293 |
-
padding: 0;
|
| 294 |
-
border: 1px solid var(--line);
|
| 295 |
-
border-radius: var(--radius);
|
| 296 |
-
background: var(--panel);
|
| 297 |
-
color: var(--text);
|
| 298 |
-
box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7);
|
| 299 |
-
}
|
| 300 |
-
dialog::backdrop { background: rgba(5, 5, 10, 0.6); }
|
| 301 |
-
.settings-form { display: grid; gap: 16px; padding: 22px; margin: 0; }
|
| 302 |
-
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
|
| 303 |
-
.dialog-head h2 { margin: 0; }
|
| 304 |
-
.token-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
|
| 305 |
-
.settings-form a { color: var(--accent); }
|
| 306 |
-
.dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
| 307 |
-
|
| 308 |
-
/* Phones: single column, 16px gutters, no horizontal scroll */
|
| 309 |
-
@media (max-width: 480px) {
|
| 310 |
-
.card { padding: 18px; }
|
| 311 |
-
.steps { grid-template-columns: 1fr; }
|
| 312 |
-
.segmented span { font-size: 0.82rem; padding: 8px 4px; }
|
| 313 |
-
.player { grid-template-columns: auto 1fr; }
|
| 314 |
-
.player #download { grid-column: 1 / -1; justify-self: start; }
|
| 315 |
-
.primary kbd { display: none; }
|
| 316 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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