Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,18 @@ def img2text(url):
|
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return story_text
|
| 17 |
|
|
|
|
| 18 |
# text2audio
|
| 19 |
def text2audio(story_text):
|
| 20 |
pipe = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
|
|
|
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 15 |
+
# 构造更详细的提示,要求生成适合3-10岁儿童阅读的童话故事,并控制输出为50-150 words
|
| 16 |
+
prompt = (
|
| 17 |
+
f"Write a complete fairy tale story for children aged 3-10. "
|
| 18 |
+
f"The story should be engaging, imaginative, and written in clear simple language. "
|
| 19 |
+
f"Make sure the story is between 50 and 150 words. "
|
| 20 |
+
f"Use the following scene description as inspiration: {text}"
|
| 21 |
+
)
|
| 22 |
+
# 调整生成参数,确保输出长度合适且不被截断
|
| 23 |
+
story_text = pipe(prompt, max_length=200, min_length=50, do_sample=True, top_p=0.95, temperature=0.8)[0]['generated_text']
|
| 24 |
return story_text
|
| 25 |
|
| 26 |
+
|
| 27 |
# text2audio
|
| 28 |
def text2audio(story_text):
|
| 29 |
pipe = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
|