Inam65 commited on
Commit
8607966
Β·
verified Β·
1 Parent(s): 8007b4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
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 process_audio(audio_path):
5
- story = transcribe_audio(audio_path)
 
 
 
 
 
 
 
 
6
  pages = split_story_to_pages(story)
7
  images = [generate_image(page["image_prompt"]) for page in pages]
8
- return [(page["text"], img) for page, img in zip(pages, images)]
 
9
 
10
  with gr.Blocks() as demo:
11
  gr.Markdown("# 🎨 AI Story Illustrator for Kids")
12
- audio_input = gr.Audio(type="filepath", label="πŸŽ™οΈ Record or Upload Story")
13
- output = gr.Gallery(label="πŸ“š Illustrated Story")
 
 
 
14
  btn = gr.Button("Generate Storybook")
15
-
16
- btn.click(fn=process_audio, inputs=audio_input, outputs=output)
 
 
 
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
+