Add Melody to MCP UI
Browse files- app.py +11 -11
- modules/constants.py +1 -1
app.py
CHANGED
|
@@ -33,11 +33,11 @@ from modules.file_utils import get_file_parts, get_filename_from_filepath, conve
|
|
| 33 |
# Added for MCP call
|
| 34 |
from smolagents.mcp_client import MCPClient
|
| 35 |
from modules.storage import upload_files_to_repo
|
| 36 |
-
from modules.constants import HF_REPO_ID, umg_mcp_server, TMPDIR, HF_API_TOKEN
|
| 37 |
|
| 38 |
MODEL = None
|
| 39 |
MODELS = None
|
| 40 |
-
IS_SHARED_SPACE = "Agents-MCP-Hackathon/UnlimitedMusicGen" in os.environ.get('SPACE_ID', '')
|
| 41 |
INTERRUPTED = False
|
| 42 |
UNLOAD_MODEL = False
|
| 43 |
MOVE_TO_CPU = False
|
|
@@ -318,9 +318,9 @@ def predict(
|
|
| 318 |
try:
|
| 319 |
# Upload files to Hugging Face Hub and get URLs
|
| 320 |
files_to_upload = []
|
| 321 |
-
if melody_filepath_arg and melody_filepath_arg not in ["None", ""]:
|
| 322 |
files_to_upload.append(melody_filepath_arg)
|
| 323 |
-
if background_image_arg and background_image_arg not in ["None", ""] and not background_image_arg.startswith("http"):
|
| 324 |
files_to_upload.append(background_image_arg)
|
| 325 |
|
| 326 |
uploaded_file_urls = {}
|
|
@@ -344,7 +344,7 @@ def predict(
|
|
| 344 |
|
| 345 |
upload_results = upload_files_to_repo(
|
| 346 |
files=files_to_upload,
|
| 347 |
-
repo_id=HF_REPO_ID,
|
| 348 |
folder_name=folder_name,
|
| 349 |
create_permalink=False # We need individual links
|
| 350 |
)
|
|
@@ -361,7 +361,7 @@ def predict(
|
|
| 361 |
if original_filename in link:
|
| 362 |
uploaded_file_urls[file_path] = link
|
| 363 |
break
|
| 364 |
-
else:
|
| 365 |
print(f"Warning: Expected a list from upload_files_to_repo, got {type(upload_results)}")
|
| 366 |
|
| 367 |
if melody_filepath_arg and melody_filepath_arg in uploaded_file_urls:
|
|
@@ -410,7 +410,7 @@ def predict(
|
|
| 410 |
tool_args = {
|
| 411 |
"model": model_name_arg,
|
| 412 |
"text": text_arg,
|
| 413 |
-
|
| 414 |
"duration": duration_arg,
|
| 415 |
"dimension": dimension_arg,
|
| 416 |
"topk": topk_arg,
|
|
@@ -426,7 +426,7 @@ def predict(
|
|
| 426 |
"prompt_index": prompt_index_arg,
|
| 427 |
"include_title": include_title_arg,
|
| 428 |
"include_settings": include_settings_arg,
|
| 429 |
-
|
| 430 |
"profile": profile_username_to_send,
|
| 431 |
"segment_length": segment_length_arg,
|
| 432 |
"settings_font_size": settings_font_size_arg,
|
|
@@ -463,9 +463,9 @@ def predict(
|
|
| 463 |
if not isinstance(seed_used, (int, float)): # Allow float for seed then cast later
|
| 464 |
raise gr.Error(f"MCP tool returned a non-numeric seed. Received type: {type(seed_used)}, value: {seed_used}")
|
| 465 |
|
| 466 |
-
if isinstance(waveform_video_path, str) and (waveform_video_path.startswith("http://"
|
| 467 |
waveform_video_path = str(download_and_save_file(waveform_video_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 468 |
-
if isinstance(wave_file_path, str) and (wave_file_path.startswith("http://"
|
| 469 |
wave_file_path = str(download_and_save_file(wave_file_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 470 |
|
| 471 |
return waveform_video_path, wave_file_path, int(seed_used)
|
|
@@ -650,7 +650,7 @@ def ui(**kwargs):
|
|
| 650 |
launch_kwargs['share'] = share
|
| 651 |
launch_kwargs['allowed_paths'] = ["assets", "./assets", "images", "./images", 'e:/TMP']
|
| 652 |
launch_kwargs['favicon_path'] = "./assets/favicon.ico"
|
| 653 |
-
launch_kwargs['mcp_server'] =
|
| 654 |
|
| 655 |
|
| 656 |
demo.queue(max_size=10, api_open=True).launch(**launch_kwargs)
|
|
|
|
| 33 |
# Added for MCP call
|
| 34 |
from smolagents.mcp_client import MCPClient
|
| 35 |
from modules.storage import upload_files_to_repo
|
| 36 |
+
from modules.constants import HF_REPO_ID, umg_mcp_server, TMPDIR, HF_API_TOKEN, IS_SHARED_SPACE
|
| 37 |
|
| 38 |
MODEL = None
|
| 39 |
MODELS = None
|
| 40 |
+
#IS_SHARED_SPACE = "Agents-MCP-Hackathon/UnlimitedMusicGen" in os.environ.get('SPACE_ID', '')
|
| 41 |
INTERRUPTED = False
|
| 42 |
UNLOAD_MODEL = False
|
| 43 |
MOVE_TO_CPU = False
|
|
|
|
| 318 |
try:
|
| 319 |
# Upload files to Hugging Face Hub and get URLs
|
| 320 |
files_to_upload = []
|
| 321 |
+
if melody_filepath_arg and melody_filepath_arg not in ["None", ""] and not melody_filepath_arg.startswith("http"):
|
| 322 |
files_to_upload.append(melody_filepath_arg)
|
| 323 |
+
if background_image_arg and background_image_arg not in ["None", ""] and not background_image_arg.startswith("http"):
|
| 324 |
files_to_upload.append(background_image_arg)
|
| 325 |
|
| 326 |
uploaded_file_urls = {}
|
|
|
|
| 344 |
|
| 345 |
upload_results = upload_files_to_repo(
|
| 346 |
files=files_to_upload,
|
| 347 |
+
repo_id=HF_REPO_ID,
|
| 348 |
folder_name=folder_name,
|
| 349 |
create_permalink=False # We need individual links
|
| 350 |
)
|
|
|
|
| 361 |
if original_filename in link:
|
| 362 |
uploaded_file_urls[file_path] = link
|
| 363 |
break
|
| 364 |
+
else:
|
| 365 |
print(f"Warning: Expected a list from upload_files_to_repo, got {type(upload_results)}")
|
| 366 |
|
| 367 |
if melody_filepath_arg and melody_filepath_arg in uploaded_file_urls:
|
|
|
|
| 410 |
tool_args = {
|
| 411 |
"model": model_name_arg,
|
| 412 |
"text": text_arg,
|
| 413 |
+
"melody_filepath": melody_file_url, # Pass URL instead of file object
|
| 414 |
"duration": duration_arg,
|
| 415 |
"dimension": dimension_arg,
|
| 416 |
"topk": topk_arg,
|
|
|
|
| 426 |
"prompt_index": prompt_index_arg,
|
| 427 |
"include_title": include_title_arg,
|
| 428 |
"include_settings": include_settings_arg,
|
| 429 |
+
"harmony_only": actual_harmony_only,
|
| 430 |
"profile": profile_username_to_send,
|
| 431 |
"segment_length": segment_length_arg,
|
| 432 |
"settings_font_size": settings_font_size_arg,
|
|
|
|
| 463 |
if not isinstance(seed_used, (int, float)): # Allow float for seed then cast later
|
| 464 |
raise gr.Error(f"MCP tool returned a non-numeric seed. Received type: {type(seed_used)}, value: {seed_used}")
|
| 465 |
|
| 466 |
+
if isinstance(waveform_video_path, str) and (waveform_video_path.startswith("http://", "https://")):
|
| 467 |
waveform_video_path = str(download_and_save_file(waveform_video_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 468 |
+
if isinstance(wave_file_path, str) and (wave_file_path.startswith("http://", "https://")):
|
| 469 |
wave_file_path = str(download_and_save_file(wave_file_path, Path(TMPDIR) / str(profile_username_to_send), HF_API_TOKEN))
|
| 470 |
|
| 471 |
return waveform_video_path, wave_file_path, int(seed_used)
|
|
|
|
| 650 |
launch_kwargs['share'] = share
|
| 651 |
launch_kwargs['allowed_paths'] = ["assets", "./assets", "images", "./images", 'e:/TMP']
|
| 652 |
launch_kwargs['favicon_path'] = "./assets/favicon.ico"
|
| 653 |
+
launch_kwargs['mcp_server'] = False
|
| 654 |
|
| 655 |
|
| 656 |
demo.queue(max_size=10, api_open=True).launch(**launch_kwargs)
|
modules/constants.py
CHANGED
|
@@ -74,4 +74,4 @@ video_extensions_list = list(video_extensions)
|
|
| 74 |
upload_file_types = model_extensions_list + image_extensions_list + audio_extensions_list + video_extensions_list
|
| 75 |
|
| 76 |
umg_mcp_server = "https://surn-unlimitedmusicgen.hf.space/gradio_api/mcp/sse"
|
| 77 |
-
|
|
|
|
| 74 |
upload_file_types = model_extensions_list + image_extensions_list + audio_extensions_list + video_extensions_list
|
| 75 |
|
| 76 |
umg_mcp_server = "https://surn-unlimitedmusicgen.hf.space/gradio_api/mcp/sse"
|
| 77 |
+
#umg_mcp_server = "http://127.0.0.1:7860/gradio_api/mcp/sse"
|