Leo Liu commited on
Commit
9b6d978
·
verified ·
1 Parent(s): 5b628a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -15
app.py CHANGED
@@ -11,20 +11,6 @@ def img2text(url):
11
 
12
  # text2story
13
  def text2story(text):
14
- # 结构化prompt模板(强制模型遵循起承转合)
15
- prompt = f"""Write a COMPLETE fairy tale for children aged 3-10. Follow these rules:
16
- [STORY STRUCTURE]
17
- 1. BEGINNING: Introduce characters and setting (20-30 words)
18
- 2. MIDDLE: Describe a magical problem (40-60 words)
19
- 3. ENDING: Show how kindness/courage solves it (30-40 words)
20
-
21
- [EXAMPLE]
22
- Input: "a forest with glowing mushrooms"
23
- Output: "Little fox Luna found glowing mushrooms deep in the forest. They were fairy homes! When a storm threatened to destroy them, Luna bravely built a leaf umbrella to protect the tiny homes. The grateful fairies made her forest guardian, and they danced under moonbeams every night."
24
-
25
- [INPUT SCENE]: {text}
26
- [STORY]:""" # 用方括号明确区分指令和内容
27
-
28
  pipe = pipeline(
29
  "text-generation",
30
  model="pranavpsv/genre-story-generator-v2",
@@ -40,7 +26,7 @@ Output: "Little fox Luna found glowing mushrooms deep in the forest. They were f
40
  )
41
 
42
  # 生成并后处理
43
- raw_output = pipe(prompt, return_full_text=False)[0]['generated_text']
44
 
45
  # 提取核心内容(适配模型输出模式)
46
  if "[STORY]:" in raw_output:
 
11
 
12
  # text2story
13
  def text2story(text):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  pipe = pipeline(
15
  "text-generation",
16
  model="pranavpsv/genre-story-generator-v2",
 
26
  )
27
 
28
  # 生成并后处理
29
+ raw_output = pipe(text, return_full_text=False)[0]['generated_text']
30
 
31
  # 提取核心内容(适配模型输出模式)
32
  if "[STORY]:" in raw_output: