englissi commited on
Commit
cc05f1f
Β·
verified Β·
1 Parent(s): 2428217

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -64
app.py CHANGED
@@ -1,7 +1,7 @@
 
1
  import requests
2
  import gradio as gr
3
-
4
-
5
 
6
  # μŠ€ν† λ¦¬ 데이터 (ν…μŠ€νŠΈ + 이미지 URL 포함)
7
  image_base_url = "https://huggingface.co/spaces/englissi/englishstories/resolve/main/image/"
@@ -18,35 +18,16 @@ stories = [
18
  {"text": "Fun in the sun is the best!", "image": f"{image_base_url}10.webp"}
19
  ]
20
 
 
21
  def generate_audio(text, filename="story.mp3"):
22
  try:
23
- # 둜컬 Fish Speech μ„œλ²„ μ£Όμ†Œ
24
- api_url = "http://localhost:8080/tts"
25
- data = {"text": text, "speaker": "en_us_male"} # ν™”μž μ„€μ • (ν•„μš”μ— 따라 λ³€κ²½)
26
-
27
- # Fish Speech μ„œλ²„μ— μš”μ²­ 보내기
28
- response = requests.post(api_url, json=data)
29
-
30
- # 응닡 확인 및 μŒμ„± μ €μž₯
31
- if response.status_code == 200:
32
- with open(filename, "wb") as f:
33
- f.write(response.content)
34
- print(f"βœ… μŒμ„± 파일 생성 μ™„λ£Œ: {filename}")
35
- return filename
36
- else:
37
- print(f"⚠️ μŒμ„± 생성 μ‹€νŒ¨: {response.status_code}")
38
- return None
39
  except Exception as e:
40
- print(f"⚠️ 였λ₯˜ λ°œμƒ: {e}")
41
  return None
42
-
43
-
44
- # 동기 싀행을 μœ„ν•΄ λž˜ν•‘
45
- def generate_audio(text, filename="story.mp3"):
46
- loop = asyncio.new_event_loop()
47
- asyncio.set_event_loop(loop)
48
- loop.run_until_complete(generate_audio_async(text, filename))
49
- return filename
50
 
51
  # μŠ€ν† λ¦¬ ν…μŠ€νŠΈλ₯Ό HTML μŠ€νƒ€μΌλ‘œ 크게 ν‘œμ‹œν•˜κ³  쀑앙 μ •λ ¬ν•˜λŠ” ν•¨μˆ˜
52
  def format_story_text(text):
@@ -91,14 +72,10 @@ init_index, init_text, init_image, init_audio = init_story()
91
 
92
  # Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성
93
  with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
94
- gr.HTML(
95
- "<h1 style='text-align:center;'>🎈 μž¬λ―ΈμžˆλŠ” μ˜μ–΄ μŠ€ν† λ¦¬ νƒ€μž„! πŸ“–</h1>"
96
- )
97
-
98
- gr.HTML(
99
- "<p style='text-align:center; font-size:1.2em;'>🐱 κ·€μ—¬μš΄ 이야기와 ν•¨κ»˜ μ˜μ–΄λ₯Ό λ°°μ›Œλ³΄μ•„μš”! <br> "
100
- "λ²„νŠΌμ„ 눌러 λ‹€μŒ μ΄μ•ΌκΈ°λ‘œ λ„˜μ–΄κ°€κ³ , μŒμ„±μ„ λ“€μœΌλ©° 따라 μ½μ–΄λ³΄μ„Έμš”! 🎡</p>"
101
- )
102
 
103
  # μƒνƒœκ°’: ν˜„μž¬ μŠ€ν† λ¦¬ μΈλ±μŠ€μ™€ ν˜„μž¬ μŠ€ν† λ¦¬ ν…μŠ€νŠΈ μ €μž₯
104
  state_index = gr.State(value=init_index)
@@ -132,33 +109,5 @@ with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
132
  outputs=[audio_output]
133
  )
134
 
135
- # CSS μŠ€νƒ€μΌ μΆ”κ°€ (κ·€μ—¬μš΄ ν…Œλ§ˆ)
136
- demo.css = """
137
- body {
138
- background-color: #FFFAF0; /* λ”°λœ»ν•œ 크림색 λ°°κ²½ */
139
- }
140
-
141
- #next-btn {
142
- background-color: #FFD700; /* λ…Έλž€μƒ‰ λ²„νŠΌ */
143
- font-size: 1.5em;
144
- font-weight: bold;
145
- border-radius: 20px;
146
- padding: 10px;
147
- }
148
-
149
- #play-btn {
150
- background-color: #90EE90; /* μ—°ν•œ μ΄ˆλ‘μƒ‰ λ²„νŠΌ */
151
- font-size: 1.5em;
152
- font-weight: bold;
153
- border-radius: 20px;
154
- padding: 10px;
155
- }
156
-
157
- img {
158
- border-radius: 10px; /* λ‘₯κ·Ό ν…Œλ‘λ¦¬ */
159
- border: 5px solid #FFFFFF; /* 흰색 ν…Œλ‘λ¦¬ */
160
- }
161
- """
162
-
163
  # μ•± μ‹€ν–‰
164
- demo.launch()
 
1
+ import os
2
  import requests
3
  import gradio as gr
4
+ from gtts import gTTS # βœ… gTTS μΆ”κ°€
 
5
 
6
  # μŠ€ν† λ¦¬ 데이터 (ν…μŠ€νŠΈ + 이미지 URL 포함)
7
  image_base_url = "https://huggingface.co/spaces/englissi/englishstories/resolve/main/image/"
 
18
  {"text": "Fun in the sun is the best!", "image": f"{image_base_url}10.webp"}
19
  ]
20
 
21
+ # πŸ“Œ gTTSλ₯Ό μ‚¬μš©ν•˜μ—¬ μŒμ„± 파일 생성
22
  def generate_audio(text, filename="story.mp3"):
23
  try:
24
+ tts = gTTS(text=text, lang="en") # βœ… μ˜μ–΄ μŒμ„± 생성
25
+ tts.save(filename)
26
+ print(f"βœ… μŒμ„± 파일 생성 μ™„λ£Œ: {filename}")
27
+ return filename
 
 
 
 
 
 
 
 
 
 
 
 
28
  except Exception as e:
29
+ print(f"⚠️ μŒμ„± 생성 μ‹€νŒ¨: {e}")
30
  return None
 
 
 
 
 
 
 
 
31
 
32
  # μŠ€ν† λ¦¬ ν…μŠ€νŠΈλ₯Ό HTML μŠ€νƒ€μΌλ‘œ 크게 ν‘œμ‹œν•˜κ³  쀑앙 μ •λ ¬ν•˜λŠ” ν•¨μˆ˜
33
  def format_story_text(text):
 
72
 
73
  # Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성
74
  with gr.Blocks(title="πŸ“š κ·€μ—¬μš΄ μŠ€ν† λ¦¬ μ•±") as demo:
75
+ gr.HTML("<h1 style='text-align:center;'>🎈 μž¬λ―ΈμžˆλŠ” μ˜μ–΄ μŠ€ν† λ¦¬ νƒ€μž„! πŸ“–</h1>")
76
+
77
+ gr.HTML("<p style='text-align:center; font-size:1.2em;'>🐱 κ·€μ—¬μš΄ 이야기와 ν•¨κ»˜ μ˜μ–΄λ₯Ό λ°°μ›Œλ³΄μ•„μš”! <br> "
78
+ "λ²„νŠΌμ„ 눌러 λ‹€μŒ μ΄μ•ΌκΈ°λ‘œ λ„˜μ–΄κ°€κ³ , μŒμ„±μ„ λ“€μœΌλ©° 따라 μ½μ–΄λ³΄μ„Έμš”! 🎡</p>")
 
 
 
 
79
 
80
  # μƒνƒœκ°’: ν˜„μž¬ μŠ€ν† λ¦¬ μΈλ±μŠ€μ™€ ν˜„μž¬ μŠ€ν† λ¦¬ ν…μŠ€νŠΈ μ €μž₯
81
  state_index = gr.State(value=init_index)
 
109
  outputs=[audio_output]
110
  )
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  # μ•± μ‹€ν–‰
113
+ demo.launch()