Yaron Koresh commited on
Commit
9a76642
·
verified ·
1 Parent(s): 3d320f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -31,7 +31,7 @@ from huggingface_hub import hf_hub_download
31
  from safetensors.torch import load_file, save_file
32
  from diffusers import FluxPipeline
33
  from PIL import Image, ImageDraw, ImageFont
34
- from transformers import pipeline
35
  from refiners.fluxion.utils import manual_seed
36
  from refiners.foundationals.latent_diffusion import Solver, solvers
37
  from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler import (
@@ -40,6 +40,9 @@ from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler i
40
  )
41
  from datetime import datetime
42
 
 
 
 
43
  def log(msg):
44
  print(f'{datetime.now().time()} {msg}')
45
 
@@ -546,11 +549,18 @@ def upscaler(
546
  return enhanced_image
547
 
548
  def summarize_text(
549
- text
550
  ):
551
  log(f'CALL summarize_text')
552
- summ = pipeline("summarization", model="Falconsai/text_summarization")
553
- summary = summ(text, do_sample=False)[0]["summary_text"]
 
 
 
 
 
 
 
554
  log(f'RET summarize_text with summary as {summary}')
555
  return summary
556
 
@@ -638,7 +648,7 @@ def handle_generation(artist,song,genre,lyrics):
638
  index = 1
639
  names = []
640
  for img in imgs:
641
- scaled_by = 4
642
  labeled_img = add_song_cover_text(img,artist,song,height*scaled_by,width*scaled_by)
643
  name = f'{artist} - {song} ({index}).png'
644
  labeled_img.save(name)
 
31
  from safetensors.torch import load_file, save_file
32
  from diffusers import FluxPipeline
33
  from PIL import Image, ImageDraw, ImageFont
34
+ from transformers import pipeline, T5ForConditionalGeneration, T5Tokenizer
35
  from refiners.fluxion.utils import manual_seed
36
  from refiners.foundationals.latent_diffusion import Solver, solvers
37
  from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler import (
 
40
  )
41
  from datetime import datetime
42
 
43
+ model = T5ForConditionalGeneration.from_pretrained("t5-large")
44
+ tokenizer = T5Tokenizer.from_pretrained("t5-large")
45
+
46
  def log(msg):
47
  print(f'{datetime.now().time()} {msg}')
48
 
 
549
  return enhanced_image
550
 
551
  def summarize_text(
552
+ text, max_len=20, min_len=10
553
  ):
554
  log(f'CALL summarize_text')
555
+ inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=float('inf'), truncation=False)
556
+ while len(inputs[0]) > max_len:
557
+ inputs[0][:512] = model.generate(
558
+ inputs[0][:512],
559
+ length_penalty=2.0,
560
+ num_beams=4,
561
+ early_stopping=True
562
+ )
563
+ summary = tokenizer.decode(inputs[0])
564
  log(f'RET summarize_text with summary as {summary}')
565
  return summary
566
 
 
648
  index = 1
649
  names = []
650
  for img in imgs:
651
+ scaled_by = 2
652
  labeled_img = add_song_cover_text(img,artist,song,height*scaled_by,width*scaled_by)
653
  name = f'{artist} - {song} ({index}).png'
654
  labeled_img.save(name)