Yaron Koresh commited on
Commit
10ce892
·
verified ·
1 Parent(s): 17a8d48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -43
app.py CHANGED
@@ -1431,31 +1431,26 @@ def translate(txt,to_lang="en",from_lang="auto"):
1431
  return translation.lower()
1432
 
1433
  @spaces.GPU(duration=300)
1434
- def handle_generation(artist,song,lyrics,h,w):
1435
 
1436
  log(f'CALL handle_generate')
1437
-
1438
- pos_artist = re.sub(r"([ \t]){1,}", " ", artist).upper().strip()
1439
-
1440
- pos_song = re.sub(r"([ \t]){1,}", " ", song).lower().strip()
1441
- pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
1442
 
1443
- lyrics = re.sub(r",( ){1,}",". ",lyrics)
1444
- lyrics_lines = re.split(r"([\n]){1,}", lyrics)
1445
 
1446
- for line_index in range(len(lyrics_lines)):
1447
- lyrics_lines[line_index] = lyrics_lines[line_index].strip()
1448
- if re.sub(r'[\.]$', '', lyrics_lines[line_index]) == lyrics_lines[line_index]:
1449
- lyrics_lines[line_index] = lyrics_lines[line_index].strip() + "."
1450
- lyrics = " ".join(lyrics_lines)
1451
 
1452
- pos_lyrics = re.sub(r"([ \t]){1,}", " ", lyrics).lower().strip()
1453
- pos_lyrics = pos_lyrics if pos_lyrics == "" else summarize(translate(pos_lyrics))
1454
- pos_lyrics = re.sub(r"([ \t]){1,}", " ", pos_lyrics).lower().strip()
1455
 
1456
  neg = f"Textual, Text, Distorted, Fake, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low Quality, Paint, Smoothed, Artificial, Phony, Gaudy, Digital Effects."
1457
  q = "\""
1458
- pos = f'HQ Hyper-realistic professional photograph{ pos_lyrics if pos_lyrics == "" else ": " + q + pos_lyrics + q }.'
1459
 
1460
  print(f"""
1461
  Positive: {pos}
@@ -1463,57 +1458,45 @@ def handle_generation(artist,song,lyrics,h,w):
1463
  Negative: {neg}
1464
  """)
1465
 
1466
- return add_song_cover_text(pipe_generate_image(pos,neg,h,w),pos_artist,pos_song,h,w)
1467
 
1468
  # entry
1469
 
1470
  if __name__ == "__main__":
1471
  with gr.Blocks(theme=gr.themes.Citrus(),css=css) as demo:
1472
  gr.Markdown(f"""
1473
- # Text to Image
1474
  """)
1475
  gr.Markdown(f"""
1476
- ## Multilingual. Realistic. Top & Bottom titles.
1477
  """)
1478
 
1479
  with gr.Row():
1480
- with gr.Column(scale=2):
1481
- artist = gr.Textbox(
1482
- placeholder="Top title",
1483
- value="",
1484
- container=False,
1485
- max_lines=1
1486
- )
1487
- song = gr.Textbox(
1488
- placeholder="Bottom title",
1489
- value="",
1490
- container=False,
1491
- max_lines=1
1492
- )
1493
 
1494
- run = gr.Button("Generate",elem_classes="btn")
1495
-
1496
- width = gr.Slider(
1497
- label="Width (px)",
1498
  minimum=512,
1499
  maximum=2048,
1500
  step=16,
1501
  value=1024,
1502
  )
1503
 
1504
- height = gr.Slider(
1505
- label="Height (px)",
1506
  minimum=512,
1507
  maximum=2048,
1508
  step=16,
1509
  value=1024,
1510
  )
 
 
1511
 
1512
- lyrics = gr.Textbox(
1513
- placeholder="Textual data (multilingual)",
1514
  value="",
1515
  container=False,
1516
- max_lines=1000
1517
  )
1518
 
1519
  with gr.Column():
@@ -1522,7 +1505,7 @@ if __name__ == "__main__":
1522
 
1523
  run.click(
1524
  fn=handle_generation,
1525
- inputs=[artist,song,lyrics,height,width],
1526
  outputs=[cover]
1527
  )
1528
  upscale_now.click(
 
1431
  return translation.lower()
1432
 
1433
  @spaces.GPU(duration=300)
1434
+ def handle_generation(h,w,d):
1435
 
1436
  log(f'CALL handle_generate')
 
 
 
 
 
1437
 
1438
+ d = re.sub(r",( ){1,}",". ",d)
1439
+ d_lines = re.split(r"([\n]){1,}", d)
1440
 
1441
+ for line_index in range(len(d_lines)):
1442
+ d_lines[line_index] = d_lines[line_index].strip()
1443
+ if re.sub(r'[\.]$', '', d_lines[line_index]) == d_lines[line_index]:
1444
+ d_lines[line_index] = d_lines[line_index].strip() + "."
1445
+ d = " ".join(d_lines)
1446
 
1447
+ pos_d = re.sub(r"([ \t]){1,}", " ", d).lower().strip()
1448
+ pos_d = pos_d if pos_d == "" else summarize(translate(pos_d))
1449
+ pos_d = re.sub(r"([ \t]){1,}", " ", pos_d).lower().strip()
1450
 
1451
  neg = f"Textual, Text, Distorted, Fake, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low Quality, Paint, Smoothed, Artificial, Phony, Gaudy, Digital Effects."
1452
  q = "\""
1453
+ pos = f'HQ Hyper-realistic professional photograph{ pos_d if pos_d == "" else ": " + pos_d }.'
1454
 
1455
  print(f"""
1456
  Positive: {pos}
 
1458
  Negative: {neg}
1459
  """)
1460
 
1461
+ return pipe_generate_image(pos,neg,h,w)
1462
 
1463
  # entry
1464
 
1465
  if __name__ == "__main__":
1466
  with gr.Blocks(theme=gr.themes.Citrus(),css=css) as demo:
1467
  gr.Markdown(f"""
1468
+ # Text-to-Image generator
1469
  """)
1470
  gr.Markdown(f"""
1471
+ ### Realistic. Upscalable. Multilingual.
1472
  """)
1473
 
1474
  with gr.Row():
1475
+ with gr.Column(scale=3):
 
 
 
 
 
 
 
 
 
 
 
 
1476
 
1477
+ height = gr.Slider(
1478
+ label="Height (px)",
 
 
1479
  minimum=512,
1480
  maximum=2048,
1481
  step=16,
1482
  value=1024,
1483
  )
1484
 
1485
+ width = gr.Slider(
1486
+ label="Width (px)",
1487
  minimum=512,
1488
  maximum=2048,
1489
  step=16,
1490
  value=1024,
1491
  )
1492
+
1493
+ run = gr.Button("Generate",elem_classes="btn")
1494
 
1495
+ data = gr.Textbox(
1496
+ placeholder="Input data",
1497
  value="",
1498
  container=False,
1499
+ max_lines=100
1500
  )
1501
 
1502
  with gr.Column():
 
1505
 
1506
  run.click(
1507
  fn=handle_generation,
1508
+ inputs=[height,width,data],
1509
  outputs=[cover]
1510
  )
1511
  upscale_now.click(