yaron123 commited on
Commit
b0bb2c9
·
1 Parent(s): 967bc0b
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -25,6 +25,7 @@ from huggingface_hub import hf_hub_download
25
  from safetensors.torch import load_file, save_file
26
  from diffusers import FluxPipeline
27
  from PIL import Image, ImageDraw, ImageFont
 
28
 
29
  # logging
30
 
@@ -45,6 +46,7 @@ else:
45
  device = "cpu"
46
 
47
  base = "black-forest-labs/FLUX.1-schnell"
 
48
 
49
  # precision data
50
 
@@ -118,6 +120,9 @@ function custom(){
118
  image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.bfloat16).to(device)
119
  image_pipe.enable_model_cpu_offload()
120
 
 
 
 
121
  # functionality
122
 
123
  def generate_random_string(length):
@@ -145,8 +150,9 @@ def handle_generate(artist,song,genre,lyrics):
145
  pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
146
  pos_genre = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", genre)).upper().strip()
147
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", lyrics)).lower().strip()
 
148
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry"
149
- pos = f'Realistic Natural Genuine Reasonable Detailed { pos_genre } GENRE SONG COVER FOR { pos_song }: "{ pos_lyrics }"'
150
 
151
  print(f"""
152
  Positive: {pos}
 
25
  from safetensors.torch import load_file, save_file
26
  from diffusers import FluxPipeline
27
  from PIL import Image, ImageDraw, ImageFont
28
+ from transformers import PegasusForConditionalGeneration, PegasusTokenizerFast
29
 
30
  # logging
31
 
 
46
  device = "cpu"
47
 
48
  base = "black-forest-labs/FLUX.1-schnell"
49
+ pegasus_name = "google/pegasus-xsum"
50
 
51
  # precision data
52
 
 
120
  image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.bfloat16).to(device)
121
  image_pipe.enable_model_cpu_offload()
122
 
123
+ pegasus_tokenizer = PegasusTokenizerFast.from_pretrained(pegasus_name)
124
+ pegasus_model = PegasusForConditionalGeneration.from_pretrained(pegasus_name)
125
+
126
  # functionality
127
 
128
  def generate_random_string(length):
 
150
  pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
151
  pos_genre = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", genre)).upper().strip()
152
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", lyrics)).lower().strip()
153
+ pos_lyrics_sum = pegasus_tokenizer.decode(pegasus_model.generate(pegasus_tokenizer(pos_lyrics,return_tensors="pt").input_ids)[0], skip_special_tokens=True)
154
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry"
155
+ pos = f'Realistic Natural Genuine Reasonable Detailed, { pos_genre } GENRE SONG - { pos_song }: "{ pos_lyrics_sum }"'
156
 
157
  print(f"""
158
  Positive: {pos}