Spaces:
Runtime error
Runtime error
Updating Docstrings for MCP
Browse files- app.py +93 -3
- modules/user_history.py +37 -6
app.py
CHANGED
|
@@ -80,22 +80,48 @@ class FileCleaner:
|
|
| 80 |
#file_cleaner = FileCleaner()
|
| 81 |
|
| 82 |
def toggle_audio_src(choice):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if choice == "mic":
|
| 84 |
return gr.update(source="microphone", value=None, label="Microphone")
|
| 85 |
else:
|
| 86 |
return gr.update(source="upload", value=None, label="File")
|
| 87 |
|
| 88 |
def get_waveform(*args, **kwargs):
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
be = time.time()
|
| 91 |
with warnings.catch_warnings():
|
| 92 |
warnings.simplefilter('ignore')
|
| 93 |
out = gr.make_waveform(*args, **kwargs)
|
| 94 |
print("Make a video took", time.time() - be)
|
| 95 |
return out
|
| 96 |
-
|
| 97 |
|
| 98 |
def load_model(version, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
global MODEL, MODELS, UNLOAD_MODEL
|
| 100 |
print("Loading model", version)
|
| 101 |
|
|
@@ -131,6 +157,12 @@ def get_melody(melody_filepath):
|
|
| 131 |
return melody
|
| 132 |
|
| 133 |
def git_tag():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
try:
|
| 135 |
return subprocess.check_output([git, "describe", "--tags"], shell=False, encoding='utf8').strip()
|
| 136 |
except Exception:
|
|
@@ -143,12 +175,36 @@ def git_tag():
|
|
| 143 |
return "<none>"
|
| 144 |
|
| 145 |
def load_background_filepath(video_orientation):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
if video_orientation == "Landscape":
|
| 147 |
return "./assets/background.png"
|
| 148 |
else:
|
| 149 |
return "./assets/background_portrait.png"
|
| 150 |
|
| 151 |
-
def load_melody_filepath(melody_filepath, title, assigned_model,topp, temperature, cfg_coef, segment_length = 30):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# get melody filename
|
| 153 |
#$Union[str, os.PathLike]
|
| 154 |
symbols = ['_', '.', '-']
|
|
@@ -184,6 +240,40 @@ def load_melody_filepath(melody_filepath, title, assigned_model,topp, temperatur
|
|
| 184 |
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)
|
| 185 |
|
| 186 |
def predict(model, text, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, 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, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
|
| 188 |
output_segments = None
|
| 189 |
melody_name = "Not Used"
|
|
|
|
| 80 |
#file_cleaner = FileCleaner()
|
| 81 |
|
| 82 |
def toggle_audio_src(choice):
|
| 83 |
+
"""
|
| 84 |
+
Toggle the audio input source between microphone and file upload.
|
| 85 |
+
|
| 86 |
+
Args:
|
| 87 |
+
choice (str): The selected audio source, either 'mic' or 'upload'.
|
| 88 |
+
|
| 89 |
+
Returns:
|
| 90 |
+
gr.Update: Gradio update object to change the audio input component.
|
| 91 |
+
"""
|
| 92 |
if choice == "mic":
|
| 93 |
return gr.update(source="microphone", value=None, label="Microphone")
|
| 94 |
else:
|
| 95 |
return gr.update(source="upload", value=None, label="File")
|
| 96 |
|
| 97 |
def get_waveform(*args, **kwargs):
|
| 98 |
+
"""
|
| 99 |
+
Generate a waveform video for the given audio input.
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
melody_filepath (str): Path to the melody audio file.
|
| 103 |
+
|
| 104 |
+
Returns:
|
| 105 |
+
tuple: (sample_rate, audio_data) loaded from the file.
|
| 106 |
+
"""
|
| 107 |
be = time.time()
|
| 108 |
with warnings.catch_warnings():
|
| 109 |
warnings.simplefilter('ignore')
|
| 110 |
out = gr.make_waveform(*args, **kwargs)
|
| 111 |
print("Make a video took", time.time() - be)
|
| 112 |
return out
|
|
|
|
| 113 |
|
| 114 |
def load_model(version, progress=gr.Progress(track_tqdm=True)):
|
| 115 |
+
"""
|
| 116 |
+
Load a MusicGen model by version name, optionally showing progress.
|
| 117 |
+
|
| 118 |
+
Args:
|
| 119 |
+
version (str): The model version to load.
|
| 120 |
+
progress (gr.Progress, optional): Gradio progress tracker.
|
| 121 |
+
|
| 122 |
+
Returns:
|
| 123 |
+
MusicGen: The loaded MusicGen model instance.
|
| 124 |
+
"""
|
| 125 |
global MODEL, MODELS, UNLOAD_MODEL
|
| 126 |
print("Loading model", version)
|
| 127 |
|
|
|
|
| 157 |
return melody
|
| 158 |
|
| 159 |
def git_tag():
|
| 160 |
+
"""
|
| 161 |
+
Get the current git tag or fallback to the first line of CHANGELOG.md if unavailable.
|
| 162 |
+
|
| 163 |
+
Returns:
|
| 164 |
+
str: The current git tag or '<none>' if not available.
|
| 165 |
+
"""
|
| 166 |
try:
|
| 167 |
return subprocess.check_output([git, "describe", "--tags"], shell=False, encoding='utf8').strip()
|
| 168 |
except Exception:
|
|
|
|
| 175 |
return "<none>"
|
| 176 |
|
| 177 |
def load_background_filepath(video_orientation):
|
| 178 |
+
"""
|
| 179 |
+
Get the background image path based on video orientation.
|
| 180 |
+
|
| 181 |
+
Args:
|
| 182 |
+
video_orientation (str): Either 'Landscape' or 'Portait'.
|
| 183 |
+
|
| 184 |
+
Returns:
|
| 185 |
+
str: Path to the background image file.
|
| 186 |
+
"""
|
| 187 |
if video_orientation == "Landscape":
|
| 188 |
return "./assets/background.png"
|
| 189 |
else:
|
| 190 |
return "./assets/background_portrait.png"
|
| 191 |
|
| 192 |
+
def load_melody_filepath(melody_filepath, title, assigned_model, topp, temperature, cfg_coef, segment_length = 30):
|
| 193 |
+
"""
|
| 194 |
+
Update melody-related UI fields based on the selected melody file and settings.
|
| 195 |
+
|
| 196 |
+
Args:
|
| 197 |
+
melody_filepath (str): Path to the melody file.
|
| 198 |
+
title (str): The song title.
|
| 199 |
+
assigned_model (str): The selected model name.
|
| 200 |
+
topp (float): Top-p sampling value.
|
| 201 |
+
temperature (float): Sampling temperature.
|
| 202 |
+
cfg_coef (float): Classifier-free guidance coefficient.
|
| 203 |
+
segment_length (int, optional): Segment length in seconds.
|
| 204 |
+
|
| 205 |
+
Returns:
|
| 206 |
+
tuple: Updated values for title, prompt_index, model, topp, temperature, cfg_coef, overlap.
|
| 207 |
+
"""
|
| 208 |
# get melody filename
|
| 209 |
#$Union[str, os.PathLike]
|
| 210 |
symbols = ['_', '.', '-']
|
|
|
|
| 240 |
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)
|
| 241 |
|
| 242 |
def predict(model, text, melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, 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, progress=gr.Progress(track_tqdm=True)):
|
| 243 |
+
"""
|
| 244 |
+
Generate music and video based on the provided parameters and model.
|
| 245 |
+
|
| 246 |
+
Args:
|
| 247 |
+
model (str): Model name to use for generation.
|
| 248 |
+
text (str): Prompt describing the music.
|
| 249 |
+
melody_filepath (str): Path to melody conditioning file. default to None.
|
| 250 |
+
duration (int): Total duration in seconds.
|
| 251 |
+
dimension (int): Audio stacking/concatenation dimension.
|
| 252 |
+
topk (int): Top-k sampling value.
|
| 253 |
+
topp (float): Top-p sampling value.
|
| 254 |
+
temperature (float): Sampling temperature.
|
| 255 |
+
cfg_coef (float): Classifier-free guidance coefficient.
|
| 256 |
+
background (str): Path to background image.
|
| 257 |
+
title (str): Song title.
|
| 258 |
+
settings_font (str): Path to font file.
|
| 259 |
+
settings_font_color (str): Font color for settings text.
|
| 260 |
+
seed (int): Random seed.
|
| 261 |
+
overlap (int, optional): Segment overlap in seconds.
|
| 262 |
+
prompt_index (int, optional): Melody segment index.
|
| 263 |
+
include_title (bool, optional): Whether to add title to video.
|
| 264 |
+
include_settings (bool, optional): Whether to add settings to video.
|
| 265 |
+
harmony_only (bool, optional): Whether to use harmony only.
|
| 266 |
+
profile (gr.OAuthProfile): User profile.
|
| 267 |
+
segment_length (int, optional): Segment length in seconds.
|
| 268 |
+
settings_font_size (int, optional): Font size for settings text.
|
| 269 |
+
settings_animate_waveform (bool, optional): Animate waveform in video.
|
| 270 |
+
video_orientation (str, optional): Video orientation.
|
| 271 |
+
excerpt_duration (float, optional): Excerpt duration for style conditioning.
|
| 272 |
+
progress (gr.Progress, optional): Gradio progress tracker.
|
| 273 |
+
|
| 274 |
+
Returns:
|
| 275 |
+
tuple: (waveform_video_path, wave_file_path, seed_used)
|
| 276 |
+
"""
|
| 277 |
global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
|
| 278 |
output_segments = None
|
| 279 |
melody_name = "Not Used"
|
modules/user_history.py
CHANGED
|
@@ -18,7 +18,7 @@ Useful links:
|
|
| 18 |
Update by Surn (Charles Fettinger)
|
| 19 |
"""
|
| 20 |
|
| 21 |
-
__version__ = "0.3.
|
| 22 |
|
| 23 |
import json
|
| 24 |
import os
|
|
@@ -46,9 +46,16 @@ from tqdm import tqdm
|
|
| 46 |
user_profile = gr.State(None)
|
| 47 |
|
| 48 |
def get_profile() -> gr.OAuthProfile | None:
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return user_profile
|
| 53 |
|
| 54 |
def setup(folder_path: str | Path | None = None, display_type: str = "image_path") -> None:
|
|
@@ -377,7 +384,15 @@ class _UserHistory(object):
|
|
| 377 |
|
| 378 |
|
| 379 |
def _fetch_user_history(profile: gr.OAuthProfile | None) -> List[Tuple[str, str]]:
|
| 380 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
# Cannot load history for logged out users
|
| 382 |
global user_profile
|
| 383 |
if profile is None:
|
|
@@ -407,7 +422,15 @@ def _fetch_user_history(profile: gr.OAuthProfile | None) -> List[Tuple[str, str]
|
|
| 407 |
|
| 408 |
|
| 409 |
def _export_user_history(profile: gr.OAuthProfile | None) -> Dict | None:
|
| 410 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
# Cannot load history for logged out users
|
| 412 |
if profile is None:
|
| 413 |
return None
|
|
@@ -428,7 +451,15 @@ def _export_user_history(profile: gr.OAuthProfile | None) -> Dict | None:
|
|
| 428 |
|
| 429 |
|
| 430 |
def _delete_user_history(profile: gr.OAuthProfile | None) -> None:
|
| 431 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
# Cannot load history for logged out users
|
| 433 |
if profile is None:
|
| 434 |
return
|
|
|
|
| 18 |
Update by Surn (Charles Fettinger)
|
| 19 |
"""
|
| 20 |
|
| 21 |
+
__version__ = "0.3.5"
|
| 22 |
|
| 23 |
import json
|
| 24 |
import os
|
|
|
|
| 46 |
user_profile = gr.State(None)
|
| 47 |
|
| 48 |
def get_profile() -> gr.OAuthProfile | None:
|
| 49 |
+
"""
|
| 50 |
+
Retrieve the currently logged-in user's profile.
|
| 51 |
+
|
| 52 |
+
This function returns the user profile stored in the global Gradio state.
|
| 53 |
+
If no user is logged in, it returns None.
|
| 54 |
|
| 55 |
+
Returns:
|
| 56 |
+
gr.OAuthProfile | None: The currently logged-in user's profile, or None if no user is logged in.
|
| 57 |
+
"""
|
| 58 |
+
global user_profile
|
| 59 |
return user_profile
|
| 60 |
|
| 61 |
def setup(folder_path: str | Path | None = None, display_type: str = "image_path") -> None:
|
|
|
|
| 384 |
|
| 385 |
|
| 386 |
def _fetch_user_history(profile: gr.OAuthProfile | None) -> List[Tuple[str, str]]:
|
| 387 |
+
"""
|
| 388 |
+
Return saved history for the given user.
|
| 389 |
+
|
| 390 |
+
Args:
|
| 391 |
+
profile (gr.OAuthProfile | None): The user profile.
|
| 392 |
+
|
| 393 |
+
Returns:
|
| 394 |
+
List[Tuple[str, str]]: A list of tuples, where each tuple contains the path to an image and its label.
|
| 395 |
+
"""
|
| 396 |
# Cannot load history for logged out users
|
| 397 |
global user_profile
|
| 398 |
if profile is None:
|
|
|
|
| 422 |
|
| 423 |
|
| 424 |
def _export_user_history(profile: gr.OAuthProfile | None) -> Dict | None:
|
| 425 |
+
"""
|
| 426 |
+
Zip all history for the given user, if it exists, and return it as a downloadable file.
|
| 427 |
+
|
| 428 |
+
Args:
|
| 429 |
+
profile (gr.OAuthProfile | None): The user profile.
|
| 430 |
+
|
| 431 |
+
Returns:
|
| 432 |
+
Dict | None: A Gradio update dictionary with the path to the zip file if successful, or None if the user is not logged in or user history is not initialized.
|
| 433 |
+
"""
|
| 434 |
# Cannot load history for logged out users
|
| 435 |
if profile is None:
|
| 436 |
return None
|
|
|
|
| 451 |
|
| 452 |
|
| 453 |
def _delete_user_history(profile: gr.OAuthProfile | None) -> None:
|
| 454 |
+
"""
|
| 455 |
+
Delete all history for the given user.
|
| 456 |
+
|
| 457 |
+
Args:
|
| 458 |
+
profile (gr.OAuthProfile | None): The user profile.
|
| 459 |
+
|
| 460 |
+
Returns:
|
| 461 |
+
None
|
| 462 |
+
"""
|
| 463 |
# Cannot load history for logged out users
|
| 464 |
if profile is None:
|
| 465 |
return
|