Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,26 +15,10 @@ def img2text(url):
|
|
| 15 |
|
| 16 |
# text2story
|
| 17 |
def text2story(text):
|
| 18 |
-
pipe = pipeline(
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
max_new_tokens=300, # 预留冗余空间
|
| 22 |
-
min_new_tokens=100,
|
| 23 |
-
do_sample=True,
|
| 24 |
-
temperature=0.65, # 降低随机性
|
| 25 |
-
top_p=0.85,
|
| 26 |
-
top_k=30, # 加速生成
|
| 27 |
-
repetition_penalty=1.3,
|
| 28 |
-
no_repeat_ngram_size=3, # 防止重复短语
|
| 29 |
-
early_stopping=False # 避免提前终止
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# 生成并后处理
|
| 33 |
-
story = pipe(text, return_full_text=False)[0]['generated_text']
|
| 34 |
|
| 35 |
-
# 智能截断机制
|
| 36 |
-
target_length = min(max(len(story.split()), 50), 150)
|
| 37 |
-
return " ".join(story.split()[:target_length])
|
| 38 |
|
| 39 |
# text2audio
|
| 40 |
def text2audio(story_text):
|
|
|
|
| 15 |
|
| 16 |
# text2story
|
| 17 |
def text2story(text):
|
| 18 |
+
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
| 19 |
+
story_text = pipe(text)[0]['generated_text']
|
| 20 |
+
return story_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# text2audio
|
| 24 |
def text2audio(story_text):
|