[Admin maintenance] Support new ZeroGPU hardware

#16
by multimodalart HF Staff - opened
Files changed (2) hide show
  1. app.py +12 -0
  2. requirements.txt +3 -4
app.py CHANGED
@@ -6,6 +6,7 @@ This source code is licensed under the license found in the
6
  LICENSE file in the root directory of this source tree.
7
  """
8
 
 
9
  from tempfile import NamedTemporaryFile
10
  import argparse
11
  import torch
@@ -250,6 +251,16 @@ def load_melody_filepath(melody_filepath, title, assigned_model, topp, temperatu
250
 
251
  return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=-1), gr.update(value=assigned_model, interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef), gr.update(maximum=MAX_OVERLAP)
252
 
 
 
 
 
 
 
 
 
 
 
253
  def predict(model, text, melody_filepath = None, duration=10, dimension=2, topk=200, topp=0, temperature=1.0, cfg_coef=4.0, background = None, title="UnlimitedMusicGen", settings_font="./assets/arial.ttf", settings_font_color = "#c87f05", seed=-1, overlap=1, prompt_index = 0, include_title = True, include_settings = True, harmony_only = False, profile = gr.OAuthProfile, segment_length = 30, settings_font_size=28, settings_animate_waveform=False, video_orientation="Landscape", excerpt_duration=3.5, return_history_json=False, progress=gr.Progress(track_tqdm=True)):
254
  """
255
  Generate music and video based on the provided parameters and model.
@@ -621,6 +632,7 @@ def fix_path(path: str) -> str:
621
  return "./" + path[index:].replace("\\", "/")
622
  return path
623
  # Add this wrapper function above the gr.api definitions
 
624
  def predict_simple(model: str, text: str, melody_filepath: str = None, duration: int = 10, dimension: int = 2, topk: int = 200, topp: float = 0.01, temperature: float = 1.0, cfg_coef: float = 4.0, background: str = "./assets/background.png", title: str = "UnlimitedMusicGen", settings_font: str = "./assets/arial.ttf", settings_font_color: str = "#c87f05", seed: int = -1, overlap: int = 1, prompt_index: int = -1, include_title: bool = True, include_settings: bool = True, harmony_only: bool = False, profile: str = "Satoshi Nakamoto", segment_length: int = 30, settings_font_size: int = 28, settings_animate_waveform: bool = False, video_orientation: str = "Landscape", return_history_json: bool = False) -> tp.List[tp.Tuple[str, str, str]]:
625
  """
626
  Generate music and video based on the provided parameters and model.
 
6
  LICENSE file in the root directory of this source tree.
7
  """
8
 
9
+ import spaces # noqa: F401 (must be imported before torch / any CUDA-touching module)
10
  from tempfile import NamedTemporaryFile
11
  import argparse
12
  import torch
 
251
 
252
  return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=-1), gr.update(value=assigned_model, interactive=True), gr.update(value=topp), gr.update(value=temperature), gr.update(value=cfg_coef), gr.update(maximum=MAX_OVERLAP)
253
 
254
+ def _gpu_duration(model=None, text=None, melody_filepath=None, duration=10, *args, **kwargs):
255
+ """Rough per-call GPU time estimate for the ZeroGPU scheduler, scaled with requested audio duration."""
256
+ try:
257
+ d = int(duration)
258
+ except (TypeError, ValueError):
259
+ d = 10
260
+ return max(30, min(d * 3 + 30, 300))
261
+
262
+
263
+ @spaces.GPU(duration=_gpu_duration)
264
  def predict(model, text, melody_filepath = None, duration=10, dimension=2, topk=200, topp=0, temperature=1.0, cfg_coef=4.0, background = None, title="UnlimitedMusicGen", settings_font="./assets/arial.ttf", settings_font_color = "#c87f05", seed=-1, overlap=1, prompt_index = 0, include_title = True, include_settings = True, harmony_only = False, profile = gr.OAuthProfile, segment_length = 30, settings_font_size=28, settings_animate_waveform=False, video_orientation="Landscape", excerpt_duration=3.5, return_history_json=False, progress=gr.Progress(track_tqdm=True)):
265
  """
266
  Generate music and video based on the provided parameters and model.
 
632
  return "./" + path[index:].replace("\\", "/")
633
  return path
634
  # Add this wrapper function above the gr.api definitions
635
+ @spaces.GPU(duration=_gpu_duration)
636
  def predict_simple(model: str, text: str, melody_filepath: str = None, duration: int = 10, dimension: int = 2, topk: int = 200, topp: float = 0.01, temperature: float = 1.0, cfg_coef: float = 4.0, background: str = "./assets/background.png", title: str = "UnlimitedMusicGen", settings_font: str = "./assets/arial.ttf", settings_font_color: str = "#c87f05", seed: int = -1, overlap: int = 1, prompt_index: int = -1, include_title: bool = True, include_settings: bool = True, harmony_only: bool = False, profile: str = "Satoshi Nakamoto", segment_length: int = 30, settings_font_size: int = 28, settings_animate_waveform: bool = False, video_orientation: str = "Landscape", return_history_json: bool = False) -> tp.List[tp.Tuple[str, str, str]]:
637
  """
638
  Generate music and video based on the provided parameters and model.
requirements.txt CHANGED
@@ -4,14 +4,13 @@ einops
4
  flashy>=0.0.1
5
  hydra-core>=1.1
6
  hydra_colorlog
7
- torch==2.6.0 --extra-index-url https://download.pytorch.org/whl/cu124
8
- torchaudio>=2.0.0,<2.6.2 --extra-index-url https://download.pytorch.org/whl/cu124
9
  soundfile
10
  huggingface_hub
11
  hf_xet
12
  tqdm
13
  transformers==4.43.4 # need Encodec there.
14
- xformers>=0.0.23 --index-url https://download.pytorch.org/whl/cu124
15
  demucs
16
  librosa==0.11.0
17
  soundfile
@@ -29,7 +28,7 @@ mutagen
29
  fastapi>=0.88.0
30
  pydantic
31
  typer
32
- torchvision>=0.21.0 --extra-index-url https://download.pytorch.org/whl/cu124
33
  #torchtext
34
  pesq
35
  pystoi
 
4
  flashy>=0.0.1
5
  hydra-core>=1.1
6
  hydra_colorlog
7
+ torchaudio
 
8
  soundfile
9
  huggingface_hub
10
  hf_xet
11
  tqdm
12
  transformers==4.43.4 # need Encodec there.
13
+ xformers
14
  demucs
15
  librosa==0.11.0
16
  soundfile
 
28
  fastapi>=0.88.0
29
  pydantic
30
  typer
31
+ torchvision
32
  #torchtext
33
  pesq
34
  pystoi