Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import os
|
|
|
|
|
2 |
import gradio as gr
|
3 |
-
from TTS.api import TTS
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
tts = TTS(model_name=TTS_MODEL)
|
8 |
|
9 |
# μ€ν 리 λ°μ΄ν° (ν
μ€νΈ + μ΄λ―Έμ§ URL ν¬ν¨)
|
10 |
image_base_url = "https://huggingface.co/spaces/englissi/englishstories/resolve/main/image/"
|
@@ -21,13 +21,19 @@ stories = [
|
|
21 |
{"text": "Fun in the sun is the best!", "image": f"{image_base_url}10.webp"}
|
22 |
]
|
23 |
|
24 |
-
# μμ± νμΌ μμ±
|
25 |
-
def
|
26 |
try:
|
27 |
-
tts.
|
|
|
28 |
print(f"β
μμ± νμΌ μμ± μλ£: {filename}")
|
29 |
except Exception as e:
|
30 |
-
print("TTS μμ± μ€λ₯:", e)
|
|
|
|
|
|
|
|
|
|
|
31 |
return filename
|
32 |
|
33 |
# μ€ν 리 ν
μ€νΈλ₯Ό HTML μ€νμΌλ‘ ν¬κ² νμνκ³ μ€μ μ λ ¬νλ ν¨μ
|
@@ -51,7 +57,7 @@ def init_story():
|
|
51 |
story = stories[index]
|
52 |
text = story["text"]
|
53 |
image = story["image"]
|
54 |
-
audio_file = generate_audio(text, filename="story.
|
55 |
return index, text, image, audio_file
|
56 |
|
57 |
# "λ€μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ
|
@@ -60,12 +66,12 @@ def next_story(current_index):
|
|
60 |
story = stories[new_index]
|
61 |
text = story["text"]
|
62 |
image = story["image"]
|
63 |
-
audio_file = generate_audio(text, filename="story.
|
64 |
return new_index, format_story_text(text), image, audio_file, text
|
65 |
|
66 |
# "μ¬μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ
|
67 |
def play_story(current_text):
|
68 |
-
audio_file = generate_audio(current_text, filename="story.
|
69 |
return audio_file
|
70 |
|
71 |
# μ΄κΈ° λ°μ΄ν° μ€μ
|
@@ -114,33 +120,5 @@ with gr.Blocks(title="π κ·μ¬μ΄ μ€ν 리 μ±") as demo:
|
|
114 |
outputs=[audio_output]
|
115 |
)
|
116 |
|
117 |
-
# CSS μ€νμΌ μΆκ° (κ·μ¬μ΄ ν
λ§)
|
118 |
-
demo.css = """
|
119 |
-
body {
|
120 |
-
background-color: #FFFAF0; /* λ°λ»ν ν¬λ¦Όμ λ°°κ²½ */
|
121 |
-
}
|
122 |
-
|
123 |
-
#next-btn {
|
124 |
-
background-color: #FFD700; /* λ
Έλμ λ²νΌ */
|
125 |
-
font-size: 1.5em;
|
126 |
-
font-weight: bold;
|
127 |
-
border-radius: 20px;
|
128 |
-
padding: 10px;
|
129 |
-
}
|
130 |
-
|
131 |
-
#play-btn {
|
132 |
-
background-color: #90EE90; /* μ°ν μ΄λ‘μ λ²νΌ */
|
133 |
-
font-size: 1.5em;
|
134 |
-
font-weight: bold;
|
135 |
-
border-radius: 20px;
|
136 |
-
padding: 10px;
|
137 |
-
}
|
138 |
-
|
139 |
-
img {
|
140 |
-
border-radius: 10px; /* λ₯κ·Ό ν
λ리 */
|
141 |
-
border: 5px solid #FFFFFF; /* ν°μ ν
λ리 */
|
142 |
-
}
|
143 |
-
"""
|
144 |
-
|
145 |
# μ± μ€ν
|
146 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
import asyncio
|
3 |
+
import edge_tts
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
+
# Edge TTS μμ± μ€μ (Ryan: μ΄λ¦°μ΄ λͺ©μ리)
|
7 |
+
VOICE = "en-US-RyanNeural"
|
|
|
8 |
|
9 |
# μ€ν 리 λ°μ΄ν° (ν
μ€νΈ + μ΄λ―Έμ§ URL ν¬ν¨)
|
10 |
image_base_url = "https://huggingface.co/spaces/englissi/englishstories/resolve/main/image/"
|
|
|
21 |
{"text": "Fun in the sun is the best!", "image": f"{image_base_url}10.webp"}
|
22 |
]
|
23 |
|
24 |
+
# Edge TTSλ₯Ό μ¬μ©νμ¬ μμ± νμΌ μμ± (λΉλκΈ° ν¨μ)
|
25 |
+
async def generate_audio_async(text, filename="story.mp3"):
|
26 |
try:
|
27 |
+
tts = edge_tts.Communicate(text, VOICE)
|
28 |
+
await tts.save(filename)
|
29 |
print(f"β
μμ± νμΌ μμ± μλ£: {filename}")
|
30 |
except Exception as e:
|
31 |
+
print("β οΈ TTS μμ± μ€λ₯:", e)
|
32 |
+
return filename
|
33 |
+
|
34 |
+
# Gradioμ μ°λμ μν΄ λκΈ° ν¨μλ‘ λ³ν
|
35 |
+
def generate_audio(text, filename="story.mp3"):
|
36 |
+
asyncio.run(generate_audio_async(text, filename))
|
37 |
return filename
|
38 |
|
39 |
# μ€ν 리 ν
μ€νΈλ₯Ό HTML μ€νμΌλ‘ ν¬κ² νμνκ³ μ€μ μ λ ¬νλ ν¨μ
|
|
|
57 |
story = stories[index]
|
58 |
text = story["text"]
|
59 |
image = story["image"]
|
60 |
+
audio_file = generate_audio(text, filename="story.mp3")
|
61 |
return index, text, image, audio_file
|
62 |
|
63 |
# "λ€μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ
|
|
|
66 |
story = stories[new_index]
|
67 |
text = story["text"]
|
68 |
image = story["image"]
|
69 |
+
audio_file = generate_audio(text, filename="story.mp3")
|
70 |
return new_index, format_story_text(text), image, audio_file, text
|
71 |
|
72 |
# "μ¬μ" λ²νΌ ν΄λ¦ μ νΈμΆλλ ν¨μ
|
73 |
def play_story(current_text):
|
74 |
+
audio_file = generate_audio(current_text, filename="story.mp3")
|
75 |
return audio_file
|
76 |
|
77 |
# μ΄κΈ° λ°μ΄ν° μ€μ
|
|
|
120 |
outputs=[audio_output]
|
121 |
)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
# μ± μ€ν
|
124 |
demo.launch()
|