Spaces:
Sleeping
Sleeping
commit
Browse files
app.py
CHANGED
@@ -413,7 +413,8 @@ CHECKPOINTS = ESRGANUpscalerCheckpoints(
|
|
413 |
|
414 |
device = DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
415 |
DTYPE = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
|
416 |
-
enhancer = ESRGANUpscaler(checkpoints=CHECKPOINTS, device=
|
|
|
417 |
|
418 |
# logging
|
419 |
|
@@ -434,8 +435,8 @@ pegasus_name = "google/pegasus-xsum"
|
|
434 |
# precision data
|
435 |
|
436 |
seq=512
|
437 |
-
width=
|
438 |
-
height=
|
439 |
image_steps=8
|
440 |
img_accu=0
|
441 |
|
@@ -554,7 +555,7 @@ def upscaler(
|
|
554 |
return enhanced_image
|
555 |
|
556 |
def summarize_text(
|
557 |
-
text, max_length=
|
558 |
):
|
559 |
log(f'CALL summarize_text')
|
560 |
summary = pegasus_tokenizer.decode( pegasus_model.generate(
|
@@ -570,8 +571,7 @@ def generate_random_string(length):
|
|
570 |
characters = str(ascii_letters + digits)
|
571 |
return ''.join(random.choice(characters) for _ in range(length))
|
572 |
|
573 |
-
|
574 |
-
def pipe_generate(p1,p2):
|
575 |
log(f'CALL pipe_generate')
|
576 |
imgs = image_pipe(
|
577 |
prompt=p1,
|
@@ -579,7 +579,7 @@ def pipe_generate(p1,p2):
|
|
579 |
height=height,
|
580 |
width=width,
|
581 |
guidance_scale=img_accu,
|
582 |
-
num_images_per_prompt=
|
583 |
num_inference_steps=image_steps,
|
584 |
max_sequence_length=seq,
|
585 |
generator=torch.Generator(device).manual_seed(int(str(random.random()).split(".")[1]))
|
@@ -612,6 +612,20 @@ def add_song_cover_text(img,artist,song):
|
|
612 |
|
613 |
return img
|
614 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
def handle_generate(artist,song,genre,lyrics):
|
616 |
|
617 |
log(f'CALL handle_generate')
|
@@ -631,19 +645,9 @@ def handle_generate(artist,song,genre,lyrics):
|
|
631 |
|
632 |
Negative: {neg}
|
633 |
""")
|
634 |
-
|
635 |
-
imgs = pipe_generate(pos,neg)
|
636 |
-
|
637 |
-
names = []
|
638 |
-
index = 1
|
639 |
-
for img in imgs:
|
640 |
-
labeled_img = add_song_cover_text(img,pos_artist,pos_song)
|
641 |
-
enhanced_img = upscaler(labeled_img)
|
642 |
-
name = f'{pos_artist} - {pos_song} ({index}).png'
|
643 |
-
enhanced_img.save(name)
|
644 |
-
names.append(name)
|
645 |
-
return names
|
646 |
|
|
|
|
|
647 |
# entry
|
648 |
|
649 |
if __name__ == "__main__":
|
@@ -682,17 +686,12 @@ if __name__ == "__main__":
|
|
682 |
run = gr.Button("Generate",elem_classes="btn")
|
683 |
|
684 |
with gr.Row():
|
685 |
-
|
686 |
-
cover2 = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
687 |
-
cover3 = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
688 |
-
cover4 = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
689 |
-
cover5 = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
690 |
-
cover6 = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
691 |
|
692 |
run.click(
|
693 |
fn=handle_generate,
|
694 |
inputs=[artist,song,genre,lyrics],
|
695 |
-
outputs=[
|
696 |
)
|
697 |
|
698 |
demo.queue().launch()
|
|
|
413 |
|
414 |
device = DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
415 |
DTYPE = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32
|
416 |
+
enhancer = ESRGANUpscaler(checkpoints=CHECKPOINTS, device=DEVICE, dtype=DTYPE)
|
417 |
+
enhancer.to(DEVICE)
|
418 |
|
419 |
# logging
|
420 |
|
|
|
435 |
# precision data
|
436 |
|
437 |
seq=512
|
438 |
+
width=1536
|
439 |
+
height=1536
|
440 |
image_steps=8
|
441 |
img_accu=0
|
442 |
|
|
|
555 |
return enhanced_image
|
556 |
|
557 |
def summarize_text(
|
558 |
+
text, max_length=10, num_beams=4, early_stopping=True
|
559 |
):
|
560 |
log(f'CALL summarize_text')
|
561 |
summary = pegasus_tokenizer.decode( pegasus_model.generate(
|
|
|
571 |
characters = str(ascii_letters + digits)
|
572 |
return ''.join(random.choice(characters) for _ in range(length))
|
573 |
|
574 |
+
def pipe_generate_image(p1,p2):
|
|
|
575 |
log(f'CALL pipe_generate')
|
576 |
imgs = image_pipe(
|
577 |
prompt=p1,
|
|
|
579 |
height=height,
|
580 |
width=width,
|
581 |
guidance_scale=img_accu,
|
582 |
+
num_images_per_prompt=1,
|
583 |
num_inference_steps=image_steps,
|
584 |
max_sequence_length=seq,
|
585 |
generator=torch.Generator(device).manual_seed(int(str(random.random()).split(".")[1]))
|
|
|
612 |
|
613 |
return img
|
614 |
|
615 |
+
@spaces.GPU(duration=180)
|
616 |
+
def all_pipes(img,pos,neg,artist,song):
|
617 |
+
imgs = pipe_generate_image(pos,neg)
|
618 |
+
|
619 |
+
names = []
|
620 |
+
index = 1
|
621 |
+
for img in imgs:
|
622 |
+
labeled_img = add_song_cover_text(img,artist,song)
|
623 |
+
enhanced_img = upscaler(labeled_img)
|
624 |
+
name = f'{pos_artist} - {pos_song} ({index}).png'
|
625 |
+
enhanced_img.save(name)
|
626 |
+
names.append(name)
|
627 |
+
return names
|
628 |
+
|
629 |
def handle_generate(artist,song,genre,lyrics):
|
630 |
|
631 |
log(f'CALL handle_generate')
|
|
|
645 |
|
646 |
Negative: {neg}
|
647 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
648 |
|
649 |
+
return all_pipes(img,pos,neg,pos_artist,pos_song)
|
650 |
+
|
651 |
# entry
|
652 |
|
653 |
if __name__ == "__main__":
|
|
|
686 |
run = gr.Button("Generate",elem_classes="btn")
|
687 |
|
688 |
with gr.Row():
|
689 |
+
cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
|
|
|
|
|
|
|
|
|
|
690 |
|
691 |
run.click(
|
692 |
fn=handle_generate,
|
693 |
inputs=[artist,song,genre,lyrics],
|
694 |
+
outputs=[cover]
|
695 |
)
|
696 |
|
697 |
demo.queue().launch()
|