englissi commited on
Commit
f18dceb
Β·
verified Β·
1 Parent(s): 731366e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -34,6 +34,27 @@ long_vowel_stories = [
34
  {"text": "A baby bird flew away.", "image": f"{image_base_url}20.webp"}
35
  ]
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  # πŸ“Œ gTTSλ₯Ό μ‚¬μš©ν•˜μ—¬ μŒμ„± 파일 생성 (κ³ μœ ν•œ 파일λͺ… + 캐싱 μ‹œμŠ€ν…œ μΆ”κ°€)
38
  cached_audio = {} # 같은 λ¬Έμž₯에 λŒ€ν•΄ APIλ₯Ό μ—¬λŸ¬ 번 ν˜ΈμΆœν•˜μ§€ μ•Šλ„λ‘ μ €μž₯
39
 
@@ -80,6 +101,8 @@ def play_story(current_text):
80
  # πŸ“Œ 초기 데이터 μ„€μ •
81
  init_index_short, init_text_short, init_image_short, init_audio_short = 0, short_vowel_stories[0]["text"], short_vowel_stories[0]["image"], generate_audio(short_vowel_stories[0]["text"])
82
  init_index_long, init_text_long, init_image_long, init_audio_long = 0, long_vowel_stories[0]["text"], long_vowel_stories[0]["image"], generate_audio(long_vowel_stories[0]["text"])
 
 
83
 
84
  # πŸ“Œ Gradio UI ꡬ성
85
  with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
@@ -199,5 +222,27 @@ with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
199
  outputs=[audio_output_long]
200
  )
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  # πŸ“Œ μ•± μ‹€ν–‰
203
  demo.launch()
 
34
  {"text": "A baby bird flew away.", "image": f"{image_base_url}20.webp"}
35
  ]
36
 
37
+ # πŸ“Œ Blends & Digraphs μŠ€ν† λ¦¬ 데이터
38
+ blends_digraphs_stories = [
39
+ {"text": "Blake blows a blue blimp.", "image": f"{image_base_url}21.webp"},
40
+ {"text": "Brad brings a brown brush.", "image": f"{image_base_url}22.webp"},
41
+ {"text": "The clock clicks and claps.", "image": f"{image_base_url}23.webp"},
42
+ {"text": "Crispy crackers crunch.", "image": f"{image_base_url}24.webp"},
43
+ {"text": "A frog frogs on a free log.", "image": f"{image_base_url}25.webp"},
44
+ {"text": "Green grapes grow big.", "image": f"{image_base_url}26.webp"},
45
+ {"text": "The train trips on tracks.", "image": f"{image_base_url}27.webp"},
46
+ {"text": "The ship shines in the sun.", "image": f"{image_base_url}28.webp"},
47
+ {"text": "Chip and cheese are on my chin.", "image": f"{image_base_url}29.webp"},
48
+ {"text": "The thumb is thick.", "image": f"{image_base_url}30.webp"},
49
+ {"text": "White whales whisper.", "image": f"{image_base_url}31.webp"},
50
+ {"text": "A skunk skips sky-high.", "image": f"{image_base_url}32.webp"},
51
+ {"text": "The sleepy sloth slides.", "image": f"{image_base_url}33.webp"},
52
+ {"text": "Small smiles smell sweet.", "image": f"{image_base_url}34.webp"},
53
+ {"text": "The snail snaps a snack.", "image": f"{image_base_url}35.webp"},
54
+ {"text": "The spider spins a spotty web.", "image": f"{image_base_url}36.webp"},
55
+ {"text": "The star stands in the storm.", "image": f"{image_base_url}37.webp"},
56
+ {"text": "A swan swims in the sweet lake.", "image": f"{image_base_url}38.webp"}
57
+
58
  # πŸ“Œ gTTSλ₯Ό μ‚¬μš©ν•˜μ—¬ μŒμ„± 파일 생성 (κ³ μœ ν•œ 파일λͺ… + 캐싱 μ‹œμŠ€ν…œ μΆ”κ°€)
59
  cached_audio = {} # 같은 λ¬Έμž₯에 λŒ€ν•΄ APIλ₯Ό μ—¬λŸ¬ 번 ν˜ΈμΆœν•˜μ§€ μ•Šλ„λ‘ μ €μž₯
60
 
 
101
  # πŸ“Œ 초기 데이터 μ„€μ •
102
  init_index_short, init_text_short, init_image_short, init_audio_short = 0, short_vowel_stories[0]["text"], short_vowel_stories[0]["image"], generate_audio(short_vowel_stories[0]["text"])
103
  init_index_long, init_text_long, init_image_long, init_audio_long = 0, long_vowel_stories[0]["text"], long_vowel_stories[0]["image"], generate_audio(long_vowel_stories[0]["text"])
104
+ init_index_blends, init_text_blends, init_image_blends, init_audio_blends = 0, blends_digraphs_stories[0]["text"], blends_digraphs_stories[0]["image"], generate_audio(blends_digraphs_stories[0]["text"])
105
+
106
 
107
  # πŸ“Œ Gradio UI ꡬ성
108
  with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
 
222
  outputs=[audio_output_long]
223
  )
224
 
225
+ with gr.TabItem("Blends (μ΄μ€‘μžμŒ)"):
226
+ state_index_blends = gr.State(value=init_index_blends)
227
+ state_text_blends = gr.State(value=init_text_blends)
228
+
229
+ story_text_blends = gr.HTML(value=f"<div class='story-text'>{init_text_blends}</div>")
230
+ story_image_blends = gr.Image(value=init_image_blends, width=300, height=300)
231
+ audio_output_blends = gr.Audio(value=init_audio_blends, autoplay=False)
232
+
233
+ with gr.Row():
234
+ next_button_blends = gr.Button("πŸ‘‰ λ‹€μŒ 이야기", elem_classes=["btn-custom", "next-btn"])
235
+ play_button_blends = gr.Button("πŸ”Š λ‹€μ‹œ λ“£κΈ°", elem_classes=["btn-custom", "play-btn"])
236
+
237
+ next_button_long.click(
238
+ fn=next_story,
239
+ inputs=[state_index_blends, gr.State(value=blends_digraphs_storiesies)],
240
+ outputs=[state_index_blends, story_text_blends, story_image_blends, audio_output_blends, state_text_blends]
241
+ )
242
+
243
+ play_button_blends.click(
244
+ fn=play_story,
245
+ inputs=[state_text_blends],
246
+ outputs=[audio_output_blends]
247
  # πŸ“Œ μ•± μ‹€ν–‰
248
  demo.launch()