Spaces:
Running on Zero
Running on Zero
213
#14
by e33r243r2w34r - opened
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🎺
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
short_description: Get a music sample inspired by the mood of an image
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.15.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: true
|
| 10 |
short_description: Get a music sample inspired by the mood of an image
|
app.py
CHANGED
|
@@ -19,7 +19,7 @@ def check_api(model_name):
|
|
| 19 |
return "api not ready yet"
|
| 20 |
elif model_name == "AudioLDM-2":
|
| 21 |
try :
|
| 22 |
-
client = Client("fffiloni/audioldm2-text2audio-text2music-API")
|
| 23 |
return "api ready"
|
| 24 |
except :
|
| 25 |
return "api not ready yet"
|
|
@@ -31,7 +31,7 @@ def check_api(model_name):
|
|
| 31 |
return "api not ready yet"
|
| 32 |
elif model_name == "Mustango":
|
| 33 |
try :
|
| 34 |
-
client = Client("fffiloni/mustango-API
|
| 35 |
return "api ready"
|
| 36 |
except :
|
| 37 |
return "api not ready yet"
|
|
@@ -47,12 +47,6 @@ def check_api(model_name):
|
|
| 47 |
return "api ready"
|
| 48 |
except:
|
| 49 |
return "api not ready yet"
|
| 50 |
-
elif model_name == "ACE Step":
|
| 51 |
-
try :
|
| 52 |
-
client = Client("fffiloni/ACE-Step-API", hf_token=hf_token)
|
| 53 |
-
return "api ready"
|
| 54 |
-
except :
|
| 55 |
-
return "api not ready yet"
|
| 56 |
|
| 57 |
|
| 58 |
from moviepy.editor import VideoFileClip
|
|
@@ -75,7 +69,7 @@ def extract_audio(video_in):
|
|
| 75 |
|
| 76 |
|
| 77 |
def get_caption(image_in):
|
| 78 |
-
kosmos2_client = Client("fffiloni/Kosmos-2-API")
|
| 79 |
kosmos2_result = kosmos2_client.predict(
|
| 80 |
image_input=handle_file(image_in),
|
| 81 |
text_input="Detailed",
|
|
@@ -131,10 +125,10 @@ def get_magnet(prompt):
|
|
| 131 |
return result[1]
|
| 132 |
|
| 133 |
def get_audioldm(prompt):
|
| 134 |
-
client = Client("fffiloni/audioldm2-text2audio-text2music-API")
|
| 135 |
seed = random.randint(0, MAX_SEED)
|
| 136 |
result = client.predict(
|
| 137 |
-
|
| 138 |
negative_prompt="Low quality.", # str in 'Negative prompt' Textbox component
|
| 139 |
duration=10, # int | float (numeric value between 5 and 15) in 'Duration (seconds)' Slider component
|
| 140 |
guidance_scale=6.5, # int | float (numeric value between 0 and 7) in 'Guidance scale' Slider component
|
|
@@ -159,7 +153,7 @@ def get_riffusion(prompt):
|
|
| 159 |
return result[1]
|
| 160 |
|
| 161 |
def get_mustango(prompt):
|
| 162 |
-
client = Client("fffiloni/mustango-API
|
| 163 |
result = client.predict(
|
| 164 |
prompt=prompt, # str in 'Prompt' Textbox component
|
| 165 |
steps=200, # float (numeric value between 100 and 200) in 'Steps' Slider component
|
|
@@ -191,39 +185,6 @@ def get_stable_audio_open(prompt):
|
|
| 191 |
print(result)
|
| 192 |
return result
|
| 193 |
|
| 194 |
-
def get_ace(prompt):
|
| 195 |
-
from gradio_client import Client, handle_file
|
| 196 |
-
|
| 197 |
-
client = Client("fffiloni/ACE-Step-API", hf_token=hf_token)
|
| 198 |
-
result = client.predict(
|
| 199 |
-
audio_duration=-1,
|
| 200 |
-
prompt=prompt,
|
| 201 |
-
lyrics="[inst]",
|
| 202 |
-
infer_step=60,
|
| 203 |
-
guidance_scale=15,
|
| 204 |
-
scheduler_type="euler",
|
| 205 |
-
cfg_type="apg",
|
| 206 |
-
omega_scale=10,
|
| 207 |
-
manual_seeds=None,
|
| 208 |
-
guidance_interval=0.5,
|
| 209 |
-
guidance_interval_decay=0,
|
| 210 |
-
min_guidance_scale=3,
|
| 211 |
-
use_erg_tag=True,
|
| 212 |
-
use_erg_lyric=False,
|
| 213 |
-
use_erg_diffusion=True,
|
| 214 |
-
oss_steps=None,
|
| 215 |
-
guidance_scale_text=0,
|
| 216 |
-
guidance_scale_lyric=0,
|
| 217 |
-
audio2audio_enable=False,
|
| 218 |
-
ref_audio_strength=0.5,
|
| 219 |
-
ref_audio_input=None,
|
| 220 |
-
lora_name_or_path="none",
|
| 221 |
-
api_name="/__call__"
|
| 222 |
-
)
|
| 223 |
-
print(result)
|
| 224 |
-
return result[0]
|
| 225 |
-
|
| 226 |
-
|
| 227 |
import re
|
| 228 |
import torch
|
| 229 |
from transformers import pipeline
|
|
@@ -251,7 +212,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,34 +237,13 @@ 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 |
-
"""
|
| 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: "Mustango", "AudioLDM-2", "Riffusion", "ACE Step", "Stable Audio Open".
|
| 293 |
-
|
| 294 |
-
Returns:
|
| 295 |
-
- A string containing the musical prompt generated from the image.
|
| 296 |
-
- A flag to show the retry button in the UI (for user to edit and retry the generation).
|
| 297 |
-
- The output of the selected model, typically an audio filepath or object depending on model.
|
| 298 |
-
"""
|
| 299 |
if image_in == None :
|
| 300 |
raise gr.Error("Please provide an image input")
|
| 301 |
|
| 302 |
if chosen_model == [] :
|
| 303 |
raise gr.Error("Please pick a model")
|
| 304 |
|
| 305 |
-
api_status = check_api(chosen_model)
|
| 306 |
-
|
| 307 |
if api_status == "api not ready yet" :
|
| 308 |
raise gr.Error("This model is not ready yet, you can pick another one instead :)")
|
| 309 |
|
|
@@ -332,9 +272,6 @@ def infer(image_in, chosen_model):
|
|
| 332 |
elif chosen_model == "Stable Audio Open" :
|
| 333 |
gr.Info("Now calling Stable Audio Open for music...")
|
| 334 |
music_o = get_stable_audio_open(musical_prompt)
|
| 335 |
-
elif chosen_model == "ACE Step" :
|
| 336 |
-
gr.Info("Now calling ACE Step for music...")
|
| 337 |
-
music_o = get_ace(musical_prompt)
|
| 338 |
|
| 339 |
return gr.update(value=musical_prompt, interactive=True), gr.update(visible=True), music_o
|
| 340 |
|
|
@@ -360,9 +297,6 @@ def retry(chosen_model, caption):
|
|
| 360 |
elif chosen_model == "Stable Audio Open" :
|
| 361 |
gr.Info("Now calling Stable Audio Open for music...")
|
| 362 |
music_o = get_stable_audio_open(musical_prompt)
|
| 363 |
-
elif chosen_model == "ACE Step" :
|
| 364 |
-
gr.Info("Now calling ACE Step for music...")
|
| 365 |
-
music_o = get_ace(musical_prompt)
|
| 366 |
|
| 367 |
return music_o
|
| 368 |
|
|
@@ -407,12 +341,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 407 |
label = "Choose a model",
|
| 408 |
choices = [
|
| 409 |
#"MAGNet",
|
| 410 |
-
#"ACE Step",
|
| 411 |
"AudioLDM-2",
|
| 412 |
"Riffusion",
|
| 413 |
"Mustango",
|
| 414 |
#"MusicGen",
|
| 415 |
-
|
| 416 |
],
|
| 417 |
value = None,
|
| 418 |
filterable = False
|
|
@@ -461,15 +394,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 461 |
fn = check_api,
|
| 462 |
inputs = chosen_model,
|
| 463 |
outputs = check_status,
|
| 464 |
-
queue = False
|
| 465 |
-
api_visibility='undocumented'
|
| 466 |
)
|
| 467 |
|
| 468 |
retry_btn.click(
|
| 469 |
fn = retry,
|
| 470 |
inputs = [chosen_model, caption],
|
| 471 |
-
outputs = [result]
|
| 472 |
-
api_visibility='undocumented'
|
| 473 |
)
|
| 474 |
|
| 475 |
submit_btn.click(
|
|
@@ -477,7 +408,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 477 |
inputs = [
|
| 478 |
image_in,
|
| 479 |
chosen_model,
|
| 480 |
-
|
| 481 |
],
|
| 482 |
outputs =[
|
| 483 |
caption,
|
|
@@ -486,4 +417,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 486 |
]
|
| 487 |
)
|
| 488 |
|
| 489 |
-
demo.queue(max_size=16).launch(
|
|
|
|
| 19 |
return "api not ready yet"
|
| 20 |
elif model_name == "AudioLDM-2":
|
| 21 |
try :
|
| 22 |
+
client = Client("fffiloni/audioldm2-text2audio-text2music-API", hf_token=hf_token)
|
| 23 |
return "api ready"
|
| 24 |
except :
|
| 25 |
return "api not ready yet"
|
|
|
|
| 31 |
return "api not ready yet"
|
| 32 |
elif model_name == "Mustango":
|
| 33 |
try :
|
| 34 |
+
client = Client("fffiloni/mustango-API", hf_token=hf_token)
|
| 35 |
return "api ready"
|
| 36 |
except :
|
| 37 |
return "api not ready yet"
|
|
|
|
| 47 |
return "api ready"
|
| 48 |
except:
|
| 49 |
return "api not ready yet"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
from moviepy.editor import VideoFileClip
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
def get_caption(image_in):
|
| 72 |
+
kosmos2_client = Client("fffiloni/Kosmos-2-API", hf_token=hf_token)
|
| 73 |
kosmos2_result = kosmos2_client.predict(
|
| 74 |
image_input=handle_file(image_in),
|
| 75 |
text_input="Detailed",
|
|
|
|
| 125 |
return result[1]
|
| 126 |
|
| 127 |
def get_audioldm(prompt):
|
| 128 |
+
client = Client("fffiloni/audioldm2-text2audio-text2music-API", hf_token=hf_token)
|
| 129 |
seed = random.randint(0, MAX_SEED)
|
| 130 |
result = client.predict(
|
| 131 |
+
text=prompt, # str in 'Input text' Textbox component
|
| 132 |
negative_prompt="Low quality.", # str in 'Negative prompt' Textbox component
|
| 133 |
duration=10, # int | float (numeric value between 5 and 15) in 'Duration (seconds)' Slider component
|
| 134 |
guidance_scale=6.5, # int | float (numeric value between 0 and 7) in 'Guidance scale' Slider component
|
|
|
|
| 153 |
return result[1]
|
| 154 |
|
| 155 |
def get_mustango(prompt):
|
| 156 |
+
client = Client("fffiloni/mustango-API", hf_token=hf_token)
|
| 157 |
result = client.predict(
|
| 158 |
prompt=prompt, # str in 'Prompt' Textbox component
|
| 159 |
steps=200, # float (numeric value between 100 and 200) in 'Steps' Slider component
|
|
|
|
| 185 |
print(result)
|
| 186 |
return result
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
import re
|
| 189 |
import torch
|
| 190 |
from transformers import pipeline
|
|
|
|
| 212 |
"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."
|
| 213 |
"""
|
| 214 |
|
| 215 |
+
@spaces.GPU(enable_queue=True)
|
| 216 |
def get_musical_prompt(user_prompt, chosen_model):
|
| 217 |
|
| 218 |
"""
|
|
|
|
| 237 |
print(f"SUGGESTED Musical prompt: {cleaned_text}")
|
| 238 |
return cleaned_text.lstrip("\n")
|
| 239 |
|
| 240 |
+
def infer(image_in, chosen_model, api_status):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
if image_in == None :
|
| 242 |
raise gr.Error("Please provide an image input")
|
| 243 |
|
| 244 |
if chosen_model == [] :
|
| 245 |
raise gr.Error("Please pick a model")
|
| 246 |
|
|
|
|
|
|
|
| 247 |
if api_status == "api not ready yet" :
|
| 248 |
raise gr.Error("This model is not ready yet, you can pick another one instead :)")
|
| 249 |
|
|
|
|
| 272 |
elif chosen_model == "Stable Audio Open" :
|
| 273 |
gr.Info("Now calling Stable Audio Open for music...")
|
| 274 |
music_o = get_stable_audio_open(musical_prompt)
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
return gr.update(value=musical_prompt, interactive=True), gr.update(visible=True), music_o
|
| 277 |
|
|
|
|
| 297 |
elif chosen_model == "Stable Audio Open" :
|
| 298 |
gr.Info("Now calling Stable Audio Open for music...")
|
| 299 |
music_o = get_stable_audio_open(musical_prompt)
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
return music_o
|
| 302 |
|
|
|
|
| 341 |
label = "Choose a model",
|
| 342 |
choices = [
|
| 343 |
#"MAGNet",
|
|
|
|
| 344 |
"AudioLDM-2",
|
| 345 |
"Riffusion",
|
| 346 |
"Mustango",
|
| 347 |
#"MusicGen",
|
| 348 |
+
"Stable Audio Open"
|
| 349 |
],
|
| 350 |
value = None,
|
| 351 |
filterable = False
|
|
|
|
| 394 |
fn = check_api,
|
| 395 |
inputs = chosen_model,
|
| 396 |
outputs = check_status,
|
| 397 |
+
queue = False
|
|
|
|
| 398 |
)
|
| 399 |
|
| 400 |
retry_btn.click(
|
| 401 |
fn = retry,
|
| 402 |
inputs = [chosen_model, caption],
|
| 403 |
+
outputs = [result]
|
|
|
|
| 404 |
)
|
| 405 |
|
| 406 |
submit_btn.click(
|
|
|
|
| 408 |
inputs = [
|
| 409 |
image_in,
|
| 410 |
chosen_model,
|
| 411 |
+
check_status
|
| 412 |
],
|
| 413 |
outputs =[
|
| 414 |
caption,
|
|
|
|
| 417 |
]
|
| 418 |
)
|
| 419 |
|
| 420 |
+
demo.queue(max_size=16).launch(show_api=False, show_error=True)
|