Spaces:
Sleeping
Sleeping
MCP ready
Browse files
app.py
CHANGED
@@ -251,7 +251,7 @@ Immediately STOP after that. It should be EXACTLY in this format:
|
|
251 |
"The song is an instrumental. The song is in medium tempo with a classical guitar playing a lilting melody in accompaniment style. The song is emotional and romantic. The song is a romantic instrumental song. The chord sequence is Gm, F6, Ebm. The time signature is 4/4. This song is in Adagio. The key of this song is G minor."
|
252 |
"""
|
253 |
|
254 |
-
@spaces.GPU(
|
255 |
def get_musical_prompt(user_prompt, chosen_model):
|
256 |
|
257 |
"""
|
@@ -276,13 +276,35 @@ def get_musical_prompt(user_prompt, chosen_model):
|
|
276 |
print(f"SUGGESTED Musical prompt: {cleaned_text}")
|
277 |
return cleaned_text.lstrip("\n")
|
278 |
|
279 |
-
def infer(image_in, chosen_model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
if image_in == None :
|
281 |
raise gr.Error("Please provide an image input")
|
282 |
|
283 |
if chosen_model == [] :
|
284 |
raise gr.Error("Please pick a model")
|
285 |
|
|
|
|
|
286 |
if api_status == "api not ready yet" :
|
287 |
raise gr.Error("This model is not ready yet, you can pick another one instead :)")
|
288 |
|
@@ -440,13 +462,15 @@ with gr.Blocks(css=css) as demo:
|
|
440 |
fn = check_api,
|
441 |
inputs = chosen_model,
|
442 |
outputs = check_status,
|
443 |
-
queue = False
|
|
|
444 |
)
|
445 |
|
446 |
retry_btn.click(
|
447 |
fn = retry,
|
448 |
inputs = [chosen_model, caption],
|
449 |
-
outputs = [result]
|
|
|
450 |
)
|
451 |
|
452 |
submit_btn.click(
|
@@ -454,7 +478,7 @@ with gr.Blocks(css=css) as demo:
|
|
454 |
inputs = [
|
455 |
image_in,
|
456 |
chosen_model,
|
457 |
-
check_status
|
458 |
],
|
459 |
outputs =[
|
460 |
caption,
|
@@ -463,4 +487,4 @@ with gr.Blocks(css=css) as demo:
|
|
463 |
]
|
464 |
)
|
465 |
|
466 |
-
demo.queue(max_size=16).launch(show_api=
|
|
|
251 |
"The song is an instrumental. The song is in medium tempo with a classical guitar playing a lilting melody in accompaniment style. The song is emotional and romantic. The song is a romantic instrumental song. The chord sequence is Gm, F6, Ebm. The time signature is 4/4. This song is in Adagio. The key of this song is G minor."
|
252 |
"""
|
253 |
|
254 |
+
@spaces.GPU()
|
255 |
def get_musical_prompt(user_prompt, chosen_model):
|
256 |
|
257 |
"""
|
|
|
276 |
print(f"SUGGESTED Musical prompt: {cleaned_text}")
|
277 |
return cleaned_text.lstrip("\n")
|
278 |
|
279 |
+
def infer(image_in, chosen_model):
|
280 |
+
"""
|
281 |
+
Generate music from an input image and selected music generation model.
|
282 |
+
|
283 |
+
This function performs the following steps:
|
284 |
+
1. Checks that an image and a model have been provided.
|
285 |
+
2. Verifies if the selected model's API is currently available.
|
286 |
+
3. Uses an image captioning model (Kosmos-2) to describe the image.
|
287 |
+
4. Generates a musical prompt from the image caption using a language model.
|
288 |
+
5. Sends the musical prompt to the selected music generation model and retrieves the result.
|
289 |
+
|
290 |
+
Args:
|
291 |
+
image_in: The filepath to an input image. This image is used as inspiration to generate music.
|
292 |
+
chosen_model: The name of the model to use for music generation. Supported values include:
|
293 |
+
"Mustango", "ACE Step".
|
294 |
+
|
295 |
+
Returns:
|
296 |
+
- A string containing the musical prompt generated from the image.
|
297 |
+
- A flag to show the retry button in the UI (for user to edit and retry the generation).
|
298 |
+
- The output of the selected model, typically an audio filepath or object depending on model.
|
299 |
+
"""
|
300 |
if image_in == None :
|
301 |
raise gr.Error("Please provide an image input")
|
302 |
|
303 |
if chosen_model == [] :
|
304 |
raise gr.Error("Please pick a model")
|
305 |
|
306 |
+
api_status = check_api(chosen_model)
|
307 |
+
|
308 |
if api_status == "api not ready yet" :
|
309 |
raise gr.Error("This model is not ready yet, you can pick another one instead :)")
|
310 |
|
|
|
462 |
fn = check_api,
|
463 |
inputs = chosen_model,
|
464 |
outputs = check_status,
|
465 |
+
queue = False,
|
466 |
+
show_api=False
|
467 |
)
|
468 |
|
469 |
retry_btn.click(
|
470 |
fn = retry,
|
471 |
inputs = [chosen_model, caption],
|
472 |
+
outputs = [result],
|
473 |
+
show_api=False
|
474 |
)
|
475 |
|
476 |
submit_btn.click(
|
|
|
478 |
inputs = [
|
479 |
image_in,
|
480 |
chosen_model,
|
481 |
+
#check_status
|
482 |
],
|
483 |
outputs =[
|
484 |
caption,
|
|
|
487 |
]
|
488 |
)
|
489 |
|
490 |
+
demo.queue(max_size=16).launch(show_api=True, show_error=True, ssr_mode=False, mcp_server=True)
|