Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,19 +16,8 @@ def img2text(url):
|
|
| 16 |
|
| 17 |
# text2story
|
| 18 |
def text2story(text):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
Write a children's story for ages 3-10 based on: {text}
|
| 22 |
-
Requirements:
|
| 23 |
-
1. Use simple words (1st-3rd grade level)
|
| 24 |
-
2. Main character must be an animal
|
| 25 |
-
3. Include magic elements
|
| 26 |
-
4. Have a happy ending
|
| 27 |
-
5. Story length: 100-120 words
|
| 28 |
-
[PROMPT_END]
|
| 29 |
-
"""
|
| 30 |
-
|
| 31 |
-
# 生成完整提示词(避免重复插入)
|
| 32 |
full_prompt = prompt_template.format(text=text)
|
| 33 |
|
| 34 |
# 初始化生成管道
|
|
@@ -38,7 +27,7 @@ Requirements:
|
|
| 38 |
max_new_tokens=180,
|
| 39 |
min_new_tokens=130,
|
| 40 |
temperature=0.7,
|
| 41 |
-
pad_token_id=50256
|
| 42 |
)
|
| 43 |
|
| 44 |
# 生成原始文本
|
|
@@ -64,7 +53,7 @@ Requirements:
|
|
| 64 |
|
| 65 |
# text2audio
|
| 66 |
def text2audio(story_text):
|
| 67 |
-
tts = gTTS(text=story_text, lang='en')
|
| 68 |
audio_bytes = io.BytesIO()
|
| 69 |
tts.write_to_fp(audio_bytes)
|
| 70 |
audio_bytes.seek(0)
|
|
|
|
| 16 |
|
| 17 |
# text2story
|
| 18 |
def text2story(text):
|
| 19 |
+
prompt_template = f"Write a children's story for ages 3-10 based on: {text}"
|
| 20 |
+
# 生成完整提示词(避免重复插入)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
full_prompt = prompt_template.format(text=text)
|
| 22 |
|
| 23 |
# 初始化生成管道
|
|
|
|
| 27 |
max_new_tokens=180,
|
| 28 |
min_new_tokens=130,
|
| 29 |
temperature=0.7,
|
| 30 |
+
pad_token_id=50256 # 添加模型专用参数
|
| 31 |
)
|
| 32 |
|
| 33 |
# 生成原始文本
|
|
|
|
| 53 |
|
| 54 |
# text2audio
|
| 55 |
def text2audio(story_text):
|
| 56 |
+
tts = gTTS(text = story_text, lang='en')
|
| 57 |
audio_bytes = io.BytesIO()
|
| 58 |
tts.write_to_fp(audio_bytes)
|
| 59 |
audio_bytes.seek(0)
|