Spaces:
Sleeping
Sleeping
commit
Browse files
app.py
CHANGED
@@ -125,6 +125,14 @@ pegasus_model = PegasusForConditionalGeneration.from_pretrained(pegasus_name)
|
|
125 |
|
126 |
# functionality
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
def generate_random_string(length):
|
129 |
characters = str(ascii_letters + digits)
|
130 |
return ''.join(random.choice(characters) for _ in range(length))
|
@@ -150,7 +158,7 @@ def handle_generate(artist,song,genre,lyrics):
|
|
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 =
|
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 |
|
|
|
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(pos_lyrics,return_tensors="pt").input_ids,
|
131 |
+
max_length=max_length,
|
132 |
+
num_beams=num_beams,
|
133 |
+
early_stopping=early_stopping
|
134 |
+
)[0], skip_special_tokens=True)
|
135 |
+
|
136 |
def generate_random_string(length):
|
137 |
characters = str(ascii_letters + digits)
|
138 |
return ''.join(random.choice(characters) for _ in range(length))
|
|
|
158 |
pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
|
159 |
pos_genre = re.sub(f'[{punctuation}]', '', re.sub("([ \t\n]){1,}", " ", genre)).upper().strip()
|
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 |
|