Spaces:
Build error
Build error
Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,23 +24,28 @@ def text2story(text):
|
|
| 24 |
Story: Once upon a time,"""
|
| 25 |
|
| 26 |
generation_params = {
|
| 27 |
-
"max_new_tokens":200,
|
| 28 |
-
"temperature":0.7,
|
| 29 |
-
"top_p":0.95,
|
| 30 |
-
"repetition_penalty":1.2,
|
| 31 |
-
"do_sample":True,
|
| 32 |
-
"num_return_sequences":1
|
| 33 |
}
|
| 34 |
-
story = pipe (prompt_for_children, **generation_params)[0] ['generated_text']
|
| 35 |
-
return postprocess_text(story)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
for stop_word in ["\nThe end", "The end", "End of story"]:
|
| 40 |
if story_text.endswith(stop_word):
|
| 41 |
story_text = story_text[:-len(stop_word)]
|
|
|
|
|
|
|
| 42 |
last_punct = max(story_text.rfind("."), story_text.rfind("!"), story_text.rfind("?"))
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# text2audio
|
| 46 |
def text2audio(story_text):
|
|
|
|
| 24 |
Story: Once upon a time,"""
|
| 25 |
|
| 26 |
generation_params = {
|
| 27 |
+
"max_new_tokens": 200,
|
| 28 |
+
"temperature": 0.7,
|
| 29 |
+
"top_p": 0.95,
|
| 30 |
+
"repetition_penalty": 1.2,
|
| 31 |
+
"do_sample": True,
|
| 32 |
+
"num_return_sequences": 1
|
| 33 |
}
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
story = pipe(prompt_for_children, **generation_params)[0]['generated_text']
|
| 36 |
+
# Remove prompt words
|
| 37 |
+
story_text = story.replace(prompt_for_children, "").strip()
|
| 38 |
+
|
| 39 |
+
# Remove possible redundant markings at the end
|
| 40 |
for stop_word in ["\nThe end", "The end", "End of story"]:
|
| 41 |
if story_text.endswith(stop_word):
|
| 42 |
story_text = story_text[:-len(stop_word)]
|
| 43 |
+
|
| 44 |
+
# Truncate to the last punctuation point to prevent extra text from being left behind
|
| 45 |
last_punct = max(story_text.rfind("."), story_text.rfind("!"), story_text.rfind("?"))
|
| 46 |
+
if last_punct != -1:
|
| 47 |
+
story_text = story_text[:last_punct+1]
|
| 48 |
+
return story_text
|
| 49 |
|
| 50 |
# text2audio
|
| 51 |
def text2audio(story_text):
|