Leo Liu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import streamlit as st
|
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS
|
5 |
import io
|
6 |
-
import re
|
7 |
|
8 |
|
9 |
# function part
|
@@ -18,6 +17,10 @@ def img2text(url):
|
|
18 |
def text2story(text):
|
19 |
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2", max_new_tokens=160, min_new_tokens=130, num_return_sequences=1)
|
20 |
story_text = pipe(text)[0]['generated_text']
|
|
|
|
|
|
|
|
|
21 |
return story_text
|
22 |
|
23 |
|
|
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS
|
5 |
import io
|
|
|
6 |
|
7 |
|
8 |
# function part
|
|
|
17 |
def text2story(text):
|
18 |
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2", max_new_tokens=160, min_new_tokens=130, num_return_sequences=1)
|
19 |
story_text = pipe(text)[0]['generated_text']
|
20 |
+
# Make sure the output is complete sentences
|
21 |
+
last_punctuation = max(story_text.rfind("."), story_text.rfind("!"), story_text.rfind("?"))
|
22 |
+
if last_punctuation != -1:
|
23 |
+
story_text = story_text[:last_punctuation+1]
|
24 |
return story_text
|
25 |
|
26 |
|