Spaces:
Running
Running
Update app.py
Browse files
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
|
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 |
-
|
59 |
-
st.
|
60 |
-
|
61 |
|
62 |
-
|
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 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
72 |
|
73 |
-
|
74 |
-
story = text2story(scenario)
|
75 |
-
st.write(story)
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|