Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,18 +9,18 @@ def img2text(url):
|
|
9 |
def text2story(text):
|
10 |
story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator", device_map="auto", return_full_text=False)
|
11 |
prompt = f"Create a story under 100 words about the scene: {text}."
|
12 |
-
generated = story_generator(prompt, max_new_tokens=
|
13 |
story_text = generated[0]['generated_text']
|
14 |
return story_text
|
15 |
|
16 |
def text2audio(story_text):
|
17 |
-
audio_generator = pipeline("text-to-speech", model="
|
18 |
audio_output = audio_generator(story_text)
|
19 |
return audio_output
|
20 |
|
21 |
-
st.set_page_config(page_title="Once Upon A Time - Storytelling Application", page_icon="
|
22 |
-
st.header("Create a story of yours with an image
|
23 |
-
uploaded_file = st.file_uploader("Upload an image
|
24 |
|
25 |
if uploaded_file is not None:
|
26 |
print(uploaded_file)
|
@@ -29,14 +29,13 @@ if uploaded_file is not None:
|
|
29 |
file.write(bytes_data)
|
30 |
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
31 |
|
32 |
-
st.text('
|
33 |
scenario = img2text(uploaded_file.name)
|
34 |
st.write(scenario)
|
35 |
|
36 |
-
st.text('
|
37 |
story = text2story(scenario)
|
38 |
st.write(story)
|
39 |
|
40 |
-
st.text('Generating audio data...')
|
41 |
audio_data = text2audio(story)
|
42 |
st.audio(audio_data['audio'], format="audio/wav", start_time=0, sample_rate = audio_data['sampling_rate'])
|
|
|
9 |
def text2story(text):
|
10 |
story_generator = pipeline("text-generation", model="pranavpsv/gpt2-genre-story-generator", device_map="auto", return_full_text=False)
|
11 |
prompt = f"Create a story under 100 words about the scene: {text}."
|
12 |
+
generated = story_generator(prompt, max_new_tokens=130, do_sample=True, temperature=0.7)
|
13 |
story_text = generated[0]['generated_text']
|
14 |
return story_text
|
15 |
|
16 |
def text2audio(story_text):
|
17 |
+
audio_generator = pipeline("text-to-speech", model="hexgrad/Kokoro-82M")
|
18 |
audio_output = audio_generator(story_text)
|
19 |
return audio_output
|
20 |
|
21 |
+
st.set_page_config(page_title="Once Upon A Time - Storytelling Application", page_icon="π")
|
22 |
+
st.header("Create a story of yours with an image!π°π¦π§")
|
23 |
+
uploaded_file = st.file_uploader("Upload an image for creating your story!")
|
24 |
|
25 |
if uploaded_file is not None:
|
26 |
print(uploaded_file)
|
|
|
29 |
file.write(bytes_data)
|
30 |
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
31 |
|
32 |
+
st.text('Entering the scene...')
|
33 |
scenario = img2text(uploaded_file.name)
|
34 |
st.write(scenario)
|
35 |
|
36 |
+
st.text('Your story is going to begin...')
|
37 |
story = text2story(scenario)
|
38 |
st.write(story)
|
39 |
|
|
|
40 |
audio_data = text2audio(story)
|
41 |
st.audio(audio_data['audio'], format="audio/wav", start_time=0, sample_rate = audio_data['sampling_rate'])
|