Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -748,7 +748,7 @@ def _summarize(text):
|
|
748 |
toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
|
749 |
gen = model.generate(
|
750 |
toks,
|
751 |
-
length_penalty=0.
|
752 |
num_beams=8,
|
753 |
early_stopping=True,
|
754 |
max_length=512
|
@@ -787,31 +787,42 @@ def generate_random_string(length):
|
|
787 |
characters = str(ascii_letters + digits)
|
788 |
return ''.join(random.choice(characters) for _ in range(length))
|
789 |
|
790 |
-
def add_song_cover_text(img,
|
791 |
|
792 |
-
|
793 |
-
|
794 |
-
labels_distance = 1/3
|
795 |
|
796 |
-
|
797 |
-
textheight=min(math.ceil( w / 10 ), math.ceil( h / 5 ))
|
798 |
-
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
799 |
-
textwidth = draw.textlength(song,font)
|
800 |
-
x = math.ceil((w - textwidth) / 2)
|
801 |
-
y = h - (textheight * rows / 2) - (h / 2)
|
802 |
-
y = math.ceil(y - (h / 2 * labels_distance))
|
803 |
-
draw.text((x, y), song, (255,255,255,85), font=font, spacing=2, stroke_width=math.ceil(textheight/20), stroke_fill=(0,0,0,170))
|
804 |
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
813 |
|
814 |
-
|
|
|
|
|
815 |
|
816 |
google_translate_endpoint = "https://translate.google.com/m"
|
817 |
language_codes = {
|
@@ -1523,8 +1534,22 @@ if __name__ == "__main__":
|
|
1523 |
|
1524 |
with gr.Column():
|
1525 |
cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='pil', show_share_button=False)
|
1526 |
-
|
1527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1528 |
gr.on(
|
1529 |
triggers=[run.click],
|
1530 |
fn=handle_generation,
|
@@ -1536,5 +1561,11 @@ if __name__ == "__main__":
|
|
1536 |
inputs=[cover],
|
1537 |
outputs=[cover]
|
1538 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
1539 |
|
1540 |
demo.queue().launch()
|
|
|
748 |
toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
|
749 |
gen = model.generate(
|
750 |
toks,
|
751 |
+
length_penalty=0.9,
|
752 |
num_beams=8,
|
753 |
early_stopping=True,
|
754 |
max_length=512
|
|
|
787 |
characters = str(ascii_letters + digits)
|
788 |
return ''.join(random.choice(characters) for _ in range(length))
|
789 |
|
790 |
+
def add_song_cover_text(img,top_title=None,bottom_title=none):
|
791 |
|
792 |
+
if not working:
|
|
|
|
|
793 |
|
794 |
+
working = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
|
796 |
+
h = _HEIGHT_
|
797 |
+
w = _WIDTH_
|
798 |
+
|
799 |
+
draw = ImageDraw.Draw(img,mode="RGBA")
|
800 |
+
|
801 |
+
labels_distance = 1/3
|
802 |
+
|
803 |
+
if top_title:
|
804 |
+
rows = len(song.split("\n"))
|
805 |
+
textheight=min(math.ceil( w / 10 ), math.ceil( h / 5 ))
|
806 |
+
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
807 |
+
textwidth = draw.textlength(top_title,font)
|
808 |
+
x = math.ceil((w - textwidth) / 2)
|
809 |
+
y = h - (textheight * rows / 2) - (h / 2)
|
810 |
+
y = math.ceil(y - (h / 2 * labels_distance))
|
811 |
+
draw.text((x, y), top_title, (255,255,255), font=font, spacing=2, stroke_width=math.ceil(textheight/20), stroke_fill=(0,0,0))
|
812 |
+
|
813 |
+
if bottom_title:
|
814 |
+
rows = len(artist.split("\n"))
|
815 |
+
textheight=min(math.ceil( w / 10 ), math.ceil( h / 5 ))
|
816 |
+
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
817 |
+
textwidth = draw.textlength(bottom_title,font)
|
818 |
+
x = math.ceil((w - textwidth) / 2)
|
819 |
+
y = h - (textheight * rows / 2) - (h / 2)
|
820 |
+
y = math.ceil(y + (h / 2 * labels_distance))
|
821 |
+
draw.text((x, y), bottom_title, (0,0,0), font=font, spacing=2, stroke_width=math.ceil(textheight/20), stroke_fill=(255,255,255))
|
822 |
|
823 |
+
working = False
|
824 |
+
|
825 |
+
return img
|
826 |
|
827 |
google_translate_endpoint = "https://translate.google.com/m"
|
828 |
language_codes = {
|
|
|
1534 |
|
1535 |
with gr.Column():
|
1536 |
cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='pil', show_share_button=False)
|
1537 |
+
with gr.Column():
|
1538 |
+
upscale_now = gr.Button("Upscale",elem_classes="btn")
|
1539 |
+
with gr.Column():
|
1540 |
+
top = gr.Textbox(
|
1541 |
+
placeholder="Top title",
|
1542 |
+
value="",
|
1543 |
+
container=False,
|
1544 |
+
max_lines=1
|
1545 |
+
)
|
1546 |
+
bottom = gr.Textbox(
|
1547 |
+
placeholder="Bottom title",
|
1548 |
+
value="",
|
1549 |
+
container=False,
|
1550 |
+
max_lines=1
|
1551 |
+
)
|
1552 |
+
add_titles = gr.Button("Add title(s)",elem_classes="btn")
|
1553 |
gr.on(
|
1554 |
triggers=[run.click],
|
1555 |
fn=handle_generation,
|
|
|
1561 |
inputs=[cover],
|
1562 |
outputs=[cover]
|
1563 |
)
|
1564 |
+
add_titles.click(
|
1565 |
+
fn=add_song_cover_text,
|
1566 |
+
inputs=[cover,top,bottom],
|
1567 |
+
outputs=[cover]
|
1568 |
+
)
|
1569 |
+
|
1570 |
|
1571 |
demo.queue().launch()
|