Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import transcribe_audio, split_story_to_pages, generate_image
|
| 3 |
|
| 4 |
-
def
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
pages = split_story_to_pages(story)
|
| 7 |
images = [generate_image(page["image_prompt"]) for page in pages]
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
with gr.Blocks() as demo:
|
| 11 |
gr.Markdown("# π¨ AI Story Illustrator for Kids")
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
btn = gr.Button("Generate Storybook")
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo.launch()
|
| 19 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from utils import transcribe_audio, split_story_to_pages, generate_image
|
| 3 |
|
| 4 |
+
def process_input(audio_path, text_input):
|
| 5 |
+
# Priority: Audio > Text
|
| 6 |
+
if audio_path:
|
| 7 |
+
story = transcribe_audio(audio_path)
|
| 8 |
+
elif text_input:
|
| 9 |
+
story = text_input
|
| 10 |
+
else:
|
| 11 |
+
return "Please provide either an audio recording or a text input.", []
|
| 12 |
+
|
| 13 |
+
# Process story
|
| 14 |
pages = split_story_to_pages(story)
|
| 15 |
images = [generate_image(page["image_prompt"]) for page in pages]
|
| 16 |
+
results = [(page["text"], img) for page, img in zip(pages, images)]
|
| 17 |
+
return "", results
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
gr.Markdown("# π¨ AI Story Illustrator for Kids")
|
| 21 |
+
|
| 22 |
+
with gr.Row():
|
| 23 |
+
audio_input = gr.Audio(type="filepath", label="ποΈ Record or Upload Story (Optional)")
|
| 24 |
+
text_input = gr.Textbox(lines=6, placeholder="Or type/paste your story here...", label="π Story Text (Optional)")
|
| 25 |
+
|
| 26 |
btn = gr.Button("Generate Storybook")
|
| 27 |
+
|
| 28 |
+
error_box = gr.Textbox(visible=False, label="Error Message", interactive=False)
|
| 29 |
+
output = gr.Gallery(label="π Illustrated Story")
|
| 30 |
+
|
| 31 |
+
btn.click(fn=process_input, inputs=[audio_input, text_input], outputs=[error_box, output])
|
| 32 |
|
| 33 |
demo.launch()
|
| 34 |
|
| 35 |
+
|