Spaces:
Running
Running
Download app.py from JacobLinCool/internal-model-p: direct link, hf CLI and curl.
- Browser
- Download file 3.04 kB
-
https://huggingface.co/spaces/JacobLinCool/internal-model-p/resolve/main/app.py
- Command line
-
hf download hf://spaces/JacobLinCool/internal-model-p/app.py
-
curl -L -o app.py https://huggingface.co/spaces/JacobLinCool/internal-model-p/resolve/main/app.py
3.04 kB
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| from tempfile import TemporaryDirectory | |
| import gradio as gr | |
| from gradio.processing_utils import get_upload_folder, save_file_to_cache | |
| import torch | |
| from pipeline import AudioInputError, generate_package | |
| torch.set_num_threads(min(4, os.cpu_count() or 1)) | |
| ROOT = Path(__file__).resolve().parent | |
| def run(audio, title, artist, seed, bpm, downbeat): | |
| if audio is None: | |
| raise gr.Error("Upload audio or use the synthetic demo track.") | |
| if seed is None: | |
| raise gr.Error("Enter an integer seed.") | |
| try: | |
| with TemporaryDirectory(prefix="model-p-") as directory: | |
| osz, tja, counts = generate_package( | |
| Path(audio), Path(directory), title=title or "Generated taiko chart", artist=artist or "", | |
| seed=seed, bpm=bpm, downbeat_ms=downbeat or 0, | |
| ) | |
| downloads = [save_file_to_cache(path, get_upload_folder()) for path in (osz, tja)] | |
| note_counts = " · ".join(f"{course}: {count:,} hits" for course, count in counts.items()) | |
| return note_counts, *downloads | |
| except AudioInputError as exc: | |
| raise gr.Error(str(exc)) from exc | |
| with gr.Blocks(title="Model P · Taiko chart generator", analytics_enabled=False, delete_cache=(300, 3600)) as demo: | |
| gr.Markdown( | |
| "# Model P\n" | |
| "Generate an Oni and Inner Oni chartset from audio. " | |
| "Download an osu!taiko package or a TJA package with both courses. " | |
| "The default audio is a synthetic drum loop." | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| audio = gr.Audio( | |
| value=str(ROOT / "assets/demo.mp3"), sources=["upload"], type="filepath", | |
| label="Audio", | |
| ) | |
| with gr.Accordion("Chart details and timing", open=False): | |
| with gr.Row(): | |
| title = gr.Textbox(label="Track title") | |
| artist = gr.Textbox(label="Artist") | |
| with gr.Row(): | |
| seed = gr.Number(label="Seed", value=0, precision=0) | |
| bpm = gr.Number(label="BPM (optional)", minimum=60, maximum=320) | |
| downbeat = gr.Number(label="First downbeat (ms)", value=0, minimum=0) | |
| gr.Markdown("Leave BPM blank for automatic timing. If you enter a BPM, the grid uses a constant 4/4 meter.") | |
| generate = gr.Button("Generate charts", variant="primary") | |
| with gr.Column(): | |
| result = gr.Markdown("Upload audio between 8 seconds and 3 minutes.") | |
| osz = gr.File(label="osu!taiko · OSZ") | |
| tja = gr.File(label="Taiko simulators · TJA and audio") | |
| generate.click(run, [audio, title, artist, seed, bpm, downbeat], [result, osz, tja], api_name="generate") | |
| gr.Markdown("Model P was trained on osu!taiko. TJA uses the same generated hit positions and maps Inner Oni to Edit.") | |
| if __name__ == "__main__": | |
| demo.queue(max_size=8, default_concurrency_limit=1).launch(max_file_size="24mb") | |