Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -631,9 +631,9 @@ def add_song_cover_text(img,artist,song,height,width):
|
|
631 |
|
632 |
draw = ImageDraw.Draw(img,mode="RGBA")
|
633 |
|
634 |
-
rows = 1
|
635 |
labels_distance = 1/3
|
636 |
|
|
|
637 |
textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
|
638 |
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
639 |
textwidth = draw.textlength(song,font)
|
@@ -642,6 +642,7 @@ def add_song_cover_text(img,artist,song,height,width):
|
|
642 |
y = math.ceil(y - (height / 2 * labels_distance))
|
643 |
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))
|
644 |
|
|
|
645 |
textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
|
646 |
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
647 |
textwidth = draw.textlength(artist,font)
|
@@ -652,7 +653,11 @@ def add_song_cover_text(img,artist,song,height,width):
|
|
652 |
|
653 |
return img
|
654 |
|
655 |
-
|
|
|
|
|
|
|
|
|
656 |
|
657 |
imgs = pipe_generate_image(pos,neg)
|
658 |
|
@@ -1272,19 +1277,11 @@ def translate(txt,to_lang="en",from_lang="auto"):
|
|
1272 |
log(f'RET translate with translation as {translation}')
|
1273 |
return translation.lower()
|
1274 |
|
1275 |
-
@spaces.GPU(duration=
|
1276 |
-
def handle_generation(artist,song,lyrics,
|
1277 |
|
1278 |
log(f'CALL handle_generate')
|
1279 |
-
|
1280 |
-
scaled_by = 4
|
1281 |
-
|
1282 |
-
global height
|
1283 |
-
global width
|
1284 |
-
|
1285 |
-
height = _height / scaled_by
|
1286 |
-
width = _width / scaled_by
|
1287 |
-
|
1288 |
pos_artist = re.sub(r"([ \t]){1,}", " ", artist).upper().strip()
|
1289 |
|
1290 |
pos_song = re.sub(r"([ \t]){1,}", " ", song).lower().strip()
|
@@ -1313,19 +1310,14 @@ def handle_generation(artist,song,lyrics,_height,_width):
|
|
1313 |
Negative: {neg}
|
1314 |
""")
|
1315 |
|
1316 |
-
|
1317 |
|
1318 |
-
|
1319 |
-
|
1320 |
-
|
1321 |
-
labeled_img = add_song_cover_text(img,artist,song,_height,_width)
|
1322 |
-
name = f'{artist} - {song} ({index}).png'
|
1323 |
-
labeled_img.save(name)
|
1324 |
-
names.append(name)
|
1325 |
-
index = index + 1
|
1326 |
|
1327 |
# return names
|
1328 |
-
return
|
1329 |
|
1330 |
# entry
|
1331 |
|
@@ -1344,18 +1336,27 @@ if __name__ == "__main__":
|
|
1344 |
placeholder="Top title",
|
1345 |
value="",
|
1346 |
container=False,
|
1347 |
-
max_lines=
|
1348 |
)
|
1349 |
song = gr.Textbox(
|
1350 |
placeholder="Bottom title",
|
1351 |
value="",
|
1352 |
container=False,
|
1353 |
-
max_lines=
|
1354 |
)
|
1355 |
run = gr.Button("Generate",elem_classes="btn")
|
1356 |
|
1357 |
with gr.Column():
|
1358 |
cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1359 |
|
1360 |
with gr.Row():
|
1361 |
|
@@ -1390,5 +1391,10 @@ if __name__ == "__main__":
|
|
1390 |
inputs=[artist,song,lyrics,height,width],
|
1391 |
outputs=[cover]
|
1392 |
)
|
|
|
|
|
|
|
|
|
|
|
1393 |
|
1394 |
demo.queue().launch()
|
|
|
631 |
|
632 |
draw = ImageDraw.Draw(img,mode="RGBA")
|
633 |
|
|
|
634 |
labels_distance = 1/3
|
635 |
|
636 |
+
rows = len(song.split("\n"))
|
637 |
textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
|
638 |
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
639 |
textwidth = draw.textlength(song,font)
|
|
|
642 |
y = math.ceil(y - (height / 2 * labels_distance))
|
643 |
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))
|
644 |
|
645 |
+
rows = len(artist.split("\n"))
|
646 |
textheight=min(math.ceil( width / 10 ), math.ceil( height / 5 ))
|
647 |
font = ImageFont.truetype(r"Alef-Bold.ttf", textheight)
|
648 |
textwidth = draw.textlength(artist,font)
|
|
|
653 |
|
654 |
return img
|
655 |
|
656 |
+
spaces.GPU(300)
|
657 |
+
def upscale_image(img,factor):
|
658 |
+
return upscaler(img,upscale_factor=factor)
|
659 |
+
|
660 |
+
def all_pipes(pos,neg,artist,song):
|
661 |
|
662 |
imgs = pipe_generate_image(pos,neg)
|
663 |
|
|
|
1277 |
log(f'RET translate with translation as {translation}')
|
1278 |
return translation.lower()
|
1279 |
|
1280 |
+
@spaces.GPU(duration=300)
|
1281 |
+
def handle_generation(artist,song,lyrics,height,width):
|
1282 |
|
1283 |
log(f'CALL handle_generate')
|
1284 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1285 |
pos_artist = re.sub(r"([ \t]){1,}", " ", artist).upper().strip()
|
1286 |
|
1287 |
pos_song = re.sub(r"([ \t]){1,}", " ", song).lower().strip()
|
|
|
1310 |
Negative: {neg}
|
1311 |
""")
|
1312 |
|
1313 |
+
img = all_pipes(pos,neg,pos_artist,pos_song)[0]
|
1314 |
|
1315 |
+
labeled_img = add_song_cover_text(img,artist,song,height,width)
|
1316 |
+
name = f'{generate_random_string(8)}.png'
|
1317 |
+
labeled_img.save(name)
|
|
|
|
|
|
|
|
|
|
|
1318 |
|
1319 |
# return names
|
1320 |
+
return name
|
1321 |
|
1322 |
# entry
|
1323 |
|
|
|
1336 |
placeholder="Top title",
|
1337 |
value="",
|
1338 |
container=False,
|
1339 |
+
max_lines=2
|
1340 |
)
|
1341 |
song = gr.Textbox(
|
1342 |
placeholder="Bottom title",
|
1343 |
value="",
|
1344 |
container=False,
|
1345 |
+
max_lines=2
|
1346 |
)
|
1347 |
run = gr.Button("Generate",elem_classes="btn")
|
1348 |
|
1349 |
with gr.Column():
|
1350 |
cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
|
1351 |
+
up_scale_factor = gr.Slider(
|
1352 |
+
label="Upscale",
|
1353 |
+
minimum=2,
|
1354 |
+
maximum=4,
|
1355 |
+
step=1,
|
1356 |
+
value=3,
|
1357 |
+
)
|
1358 |
+
upscale_now = gr.Button("Upscale",elem_classes="btn")
|
1359 |
+
|
1360 |
|
1361 |
with gr.Row():
|
1362 |
|
|
|
1391 |
inputs=[artist,song,lyrics,height,width],
|
1392 |
outputs=[cover]
|
1393 |
)
|
1394 |
+
upscale_now.click(
|
1395 |
+
fn=upscale_image,
|
1396 |
+
inputs=[cover,up_scale_factor],
|
1397 |
+
outputs=[cover]
|
1398 |
+
)
|
1399 |
|
1400 |
demo.queue().launch()
|