Yaron Koresh commited on
Commit
284c10d
·
verified ·
1 Parent(s): c5123bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -26
app.py CHANGED
@@ -439,8 +439,6 @@ MAX_SEED = np.iinfo(np.int32).max
439
  # precision data
440
 
441
  seq=512
442
- width=1536
443
- height=1536
444
  image_steps=50
445
  img_accu=9.0
446
 
@@ -461,7 +459,7 @@ footer {
461
  display: none !important;
462
  }
463
  .image-container {
464
- aspect-ratio: """,str(width),"/",str(height),""" !important;
465
  }
466
  .dropdown-arrow {
467
  display: none !important;
@@ -654,12 +652,12 @@ def add_song_cover_text(img,artist,song,height,width):
654
 
655
  return img
656
 
657
- def all_pipes(pos,neg,artist,song):
658
 
659
  imgs = pipe_generate_image(pos,neg)
660
 
661
  for i in range(len(imgs)):
662
- imgs[i] = upscaler(imgs[i])
663
 
664
  return imgs
665
 
@@ -1275,10 +1273,18 @@ def translate(txt,to_lang="en",from_lang="auto"):
1275
  return translation.lower()
1276
 
1277
  @spaces.GPU(duration=240)
1278
- def handle_generation(artist,song,genre,lyrics):
1279
 
1280
  log(f'CALL handle_generate')
1281
 
 
 
 
 
 
 
 
 
1282
  pos_artist = re.sub(r"([ \t]){1,}", " ", artist).upper().strip()
1283
 
1284
  pos_song = re.sub(r"([ \t]){1,}", " ", song).lower().strip()
@@ -1292,17 +1298,14 @@ def handle_generation(artist,song,genre,lyrics):
1292
  if re.sub(r'[\.]$', '', lyrics_lines[line_index]) == lyrics_lines[line_index]:
1293
  lyrics_lines[line_index] = lyrics_lines[line_index].strip() + "."
1294
  lyrics = " ".join(lyrics_lines)
1295
-
1296
- pos_genre = re.sub(r"([ \t]){1,}", " ", genre).lower().strip()
1297
- pos_genre = ' '.join(word[0].upper() + word[1:] for word in pos_genre.split())
1298
 
1299
  pos_lyrics = re.sub(r"([ \t]){1,}", " ", lyrics).lower().strip()
1300
  pos_lyrics = pos_lyrics if pos_lyrics == "" else summarize(translate(pos_lyrics))
1301
  pos_lyrics = re.sub(r"([ \t]){1,}", " ", pos_lyrics).lower().strip()
1302
 
1303
- neg = f"Sexuality, Human body, Human, Textual, Text, Distorted, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low-Quality, Painted, Smooth, Artificial, Phony, Gaudy, Digital Effects."
1304
  q = "\""
1305
- pos = f'{ translate(pos_genre) } song hyper-realistic official image{ pos_lyrics if pos_lyrics == "" else ": " + q + pos_lyrics + q }.'
1306
 
1307
  print(f"""
1308
  Positive: {pos}
@@ -1310,13 +1313,12 @@ def handle_generation(artist,song,genre,lyrics):
1310
  Negative: {neg}
1311
  """)
1312
 
1313
- imgs = all_pipes(pos,neg,pos_artist,pos_song)
1314
 
1315
  index = 1
1316
  names = []
1317
  for img in imgs:
1318
- scaled_by = 2
1319
- labeled_img = add_song_cover_text(img,artist,song,height*scaled_by,width*scaled_by)
1320
  name = f'{artist} - {song} ({index}).png'
1321
  labeled_img.save(name)
1322
  names.append(name)
@@ -1330,24 +1332,18 @@ def handle_generation(artist,song,genre,lyrics):
1330
  if __name__ == "__main__":
1331
  with gr.Blocks(theme=gr.themes.Citrus(),css=css) as demo:
1332
  gr.Markdown(f"""
1333
- # Song Cover Image Generator
1334
  """)
1335
  with gr.Row():
1336
  with gr.Column(scale=4):
1337
  artist = gr.Textbox(
1338
- placeholder="Artist name",
1339
  value="",
1340
  container=False,
1341
  max_lines=1
1342
  )
1343
  song = gr.Textbox(
1344
- placeholder="Song name",
1345
- value="",
1346
- container=False,
1347
- max_lines=1
1348
- )
1349
- genre = gr.Textbox(
1350
- placeholder="Genre",
1351
  value="",
1352
  container=False,
1353
  max_lines=1
@@ -1356,18 +1352,38 @@ if __name__ == "__main__":
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
  lyrics = gr.Textbox(
1362
- placeholder="Lyrics",
1363
  value="",
1364
  container=False,
1365
- max_lines=10000
1366
  )
1367
 
1368
  run.click(
1369
  fn=handle_generation,
1370
- inputs=[artist,song,genre,lyrics],
1371
  outputs=[cover]
1372
  )
1373
 
 
439
  # precision data
440
 
441
  seq=512
 
 
442
  image_steps=50
443
  img_accu=9.0
444
 
 
459
  display: none !important;
460
  }
461
  .image-container {
462
+ aspect-ratio: 1/1 !important;
463
  }
464
  .dropdown-arrow {
465
  display: none !important;
 
652
 
653
  return img
654
 
655
+ def all_pipes(pos,neg,artist,song,factor):
656
 
657
  imgs = pipe_generate_image(pos,neg)
658
 
659
  for i in range(len(imgs)):
660
+ imgs[i] = upscaler(imgs[i],upscale_factor=factor)
661
 
662
  return imgs
663
 
 
1273
  return translation.lower()
1274
 
1275
  @spaces.GPU(duration=240)
1276
+ def handle_generation(artist,song,lyrics,_height,_width):
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()
 
1298
  if re.sub(r'[\.]$', '', lyrics_lines[line_index]) == lyrics_lines[line_index]:
1299
  lyrics_lines[line_index] = lyrics_lines[line_index].strip() + "."
1300
  lyrics = " ".join(lyrics_lines)
 
 
 
1301
 
1302
  pos_lyrics = re.sub(r"([ \t]){1,}", " ", lyrics).lower().strip()
1303
  pos_lyrics = pos_lyrics if pos_lyrics == "" else summarize(translate(pos_lyrics))
1304
  pos_lyrics = re.sub(r"([ \t]){1,}", " ", pos_lyrics).lower().strip()
1305
 
1306
+ neg = f"Sexuality, Nudity, Human body, Human, Textual, Text, Distorted, Fake, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low Quality, Paint, Smoothed, Artificial, Phony, Gaudy, Digital Effects."
1307
  q = "\""
1308
+ pos = f'HQ Hyper-realistic professional photograph{ pos_lyrics if pos_lyrics == "" else ": " + q + pos_lyrics + q }.'
1309
 
1310
  print(f"""
1311
  Positive: {pos}
 
1313
  Negative: {neg}
1314
  """)
1315
 
1316
+ imgs = all_pipes(pos,neg,pos_artist,pos_song,factor)
1317
 
1318
  index = 1
1319
  names = []
1320
  for img in imgs:
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)
 
1332
  if __name__ == "__main__":
1333
  with gr.Blocks(theme=gr.themes.Citrus(),css=css) as demo:
1334
  gr.Markdown(f"""
1335
+ # Image Generator
1336
  """)
1337
  with gr.Row():
1338
  with gr.Column(scale=4):
1339
  artist = gr.Textbox(
1340
+ placeholder="Top label",
1341
  value="",
1342
  container=False,
1343
  max_lines=1
1344
  )
1345
  song = gr.Textbox(
1346
+ placeholder="Bottom label",
 
 
 
 
 
 
1347
  value="",
1348
  container=False,
1349
  max_lines=1
 
1352
 
1353
  with gr.Column():
1354
  cover = gr.Image(interactive=False,container=False,elem_classes="image-container", label="Result", show_label=True, type='filepath', show_share_button=False)
1355
+
1356
+ with gr.Row():
1357
+
1358
+ with gr.Column():
1359
+ width = gr.Slider(
1360
+ label="Width (px)",
1361
+ minimum=512,
1362
+ maximum=3072,
1363
+ step=256,
1364
+ value=1536,
1365
+ )
1366
+
1367
+ with gr.Column():
1368
+ height = gr.Slider(
1369
+ label="Height (px)",
1370
+ minimum=512,
1371
+ maximum=3072,
1372
+ step=256,
1373
+ value=1536,
1374
+ )
1375
 
1376
  with gr.Row():
1377
  lyrics = gr.Textbox(
1378
+ placeholder="Input data",
1379
  value="",
1380
  container=False,
1381
+ max_lines=1000
1382
  )
1383
 
1384
  run.click(
1385
  fn=handle_generation,
1386
+ inputs=[artist,song,lyrics,height,width],
1387
  outputs=[cover]
1388
  )
1389