englissi commited on
Commit
04aa6eb
Β·
verified Β·
1 Parent(s): 091700c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -153
app.py CHANGED
@@ -217,158 +217,34 @@ with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
217
  gr.HTML("<h1>🎈 μž¬λ―ΈμžˆλŠ” μ˜μ–΄ μŠ€ν† λ¦¬ νƒ€μž„! πŸ“–</h1>")
218
  gr.HTML("<p>🐱 κ·€μ—¬μš΄ 이야기와 ν•¨κ»˜ μ˜μ–΄λ₯Ό λ°°μ›Œλ³΄μ•„μš”! <br> λ²„νŠΌμ„ 눌러 λ‹€μŒ μ΄μ•ΌκΈ°λ‘œ λ„˜μ–΄κ°€κ³ , μŒμ„±μ„ λ“€μœΌλ©° 따라 μ½μ–΄λ³΄μ„Έμš”! 🎡</p>")
219
 
220
- with gr.Tabs():
221
- # -- Short Vowel Tab --
222
- with gr.TabItem("Short Vowel (단λͺ¨μŒ)"):
223
- state_index_short = gr.State(value=init_index_short)
224
- state_text_short = gr.State(value=init_text_short)
225
-
226
- story_text_short = gr.HTML(value=f"<div class='story-text'>{init_text_short}</div>")
227
- story_image_short = gr.Image(value=init_image_short, width=300, height=300)
228
- audio_output_short = gr.Audio(value=init_audio_short, autoplay=False)
229
-
230
- with gr.Row():
231
- next_button_short = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
232
- play_button_short = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
233
-
234
- # "λ‹€μŒ 이야기" λ²„νŠΌ 클릭 μ‹œ
235
- next_button_short.click(
236
- fn=next_story,
237
- inputs=[state_index_short, gr.State(value=short_vowel_stories)],
238
- outputs=[state_index_short, story_text_short, story_image_short, audio_output_short, state_text_short]
239
- )
240
-
241
- # "μž¬μƒ" λ²„νŠΌ 클릭 μ‹œ
242
- play_button_short.click(
243
- fn=play_story,
244
- inputs=[state_text_short],
245
- outputs=[audio_output_short]
246
- )
247
-
248
- # -- Long Vowel Tab --
249
- with gr.TabItem("Long Vowel (μž₯λͺ¨μŒ)"):
250
- state_index_long = gr.State(value=init_index_long)
251
- state_text_long = gr.State(value=init_text_long)
252
-
253
- story_text_long = gr.HTML(value=f"<div class='story-text'>{init_text_long}</div>")
254
- story_image_long = gr.Image(value=init_image_long, width=300, height=300)
255
- audio_output_long = gr.Audio(value=init_audio_long, autoplay=False)
256
-
257
- with gr.Row():
258
- next_button_long = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
259
- play_button_long = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
260
-
261
- next_button_long.click(
262
- fn=next_story,
263
- inputs=[state_index_long, gr.State(value=long_vowel_stories)],
264
- outputs=[state_index_long, story_text_long, story_image_long, audio_output_long, state_text_long]
265
- )
266
-
267
- play_button_long.click(
268
- fn=play_story,
269
- inputs=[state_text_long],
270
- outputs=[audio_output_long]
271
- )
272
-
273
- # -- Blends & Digraphs Tab --
274
- with gr.TabItem("Blends (μ΄μ€‘μžμŒ)"):
275
- state_index_blends = gr.State(value=init_index_blends)
276
- state_text_blends = gr.State(value=init_text_blends)
277
-
278
- story_text_blends = gr.HTML(value=f"<div class='story-text'>{init_text_blends}</div>")
279
- story_image_blends = gr.Image(value=init_image_blends, width=300, height=300)
280
- audio_output_blends = gr.Audio(value=init_audio_blends, autoplay=False)
281
-
282
- with gr.Row():
283
- next_button_blends = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
284
- play_button_blends = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
285
-
286
- next_button_blends.click(
287
- fn=next_story,
288
- inputs=[state_index_blends, gr.State(value=blends_digraphs_stories)],
289
- outputs=[state_index_blends, story_text_blends, story_image_blends, audio_output_blends, state_text_blends]
290
- )
291
-
292
- play_button_blends.click(
293
- fn=play_story,
294
- inputs=[state_text_blends],
295
- outputs=[audio_output_blends]
296
- )
297
-
298
- # -- The Red Ball Tab --
299
- with gr.TabItem("The Red Ball"):
300
- state_index_red_ball = gr.State(value=the_red_ball_index)
301
- state_text_red_ball = gr.State(value=the_red_ball_text)
302
-
303
- story_text_red_ball = gr.HTML(value=f"<div class='story-text'>{the_red_ball_text}</div>")
304
- story_image_red_ball = gr.Image(value=the_red_ball_image, width=300, height=300)
305
- audio_output_red_ball = gr.Audio(value=the_red_ball_audio, autoplay=False)
306
-
307
- with gr.Row():
308
- next_button_red_ball = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
309
- play_button_red_ball = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
310
-
311
- next_button_red_ball.click(
312
- fn=next_story,
313
- inputs=[state_index_red_ball, gr.State(value=the_red_ball_story)],
314
- outputs=[state_index_red_ball, story_text_red_ball, story_image_red_ball, audio_output_red_ball, state_text_red_ball]
315
- )
316
-
317
- play_button_red_ball.click(
318
- fn=play_story,
319
- inputs=[state_text_red_ball],
320
- outputs=[audio_output_red_ball]
321
- )
322
-
323
- # -- The Big Cat Tab --
324
- with gr.TabItem("The Big Cat"):
325
- state_index_big_cat = gr.State(value=the_big_cat_index)
326
- state_text_big_cat = gr.State(value=the_big_cat_text)
327
-
328
- story_text_big_cat = gr.HTML(value=f"<div class='story-text'>{the_big_cat_text}</div>")
329
- story_image_big_cat = gr.Image(value=the_big_cat_image, width=300, height=300)
330
- audio_output_big_cat = gr.Audio(value=the_big_cat_audio, autoplay=False)
331
-
332
- with gr.Row():
333
- next_button_big_cat = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
334
- play_button_big_cat = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
335
-
336
- next_button_big_cat.click(
337
- fn=next_story,
338
- inputs=[state_index_big_cat, gr.State(value=the_big_cat_story)],
339
- outputs=[state_index_big_cat, story_text_big_cat, story_image_big_cat, audio_output_big_cat, state_text_big_cat]
340
- )
341
-
342
- play_button_big_cat.click(
343
- fn=play_story,
344
- inputs=[state_text_big_cat],
345
- outputs=[audio_output_big_cat]
346
- )
347
-
348
- # -- The Hot Sun --
349
- with gr.TabItem("The Hot Sun"):
350
- state_index_hot_sun = gr.State(value=the_hot_sun_index)
351
- state_text_hot_sun = gr.State(value=the_hot_sun_text)
352
-
353
- story_text_hot_sun = gr.HTML(value=f"<div class='story-text'>{the_hot_sun_text}</div>")
354
- story_image_hot_sun = gr.Image(value=the_hot_sun_image, width=300, height=300)
355
- audio_output_hot_sun = gr.Audio(value=the_hot_sun_audio, autoplay=False)
356
-
357
- with gr.Row():
358
- next_button_hot_sun = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
359
- play_button_hot_sun = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
360
-
361
- next_button_hot_sun.click(
362
- fn=next_story,
363
- inputs=[state_index_hot_sun, gr.State(value=the_hot_sun_story)],
364
- outputs=[state_index_hot_sun, story_text_hot_sun, story_image_hot_sun, audio_output_hot_sun, state_text_hot_sun]
365
- )
366
-
367
- play_button_hot_sun.click(
368
- fn=play_story,
369
- inputs=[state_text_hot_sun],
370
- outputs=[audio_output_hot_sun]
371
- )
372
-
373
  # πŸ“Œ μ•± μ‹€ν–‰
374
  demo.launch()
 
217
  gr.HTML("<h1>🎈 μž¬λ―ΈμžˆλŠ” μ˜μ–΄ μŠ€ν† λ¦¬ νƒ€μž„! πŸ“–</h1>")
218
  gr.HTML("<p>🐱 κ·€μ—¬μš΄ 이야기와 ν•¨κ»˜ μ˜μ–΄λ₯Ό λ°°μ›Œλ³΄μ•„μš”! <br> λ²„νŠΌμ„ 눌러 λ‹€μŒ μ΄μ•ΌκΈ°λ‘œ λ„˜μ–΄κ°€κ³ , μŒμ„±μ„ λ“€μœΌλ©° 따라 μ½μ–΄λ³΄μ„Έμš”! 🎡</p>")
219
 
220
+ with gr.Tabs():
221
+ for story_name, story_data in [("Short Vowel", short_vowel_stories),
222
+ ("Long Vowel", long_vowel_stories),
223
+ ("Blends & Digraphs", blends_digraphs_stories),
224
+ ("The Red Ball", the_red_ball_story),
225
+ ("The Big Cat", the_big_cat_story),
226
+ ("The Hot Sun", the_hot_sun_story)]:
227
+ with gr.TabItem(story_name):
228
+ state_index = gr.State(value=0)
229
+ state_text = gr.State(value=story_data[0]["text"])
230
+
231
+ story_text = gr.HTML(value=f"<div class='story-text'>{story_data[0]['text']}</div>")
232
+ story_image = gr.Image(value=story_data[0]["image"], width=300, height=300)
233
+ audio_output = gr.Audio(value=generate_audio(story_data[0]["text"]), autoplay=False)
234
+
235
+ with gr.Row():
236
+ next_button = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
237
+ play_button = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
238
+
239
+ next_button.click(
240
+ fn=next_story,
241
+ inputs=[state_index, gr.State(value=story_data)],
242
+ outputs=[state_index, story_text, story_image, audio_output, state_text]
243
+ )
244
+ play_button.click(
245
+ fn=play_story,
246
+ inputs=[state_text],
247
+ outputs=[audio_output]
248
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  # πŸ“Œ μ•± μ‹€ν–‰
250
  demo.launch()