yaron123 commited on
Commit
b1aeecd
·
1 Parent(s): 9d7dc73
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -120,12 +120,14 @@ function custom(){
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 summarize_text(text, model_name="google/pegasus-xsum", max_length=30, num_beams=4, early_stopping=True):
 
 
 
 
 
129
  return pegasus_tokenizer.decode( pegasus_model.generate(
130
  pegasus_tokenizer(text,return_tensors="pt").input_ids,
131
  max_length=max_length,
@@ -137,7 +139,7 @@ def generate_random_string(length):
137
  characters = str(ascii_letters + digits)
138
  return ''.join(random.choice(characters) for _ in range(length))
139
 
140
- @spaces.GPU()
141
  def pipe_generate(p1,p2):
142
  return image_pipe(
143
  prompt=p1,
@@ -160,7 +162,7 @@ def handle_generate(artist,song,genre,lyrics):
160
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", lyrics)).lower().strip()
161
  pos_lyrics_sum = summarize_text(pos_lyrics)
162
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry"
163
- pos = f'Realistic Natural Genuine Reasonable Detailed, { pos_genre } GENRE SONG - { pos_song }: "{ pos_lyrics_sum }"'
164
 
165
  print(f"""
166
  Positive: {pos}
 
120
  image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.bfloat16).to(device)
121
  image_pipe.enable_model_cpu_offload()
122
 
 
 
 
123
  # functionality
124
 
125
+ @spaces.GPU(duration=40)
126
+ def summarize_text(
127
+ text, max_length=60, num_beams=4, early_stopping=True,
128
+ pegasus_tokenizer = PegasusTokenizerFast.from_pretrained("google/pegasus-xsum"),
129
+ pegasus_model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
130
+ ):
131
  return pegasus_tokenizer.decode( pegasus_model.generate(
132
  pegasus_tokenizer(text,return_tensors="pt").input_ids,
133
  max_length=max_length,
 
139
  characters = str(ascii_letters + digits)
140
  return ''.join(random.choice(characters) for _ in range(length))
141
 
142
+ @spaces.GPU(duration=80)
143
  def pipe_generate(p1,p2):
144
  return image_pipe(
145
  prompt=p1,
 
162
  pos_lyrics = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", lyrics)).lower().strip()
163
  pos_lyrics_sum = summarize_text(pos_lyrics)
164
  neg = f"Textual Labeled Distorted Discontinuous Ugly Blurry"
165
+ pos = f'Realistic Natural Genuine Reasonable Detailed { pos_genre } GENRE { pos_song } "{ pos_lyrics_sum }"'
166
 
167
  print(f"""
168
  Positive: {pos}