Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from utils import transcribe_audio, split_story_to_pages, generate_image | |
| def process_input(audio_path, text_input): | |
| # Priority: Audio > Text | |
| if audio_path: | |
| story = transcribe_audio(audio_path) | |
| elif text_input: | |
| story = text_input | |
| else: | |
| return "Please provide either an audio recording or a text input.", [] | |
| # Process story | |
| pages = split_story_to_pages(story) | |
| images = [generate_image(page["image_prompt"]) for page in pages] | |
| results = [(page["text"], img) for page, img in zip(pages, images)] | |
| return "", results | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π¨ AI Story Illustrator for Kids") | |
| with gr.Row(): | |
| audio_input = gr.Audio(type="filepath", label="ποΈ Record or Upload Story (Optional)") | |
| text_input = gr.Textbox(lines=6, placeholder="Or type/paste your story here...", label="π Story Text (Optional)") | |
| btn = gr.Button("Generate Storybook") | |
| error_box = gr.Textbox(visible=False, label="Error Message", interactive=False) | |
| output = gr.Gallery(label="π Illustrated Story") | |
| btn.click(fn=process_input, inputs=[audio_input, text_input], outputs=[error_box, output]) | |
| demo.launch() | |