ElvisTsang commited on
Commit
5c5debf
Β·
verified Β·
1 Parent(s): 6254442

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -14,7 +14,7 @@ def text2story(text):
14
  generated = story_generator(prompt, max_new_tokens=150, do_sample=True)
15
  story_text = generated[0]['generated_text']
16
 
17
- # Remove leading ". " if present
18
  story_text = re.sub(r'^\s*[.,!?;:]+\s*', '', story_text)
19
  story_text = story_text.lstrip()
20
 
@@ -55,25 +55,31 @@ def text2audio(story_text):
55
  audio_output = audio_generator(story_text)
56
  return audio_output
57
 
58
- st.set_page_config(page_title="Once Upon A Time - Storytelling Application", page_icon="πŸ“–")
59
- st.header("Create a story of yours with an image!πŸ§™")
60
- uploaded_file = st.file_uploader("Upload an image for creating your story!")
61
 
62
- if uploaded_file is not None:
63
- print(uploaded_file)
64
- bytes_data = uploaded_file.getvalue()
65
- with open(uploaded_file.name, "wb") as file:
66
- file.write(bytes_data)
67
- st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
68
 
69
- st.text('Entering the scene...🏰')
70
- scenario = img2text(uploaded_file.name)
71
- st.write(scenario)
 
 
72
 
73
- st.text('Your story is going to begin...πŸ¦„')
74
- story = text2story(scenario)
75
- st.write(story)
76
 
77
- st.text('Your story is going to be told...🎧')
78
- audio_data = text2audio(story)
79
- st.audio(audio_data['audio'], format="audio/wav", start_time=0, sample_rate = audio_data['sampling_rate'])
 
 
 
 
 
 
 
 
 
 
 
 
14
  generated = story_generator(prompt, max_new_tokens=150, do_sample=True)
15
  story_text = generated[0]['generated_text']
16
 
17
+ # Remove leading punctuation if present
18
  story_text = re.sub(r'^\s*[.,!?;:]+\s*', '', story_text)
19
  story_text = story_text.lstrip()
20
 
 
55
  audio_output = audio_generator(story_text)
56
  return audio_output
57
 
58
+ def main():
59
+ st.set_page_config(page_title="Once Upon A Time - Storytelling Application", page_icon="πŸ“–")
60
+ st.header("Create a story of yours with an image!πŸ§™")
61
 
62
+ uploaded_file = st.file_uploader("Upload an image for creating your story!")
 
 
 
 
 
63
 
64
+ if uploaded_file is not None:
65
+ # Save the file
66
+ bytes_data = uploaded_file.getvalue()
67
+ with open(uploaded_file.name, "wb") as file:
68
+ file.write(bytes_data)
69
 
70
+ st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
 
 
71
 
72
+ st.text('Entering the scene...🏰')
73
+ scenario = img2text(uploaded_file.name)
74
+ st.write(scenario)
75
+
76
+ st.text('Your story is going to begin...πŸ¦„')
77
+ story = text2story(scenario)
78
+ st.write(story)
79
+
80
+ st.text('Your story is going to be told...🎧')
81
+ audio_data = text2audio(story)
82
+ st.audio(audio_data['audio'], format="audio/wav", start_time=0, sample_rate=audio_data['sampling_rate'])
83
+
84
+ if __name__ == "__main__":
85
+ main()