Leo Liu commited on
Commit
26ee4b9
·
verified ·
1 Parent(s): 4a46673

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -13,19 +13,16 @@ def img2text(url):
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
  story_text = pipe(text,
19
- do_sample=True, # 启用随机采样
20
- temperature=0.9, # 控制随机性(0-1,越大越有创意)
21
- top_k=50, # 限制采样词汇量
22
  num_return_sequences=1)[0]['generated_text']
23
-
24
- # 确保输出以完整句子结尾
25
  last_punctuation = max(story_text.rfind("."), story_text.rfind("!"), story_text.rfind("?"))
26
  if last_punctuation != -1:
27
  story_text = story_text[:last_punctuation+1]
28
-
29
  safe_story = story_text.replace("violence", "").replace("scary", "").replace("died", "solved")
30
  return safe_story
31
 
 
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
  story_text = pipe(text,
19
+ do_sample=True,
20
+ temperature=0.9,
21
+ top_k=50,
22
  num_return_sequences=1)[0]['generated_text']
 
 
23
  last_punctuation = max(story_text.rfind("."), story_text.rfind("!"), story_text.rfind("?"))
24
  if last_punctuation != -1:
25
  story_text = story_text[:last_punctuation+1]
 
26
  safe_story = story_text.replace("violence", "").replace("scary", "").replace("died", "solved")
27
  return safe_story
28