yaron123 commited on
Commit
c558c3e
·
1 Parent(s): 8e3b331
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -455,9 +455,6 @@ h1,h2,h3,h4,h5,h6 {
455
  footer {
456
  display: none !important;
457
  }
458
- #col-container {
459
- margin: 0 auto;
460
- }
461
  .image-container {
462
  aspect-ratio: """,str(width),"/",str(height),""" !important;
463
  }
@@ -522,7 +519,7 @@ def upscaler(
522
  tile_width: int = 112,
523
  tile_height: int = 144,
524
  denoise_strength: float = 0.35,
525
- num_inference_steps: int = 30,
526
  solver: str = "DDIM",
527
  ) -> Image.Image:
528
 
@@ -545,7 +542,7 @@ def upscaler(
545
  tile_size=(tile_height, tile_width),
546
  denoise_strength=denoise_strength,
547
  num_inference_steps=num_inference_steps,
548
- loras_scale={"more_details": 1.0, "sdxl_render": 1.0},
549
  solver_type=solver_type,
550
  )
551
 
@@ -585,42 +582,42 @@ def pipe_generate_image(p1,p2):
585
  log(f'RET pipe_generate')
586
  return imgs
587
 
588
- def add_song_cover_text(img,artist,song):
589
 
590
  draw = ImageDraw.Draw(img)
591
 
592
  rows = 1
593
- labels_distance = 1 / 2.5
594
 
595
  textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
596
  font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
597
  textwidth = draw.textlength(song,font)
598
  x = math.ceil((width - textwidth) / 2)
599
- y = height - math.ceil(textheight * rows / 2)
600
- y = y - math.ceil(y * labels_distance)
601
  draw.text((x, y), song, (255,255,255), font=font, spacing=2, stroke_width=4, stroke_fill=(0,0,0))
602
 
603
  textheight=min(math.ceil( width / 12 ), math.ceil( height / 6 ))
604
  font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
605
  textwidth = draw.textlength(artist,font)
606
  x = math.ceil((width - textwidth) / 2)
607
- y = height - math.ceil(textheight * rows / 2)
608
- y = y + math.ceil(y * labels_distance)
609
  draw.text((x, y), artist, (0,0,0), font=font, spacing=4, stroke_width=2, stroke_fill=(255,255,255))
610
 
611
  return img
612
 
613
- @spaces.GPU(duration=240)
614
  def all_pipes(pos,neg,artist,song):
615
  imgs = pipe_generate_image(pos,neg)
616
 
617
  names = []
618
  index = 1
619
  for img in imgs:
620
- labeled_img = add_song_cover_text(img,artist,song)
621
- enhanced_img = upscaler(labeled_img)
622
  name = f'{artist} - {song} ({index}).png'
623
- enhanced_img.save(name)
624
  names.append(name)
625
  return names
626
 
@@ -636,7 +633,7 @@ def handle_generate(artist,song,genre,lyrics):
636
  pos_lyrics_sum = pos_lyrics if pos_lyrics == "" else summarize_text(pos_lyrics)
637
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry Low-Quality Worst-Quality Low-Resolution Painted"
638
  q = "\""
639
- pos = f'Realistic Vivid Genuine Reasonable Highly-Detailed 4K { pos_genre } SONG { pos_song } { "INSTRUMENTAL" if pos_lyrics_sum == "" else q + pos_lyrics_sum + q }'
640
 
641
  print(f"""
642
  Positive: {pos}
@@ -653,21 +650,20 @@ if __name__ == "__main__":
653
  gr.Markdown(f"""
654
  # Song Cover Image Generator
655
  """)
656
- with gr.Column():
657
- with gr.Column():
658
- with gr.Row():
659
- artist = gr.Textbox(
660
  placeholder="Artist name",
661
  value="",
662
  container=False,
663
  max_lines=1
664
- )
665
- song = gr.Textbox(
666
  placeholder="Song name",
667
  value="",
668
  container=False,
669
  max_lines=1
670
- )
 
671
  genre = gr.Textbox(
672
  placeholder="Genre (English)",
673
  value="",
@@ -681,10 +677,10 @@ if __name__ == "__main__":
681
  max_lines=1
682
  )
683
 
684
- run = gr.Button("Generate",elem_classes="btn")
 
685
 
686
- with gr.Row():
687
- cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
688
 
689
  run.click(
690
  fn=handle_generate,
 
455
  footer {
456
  display: none !important;
457
  }
 
 
 
458
  .image-container {
459
  aspect-ratio: """,str(width),"/",str(height),""" !important;
460
  }
 
519
  tile_width: int = 112,
520
  tile_height: int = 144,
521
  denoise_strength: float = 0.35,
522
+ num_inference_steps: int = 18,
523
  solver: str = "DDIM",
524
  ) -> Image.Image:
525
 
 
542
  tile_size=(tile_height, tile_width),
543
  denoise_strength=denoise_strength,
544
  num_inference_steps=num_inference_steps,
545
+ loras_scale={"more_details": 0.5, "sdxl_render": 1.0},
546
  solver_type=solver_type,
547
  )
548
 
 
582
  log(f'RET pipe_generate')
583
  return imgs
584
 
585
+ def add_song_cover_text(img,artist,song,height,width):
586
 
587
  draw = ImageDraw.Draw(img)
588
 
589
  rows = 1
590
+ labels_distance = 1/3
591
 
592
  textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
593
  font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
594
  textwidth = draw.textlength(song,font)
595
  x = math.ceil((width - textwidth) / 2)
596
+ y = height - (textheight * rows / 2) - (height / 2)
597
+ y = math.ceil(y - (height / 2 * labels_distance))
598
  draw.text((x, y), song, (255,255,255), font=font, spacing=2, stroke_width=4, stroke_fill=(0,0,0))
599
 
600
  textheight=min(math.ceil( width / 12 ), math.ceil( height / 6 ))
601
  font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
602
  textwidth = draw.textlength(artist,font)
603
  x = math.ceil((width - textwidth) / 2)
604
+ y = height - (textheight * rows / 2) - (height / 2)
605
+ y = math.ceil(y + (height / 2 * labels_distance))
606
  draw.text((x, y), artist, (0,0,0), font=font, spacing=4, stroke_width=2, stroke_fill=(255,255,255))
607
 
608
  return img
609
 
610
+ @spaces.GPU(duration=180)
611
  def all_pipes(pos,neg,artist,song):
612
  imgs = pipe_generate_image(pos,neg)
613
 
614
  names = []
615
  index = 1
616
  for img in imgs:
617
+ enhanced_img = upscaler(img)
618
+ labeled_img = add_song_cover_text(enhanced_img,artist,song,height*4,width*4)
619
  name = f'{artist} - {song} ({index}).png'
620
+ labeled_img.save(name)
621
  names.append(name)
622
  return names
623
 
 
633
  pos_lyrics_sum = pos_lyrics if pos_lyrics == "" else summarize_text(pos_lyrics)
634
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry Low-Quality Worst-Quality Low-Resolution Painted"
635
  q = "\""
636
+ pos = f'Realistic Vivid Genuine Reasonable Highly-Detailed 4K { pos_genre } { pos_song }{ pos_lyrics_sum if pos_lyrics_sum == "" else " " + q + pos_lyrics_sum + q }'
637
 
638
  print(f"""
639
  Positive: {pos}
 
650
  gr.Markdown(f"""
651
  # Song Cover Image Generator
652
  """)
653
+ with gr.Column(scale=2):
654
+ artist = gr.Textbox(
 
 
655
  placeholder="Artist name",
656
  value="",
657
  container=False,
658
  max_lines=1
659
+ )
660
+ song = gr.Textbox(
661
  placeholder="Song name",
662
  value="",
663
  container=False,
664
  max_lines=1
665
+ )
666
+ with gr.Column(scale=2):
667
  genre = gr.Textbox(
668
  placeholder="Genre (English)",
669
  value="",
 
677
  max_lines=1
678
  )
679
 
680
+ with gr.Column():
681
+ cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
682
 
683
+ run = gr.Button("Generate",elem_classes="btn")
 
684
 
685
  run.click(
686
  fn=handle_generate,