Spaces:
Running on Zero
Running on Zero
Keep the API focused on stable ZeroGPU transcription
Browse files- app.py +1 -49
- packages.txt +0 -1
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
"""The dedicated ZeroGPU transcription API for Score Studio."""
|
| 2 |
import logging
|
| 3 |
-
import json
|
| 4 |
import os
|
| 5 |
from pathlib import Path
|
| 6 |
-
import re
|
| 7 |
import shutil
|
| 8 |
import subprocess
|
| 9 |
import sys
|
|
@@ -14,7 +12,6 @@ import gradio as gr
|
|
| 14 |
import spaces
|
| 15 |
import torch
|
| 16 |
from transformers import AutoModel
|
| 17 |
-
from yt_dlp import YoutubeDL
|
| 18 |
|
| 19 |
MODEL_ID = "m-a-p/SheetSage2"
|
| 20 |
REVISION = "eab522a8168e8b8b8c4856bf8609cd86198f01fe"
|
|
@@ -117,46 +114,7 @@ def transcribe(audio, start, duration, melody_only, piano, progress=gr.Progress(
|
|
| 117 |
raise gr.Error("Conversion failed. Try a shorter excerpt. Details are available in the Space logs.")
|
| 118 |
|
| 119 |
|
| 120 |
-
|
| 121 |
-
match = re.fullmatch(r"https?://(?:www\.|m\.|music\.)?(?:youtube\.com/(?:watch\?v=|shorts/|live/)|youtu\.be/)([A-Za-z0-9_-]{11})(?:[?&/].*)?", str(url).strip())
|
| 122 |
-
if not match:
|
| 123 |
-
raise gr.Error("Enter a valid YouTube video link.")
|
| 124 |
-
video_id = match.group(1)
|
| 125 |
-
job = Path(tempfile.mkdtemp(prefix="youtube-", dir=ROOT))
|
| 126 |
-
try:
|
| 127 |
-
options = {
|
| 128 |
-
"quiet": True, "no_warnings": True, "noplaylist": True,
|
| 129 |
-
"socket_timeout": 15, "retries": 1, "extractor_retries": 1,
|
| 130 |
-
"fragment_retries": 1, "js_runtimes": {"node": {}},
|
| 131 |
-
"format": "bestaudio/best", "outtmpl": str(job / "audio.%(ext)s"),
|
| 132 |
-
"max_filesize": 100 * 1024 * 1024,
|
| 133 |
-
}
|
| 134 |
-
with YoutubeDL(options) as ydl:
|
| 135 |
-
source = "https://www.youtube.com/watch?v=" + video_id
|
| 136 |
-
info = ydl.extract_info(source, download=False)
|
| 137 |
-
duration = float(info.get("duration") or 0)
|
| 138 |
-
if info.get("is_live") or info.get("age_limit", 0) > 0:
|
| 139 |
-
raise gr.Error("Live or age-restricted videos are not supported.")
|
| 140 |
-
if not 5 <= duration <= 600:
|
| 141 |
-
raise gr.Error("Choose a video between five seconds and ten minutes.")
|
| 142 |
-
ydl.process_info(info)
|
| 143 |
-
audio = next((p for p in job.glob("audio.*") if p.is_file() and p.stat().st_size > 2048), None)
|
| 144 |
-
if not audio:
|
| 145 |
-
raise gr.Error("No audio could be read from this video.")
|
| 146 |
-
metadata = json.dumps({"title": info.get("title", "YouTube audio"),
|
| 147 |
-
"artist": info.get("uploader", ""), "duration": duration,
|
| 148 |
-
"thumbnail": f"https://i.ytimg.com/vi/{video_id}/hqdefault.jpg", "url": source})
|
| 149 |
-
return str(audio), metadata
|
| 150 |
-
except gr.Error:
|
| 151 |
-
raise
|
| 152 |
-
except Exception as exc:
|
| 153 |
-
logging.warning("YouTube API import failed: %s", str(exc)[:800])
|
| 154 |
-
if "not a bot" in str(exc).lower() or "confirm you" in str(exc).lower():
|
| 155 |
-
raise gr.Error("YouTube blocked this server address.")
|
| 156 |
-
raise gr.Error("The API could not download this YouTube audio.")
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
with gr.Blocks(title="Score Studio API", delete_cache=(3600, 86400)) as demo:
|
| 160 |
gr.Markdown("# Score Studio API\nThe ZeroGPU transcription engine for Score Studio. "
|
| 161 |
"Use the API below to turn audio into editable ABC, MIDI, PDF and piano audio.")
|
| 162 |
audio = gr.Audio(type="filepath", label="Audio", sources=["upload"])
|
|
@@ -174,12 +132,6 @@ with gr.Blocks(title="Score Studio API", delete_cache=(3600, 86400)) as demo:
|
|
| 174 |
run.click(transcribe, [audio, start, duration, melody, piano],
|
| 175 |
[status, gallery, pdf, preview, downloads, abc],
|
| 176 |
api_name="transcribe", concurrency_limit=1)
|
| 177 |
-
youtube_url = gr.Textbox(visible=False)
|
| 178 |
-
youtube_run = gr.Button(visible=False)
|
| 179 |
-
youtube_audio = gr.File(visible=False)
|
| 180 |
-
youtube_metadata = gr.Textbox(visible=False)
|
| 181 |
-
youtube_run.click(import_youtube, youtube_url, [youtube_audio, youtube_metadata],
|
| 182 |
-
api_name="youtube_import", concurrency_limit=2)
|
| 183 |
gr.Markdown("Powered by [SheetSage2](https://huggingface.co/m-a-p/SheetSage2), "
|
| 184 |
"CC BY-NC 4.0. Temporary files expire after 24 hours.")
|
| 185 |
|
|
|
|
| 1 |
"""The dedicated ZeroGPU transcription API for Score Studio."""
|
| 2 |
import logging
|
|
|
|
| 3 |
import os
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
import shutil
|
| 6 |
import subprocess
|
| 7 |
import sys
|
|
|
|
| 12 |
import spaces
|
| 13 |
import torch
|
| 14 |
from transformers import AutoModel
|
|
|
|
| 15 |
|
| 16 |
MODEL_ID = "m-a-p/SheetSage2"
|
| 17 |
REVISION = "eab522a8168e8b8b8c4856bf8609cd86198f01fe"
|
|
|
|
| 114 |
raise gr.Error("Conversion failed. Try a shorter excerpt. Details are available in the Space logs.")
|
| 115 |
|
| 116 |
|
| 117 |
+
with gr.Blocks(title="Score Studio API", delete_cache=(3600, 86400)) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
gr.Markdown("# Score Studio API\nThe ZeroGPU transcription engine for Score Studio. "
|
| 119 |
"Use the API below to turn audio into editable ABC, MIDI, PDF and piano audio.")
|
| 120 |
audio = gr.Audio(type="filepath", label="Audio", sources=["upload"])
|
|
|
|
| 132 |
run.click(transcribe, [audio, start, duration, melody, piano],
|
| 133 |
[status, gallery, pdf, preview, downloads, abc],
|
| 134 |
api_name="transcribe", concurrency_limit=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
gr.Markdown("Powered by [SheetSage2](https://huggingface.co/m-a-p/SheetSage2), "
|
| 136 |
"CC BY-NC 4.0. Temporary files expire after 24 hours.")
|
| 137 |
|
packages.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
ffmpeg
|
| 2 |
-
nodejs
|
| 3 |
libsndfile1
|
| 4 |
libglib2.0-0
|
| 5 |
libnss3
|
|
|
|
| 1 |
ffmpeg
|
|
|
|
| 2 |
libsndfile1
|
| 3 |
libglib2.0-0
|
| 4 |
libnss3
|
requirements.txt
CHANGED
|
@@ -10,4 +10,3 @@ pretty_midi==0.2.10
|
|
| 10 |
mido==1.3.3
|
| 11 |
setuptools==78.1.1
|
| 12 |
playwright==1.58.0
|
| 13 |
-
yt-dlp[default]==2026.8.19
|
|
|
|
| 10 |
mido==1.3.3
|
| 11 |
setuptools==78.1.1
|
| 12 |
playwright==1.58.0
|
|
|