Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
24 |
-
|
25 |
-
|
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"β οΈ
|
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 |
-
|
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()
|