Spaces:
Build error
Build error
Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,7 @@ def img2text(url):
|
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
pipe = pipeline("text-generation",
|
| 15 |
-
model="pranavpsv/genre-story-generator-v2"
|
| 16 |
-
max_new_tokens=100,
|
| 17 |
-
truncation=True)
|
| 18 |
prompt_for_children = f"""Generate a fairy tale for children aged 3-10 based on: {text}.
|
| 19 |
Requirements:
|
| 20 |
1. Simple and interesting plot
|
|
@@ -23,21 +21,18 @@ def text2story(text):
|
|
| 23 |
4. Use simple vocabulary (under 500 Lexile)
|
| 24 |
5. Short sentences (max 15 words)
|
| 25 |
6. Add onomatopoeia like 'Boom!', 'Whoosh!' etc.
|
| 26 |
-
|
| 27 |
Story: Once upon a time,"""
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
story_text = story_text[:last_punctuation+1]
|
| 40 |
-
return story_text
|
| 41 |
|
| 42 |
# Post-processing optimization
|
| 43 |
story_text = story_text.replace(prompt, "").strip()
|
|
|
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
pipe = pipeline("text-generation",
|
| 15 |
+
model="pranavpsv/genre-story-generator-v2")
|
|
|
|
|
|
|
| 16 |
prompt_for_children = f"""Generate a fairy tale for children aged 3-10 based on: {text}.
|
| 17 |
Requirements:
|
| 18 |
1. Simple and interesting plot
|
|
|
|
| 21 |
4. Use simple vocabulary (under 500 Lexile)
|
| 22 |
5. Short sentences (max 15 words)
|
| 23 |
6. Add onomatopoeia like 'Boom!', 'Whoosh!' etc.
|
|
|
|
| 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, **generation_params)[0] ['generated_text']
|
| 35 |
+
return postprocess_text(story)
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# Post-processing optimization
|
| 38 |
story_text = story_text.replace(prompt, "").strip()
|