Surn commited on
Commit
47b87f0
·
1 Parent(s): 6542012

Font Size setting

Browse files
Files changed (2) hide show
  1. app.py +6 -4
  2. audiocraft/utils/extend.py +3 -3
app.py CHANGED
@@ -168,7 +168,7 @@ def load_melody_filepath(melody_filepath, title, assigned_model,topp, temperatur
168
 
169
  return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=0), 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)
170
 
171
- 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, progress=gr.Progress(track_tqdm=True)):
172
  global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
173
  output_segments = None
174
  melody_name = "Not Used"
@@ -327,7 +327,7 @@ def predict(model, text, melody_filepath, duration, dimension, topk, topp, tempe
327
  with NamedTemporaryFile("wb", suffix=".wav", delete=False, prefix=title_file_name) as file:
328
  video_description = f"{text}\n Duration: {str(initial_duration)} Dimension: {dimension}\n Top-k:{topk} Top-p:{topp}\n Randomness:{temperature}\n cfg:{cfg_coef} overlap: {overlap}\n Seed: {seed}\n Model: {model}\n Melody Condition:{melody_name}\n Sample Segment: {prompt_index}"
329
  if include_settings or include_title:
330
- background = add_settings_to_image(title if include_title else "",video_description if include_settings else "",background_path=background,font=settings_font,font_color=settings_font_color)
331
  audio_write(
332
  file.name, output, MODEL.sample_rate, strategy="loudness",
333
  loudness_headroom_db=18, loudness_compressor=True, add_suffix=False, channels=2)
@@ -363,6 +363,7 @@ def predict(model, text, melody_filepath, duration, dimension, topk, topp, tempe
363
  "Audio": file.name,
364
  "font": settings_font,
365
  "font_color": settings_font_color,
 
366
  "harmony_only": harmony_only,
367
  "background": background,
368
  "include_title": include_title,
@@ -461,7 +462,7 @@ def ui(**kwargs):
461
  melody_filepath = gr.Audio(sources=["upload"], type="filepath", label="Melody Condition (optional)", interactive=True, elem_id="melody-input", key="melody_input")
462
  with gr.Column():
463
  harmony_only = gr.Radio(label="Use Harmony Only",choices=["No", "Yes"], value="No", interactive=True, info="Remove Drums?", key="use_harmony")
464
- prompt_index = gr.Slider(label="Melody Condition Sample Segment", minimum=-1, maximum=MAX_PROMPT_INDEX, step=1, value=0, interactive=True, info="Which 15-30 second segment to condition with, - 1 = align with conditioning melody", key="melody_index")
465
  with gr.Accordion("Video", open=False):
466
  with gr.Row():
467
  background= gr.Image(value="./assets/background.png", sources=["upload"], label="Background", width=768, height=512, type="filepath", interactive=True, key="background_imagepath")
@@ -472,6 +473,7 @@ def ui(**kwargs):
472
  title = gr.Textbox(label="Title", value="UnlimitedMusicGen", interactive=True, key="song_title")
473
  settings_font = gr.Text(label="Settings Font", value="./assets/arial.ttf", interactive=True)
474
  settings_font_color = gr.ColorPicker(label="Settings Font Color", value="#c87f05", interactive=True, key="settings_font_color")
 
475
  with gr.Accordion("Expert", open=False):
476
  with gr.Row():
477
  segment_length = gr.Slider(minimum=10, maximum=30, value=30, step=1,label="Music Generation Segment Length (s)", interactive=True,key="segment_length")
@@ -564,7 +566,7 @@ def ui(**kwargs):
564
  api_name="submit"
565
  ).then(
566
  predict,
567
- inputs=[model, text,melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap, prompt_index, include_title, include_settings, harmony_only, user_profile, segment_length],
568
  outputs=[output, wave_file, seed_used], scroll_to_output=True)
569
 
570
  # Show the interface
 
168
 
169
  return gr.update(value=melody_name), gr.update(maximum=MAX_PROMPT_INDEX, value=0), 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)
170
 
171
+ 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, progress=gr.Progress(track_tqdm=True)):
172
  global MODEL, INTERRUPTED, INTERRUPTING, MOVE_TO_CPU
173
  output_segments = None
174
  melody_name = "Not Used"
 
327
  with NamedTemporaryFile("wb", suffix=".wav", delete=False, prefix=title_file_name) as file:
328
  video_description = f"{text}\n Duration: {str(initial_duration)} Dimension: {dimension}\n Top-k:{topk} Top-p:{topp}\n Randomness:{temperature}\n cfg:{cfg_coef} overlap: {overlap}\n Seed: {seed}\n Model: {model}\n Melody Condition:{melody_name}\n Sample Segment: {prompt_index}"
329
  if include_settings or include_title:
330
+ background = add_settings_to_image(title if include_title else "",video_description if include_settings else "",background_path=background,font=settings_font,font_color=settings_font_color, font_size=settings_font_size)
331
  audio_write(
332
  file.name, output, MODEL.sample_rate, strategy="loudness",
333
  loudness_headroom_db=18, loudness_compressor=True, add_suffix=False, channels=2)
 
363
  "Audio": file.name,
364
  "font": settings_font,
365
  "font_color": settings_font_color,
366
+ "font_size": settings_font_size,
367
  "harmony_only": harmony_only,
368
  "background": background,
369
  "include_title": include_title,
 
462
  melody_filepath = gr.Audio(sources=["upload"], type="filepath", label="Melody Condition (optional)", interactive=True, elem_id="melody-input", key="melody_input")
463
  with gr.Column():
464
  harmony_only = gr.Radio(label="Use Harmony Only",choices=["No", "Yes"], value="No", interactive=True, info="Remove Drums?", key="use_harmony")
465
+ prompt_index = gr.Slider(label="Melody Condition Sample Segment", minimum=-1, maximum=MAX_PROMPT_INDEX, step=1, value=-1, interactive=True, info="Which 10-30 second segment to condition with, - 1 = align with conditioning melody", key="melody_index")
466
  with gr.Accordion("Video", open=False):
467
  with gr.Row():
468
  background= gr.Image(value="./assets/background.png", sources=["upload"], label="Background", width=768, height=512, type="filepath", interactive=True, key="background_imagepath")
 
473
  title = gr.Textbox(label="Title", value="UnlimitedMusicGen", interactive=True, key="song_title")
474
  settings_font = gr.Text(label="Settings Font", value="./assets/arial.ttf", interactive=True)
475
  settings_font_color = gr.ColorPicker(label="Settings Font Color", value="#c87f05", interactive=True, key="settings_font_color")
476
+ settings_font_size = gr.Slider(minimum=8, maximum=64, value=28, step=1, label="Settings Font Size", interactive=True, key="settings_font_size")
477
  with gr.Accordion("Expert", open=False):
478
  with gr.Row():
479
  segment_length = gr.Slider(minimum=10, maximum=30, value=30, step=1,label="Music Generation Segment Length (s)", interactive=True,key="segment_length")
 
566
  api_name="submit"
567
  ).then(
568
  predict,
569
+ inputs=[model, text,melody_filepath, duration, dimension, topk, topp, temperature, cfg_coef, background, title, settings_font, settings_font_color, seed, overlap, prompt_index, include_title, include_settings, harmony_only, user_profile, segment_length, settings_font_size],
570
  outputs=[output, wave_file, seed_used], scroll_to_output=True)
571
 
572
  # Show the interface
audiocraft/utils/extend.py CHANGED
@@ -359,7 +359,7 @@ def load_font(font_name, font_size=16):
359
  return font
360
 
361
 
362
- def add_settings_to_image(title: str = "title", description: str = "", width: int = 768, height: int = 512, background_path: str = "", font: str = "arial.ttf", font_color: str = "#ffffff"):
363
  # Create a new RGBA image with the specified dimensions
364
  image = Image.new("RGBA", (width, height), (255, 255, 255, 0))
365
  # If a background image is specified, open it and paste it onto the image
@@ -376,7 +376,7 @@ def add_settings_to_image(title: str = "title", description: str = "", width: in
376
  text_x = width // 2
377
  text_y = height // 2
378
  # Draw the title text at the center top
379
- title_font = load_font(font, 26) # Replace with your desired font and size
380
 
381
  title_text = '\n'.join(textwrap.wrap(title, width // 12))
382
  title_x, title_y, title_text_width, title_text_height = title_font.getbbox(title_text)
@@ -385,7 +385,7 @@ def add_settings_to_image(title: str = "title", description: str = "", width: in
385
  title_draw = ImageDraw.Draw(image)
386
  title_draw.multiline_text((title_x, title_y), title, fill=font_color, font=title_font, align="center")
387
  # Draw the description text two lines below the title
388
- description_font = load_font(font, 16) # Replace with your desired font and size
389
  description_text = '\n'.join(textwrap.wrap(description, width // 12))
390
  description_x, description_y, description_text_width, description_text_height = description_font.getbbox(description_text)
391
  description_x = max(text_x - (description_text_width // 2), description_x, 0)
 
359
  return font
360
 
361
 
362
+ def add_settings_to_image(title: str = "title", description: str = "", width: int = 768, height: int = 512, background_path: str = "", font: str = "arial.ttf", font_color: str = "#ffffff", font_size: int = 28, progress=gr.Progress(track_tqdm=True)):
363
  # Create a new RGBA image with the specified dimensions
364
  image = Image.new("RGBA", (width, height), (255, 255, 255, 0))
365
  # If a background image is specified, open it and paste it onto the image
 
376
  text_x = width // 2
377
  text_y = height // 2
378
  # Draw the title text at the center top
379
+ title_font = load_font(font, font_size) # Replace with your desired font and size
380
 
381
  title_text = '\n'.join(textwrap.wrap(title, width // 12))
382
  title_x, title_y, title_text_width, title_text_height = title_font.getbbox(title_text)
 
385
  title_draw = ImageDraw.Draw(image)
386
  title_draw.multiline_text((title_x, title_y), title, fill=font_color, font=title_font, align="center")
387
  # Draw the description text two lines below the title
388
+ description_font = load_font(font, int(font_size * 2 / 3)) # Replace with your desired font and size
389
  description_text = '\n'.join(textwrap.wrap(description, width // 12))
390
  description_x, description_y, description_text_width, description_text_height = description_font.getbbox(description_text)
391
  description_x = max(text_x - (description_text_width // 2), description_x, 0)