Spaces:
Build error
Build error
Leo Liu commited on
Update app.py
Browse files
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,
|
| 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 |
|