Yaron Koresh commited on
Commit
302c3d1
·
verified ·
1 Parent(s): 78cc42c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -565,16 +565,16 @@ def _summarize(text):
565
  toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
566
  gen = model.generate(
567
  toks,
568
- length_penalty=3.0,
569
- num_beams=math.ceil(len(text.split()) / 6),
570
  early_stopping=True,
571
- max_length=math.ceil(len(text.split()) / 4)
572
  )
573
  ret = tokenizer.decode(gen[0], skip_special_tokens=True)
574
  log(f'RET _summarize with ret as {ret}')
575
  return ret
576
 
577
- def summarize(text, max_words=20):
578
  log(f'CALL summarize')
579
 
580
  words = text.split()
@@ -590,12 +590,10 @@ def summarize(text, max_words=20):
590
  words_length = len(text.split())
591
 
592
  if words_length >= 510:
593
- shrink_step = 500 // (len(text.split()) / 500)
594
  while words_length >= 510:
595
  words = text.split()
596
- above_limit = words[510:]
597
  text = _summarize(
598
- " ".join(words[0:510]), shrink_step
599
  ) + " ".join(words[510:])
600
  words_length = len(text.split())
601
 
@@ -1296,9 +1294,9 @@ def handle_generation(artist,song,genre,lyrics):
1296
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub(r"([ \t]){1,}", " ", lyrics)).lower().strip()
1297
  pos_lyrics_sum = pos_lyrics if pos_lyrics == "" else summarize(translate(pos_lyrics))
1298
 
1299
- neg = f"Sexuality, Humanity, Textual, Labeled, Distorted, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low-Quality, Painted, Smoothed, Artificial, Phony, Gaudy, Digital Effects."
1300
  q = "\""
1301
- pos = f'HQ Hyper-realistic { translate(pos_genre) } song "{ translate(pos_song) }"{ pos_lyrics_sum if pos_lyrics_sum == "" else ": " + pos_lyrics_sum }.'
1302
 
1303
  print(f"""
1304
  Positive: {pos}
 
565
  toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
566
  gen = model.generate(
567
  toks,
568
+ length_penalty=0.1,
569
+ num_beams=16,
570
  early_stopping=True,
571
+ max_length=512
572
  )
573
  ret = tokenizer.decode(gen[0], skip_special_tokens=True)
574
  log(f'RET _summarize with ret as {ret}')
575
  return ret
576
 
577
+ def summarize(text, max_words=10):
578
  log(f'CALL summarize')
579
 
580
  words = text.split()
 
590
  words_length = len(text.split())
591
 
592
  if words_length >= 510:
 
593
  while words_length >= 510:
594
  words = text.split()
 
595
  text = _summarize(
596
+ " ".join(words[0:510])
597
  ) + " ".join(words[510:])
598
  words_length = len(text.split())
599
 
 
1294
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub(r"([ \t]){1,}", " ", lyrics)).lower().strip()
1295
  pos_lyrics_sum = pos_lyrics if pos_lyrics == "" else summarize(translate(pos_lyrics))
1296
 
1297
+ neg = f"Sexuality, Human body, Human, Textual, Labeled, Distorted, Discontinuous, Blurry, Doll-Like, Overly Plastic, Low-Quality, Painted, Smooth, Artificial, Phony, Gaudy, Digital Effects."
1298
  q = "\""
1299
+ pos = f'{ translate(pos_genre) } song hyper-realistic official image{ pos_lyrics_sum if pos_lyrics_sum == "" else ": " + pos_lyrics_sum }.'
1300
 
1301
  print(f"""
1302
  Positive: {pos}