Spaces:
Build error
Build error
Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,8 +11,20 @@ def img2text(url):
|
|
| 11 |
|
| 12 |
# text2story
|
| 13 |
def text2story(text):
|
| 14 |
-
pipe = pipeline("text-generation",
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return story_text
|
| 17 |
|
| 18 |
# text2audio
|
|
@@ -36,21 +48,21 @@ def main():
|
|
| 36 |
|
| 37 |
|
| 38 |
#Stage 1: Image to Text
|
| 39 |
-
st.text('
|
| 40 |
scenario = img2text(uploaded_file.name)
|
| 41 |
st.write(scenario)
|
| 42 |
|
| 43 |
#Stage 2: Text to Story
|
| 44 |
-
st.text('Generating
|
| 45 |
story = text2story(scenario)
|
| 46 |
st.write(story)
|
| 47 |
|
| 48 |
#Stage 3: Story to Audio data
|
| 49 |
-
st.text('
|
| 50 |
audio_data =text2audio(story)
|
| 51 |
|
| 52 |
# Play button
|
| 53 |
-
if st.button("Play Audio"):
|
| 54 |
st.audio(audio_data['audio'],
|
| 55 |
format="audio/wav",
|
| 56 |
start_time=0,
|
|
|
|
| 11 |
|
| 12 |
# text2story
|
| 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 |
+
# Make sure the story is complete
|
| 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 |
return story_text
|
| 29 |
|
| 30 |
# text2audio
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
#Stage 1: Image to Text
|
| 51 |
+
st.text('🔍 Analyzing image...')
|
| 52 |
scenario = img2text(uploaded_file.name)
|
| 53 |
st.write(scenario)
|
| 54 |
|
| 55 |
#Stage 2: Text to Story
|
| 56 |
+
st.text('📖 Generating story...')
|
| 57 |
story = text2story(scenario)
|
| 58 |
st.write(story)
|
| 59 |
|
| 60 |
#Stage 3: Story to Audio data
|
| 61 |
+
st.text('🎧 Converting to audio...')
|
| 62 |
audio_data =text2audio(story)
|
| 63 |
|
| 64 |
# Play button
|
| 65 |
+
if st.button("Play Audio Story"):
|
| 66 |
st.audio(audio_data['audio'],
|
| 67 |
format="audio/wav",
|
| 68 |
start_time=0,
|