Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import os
|
2 |
-
import asyncio
|
3 |
-
import edge_tts
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# ์คํ ๋ฆฌ ๋ฐ์ดํฐ (ํ
์คํธ + ์ด๋ฏธ์ง URL ํฌํจ)
|
7 |
image_base_url = "https://huggingface.co/spaces/englissi/englishstories/resolve/main/image/"
|
@@ -18,25 +21,15 @@ stories = [
|
|
18 |
{"text": "Fun in the sun is the best!", "image": f"{image_base_url}10.webp"}
|
19 |
]
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
try:
|
24 |
-
|
25 |
-
|
26 |
-
await tts.save(filename)
|
27 |
except Exception as e:
|
28 |
print("TTS ์์ฑ ์ค๋ฅ:", e)
|
29 |
return filename
|
30 |
|
31 |
-
# Gradio์ ์ฐ๋์ ์ํด ๋๊ธฐ ํจ์๋ก ๋ณํ
|
32 |
-
def generate_audio(text, filename="story.mp3"):
|
33 |
-
try:
|
34 |
-
asyncio.run(generate_audio_async(text, filename))
|
35 |
-
return filename
|
36 |
-
except Exception as e:
|
37 |
-
print("์ค๋ฅ ๋ฐ์:", e)
|
38 |
-
return None
|
39 |
-
|
40 |
# ์คํ ๋ฆฌ ํ
์คํธ๋ฅผ HTML ์คํ์ผ๋ก ํฌ๊ฒ ํ์ํ๊ณ ์ค์ ์ ๋ ฌํ๋ ํจ์
|
41 |
def format_story_text(text):
|
42 |
return f"""
|
@@ -58,7 +51,7 @@ def init_story():
|
|
58 |
story = stories[index]
|
59 |
text = story["text"]
|
60 |
image = story["image"]
|
61 |
-
audio_file = generate_audio(text, filename="story.
|
62 |
return index, text, image, audio_file
|
63 |
|
64 |
# "๋ค์" ๋ฒํผ ํด๋ฆญ ์ ํธ์ถ๋๋ ํจ์
|
@@ -67,12 +60,12 @@ def next_story(current_index):
|
|
67 |
story = stories[new_index]
|
68 |
text = story["text"]
|
69 |
image = story["image"]
|
70 |
-
audio_file = generate_audio(text, filename="story.
|
71 |
return new_index, format_story_text(text), image, audio_file, text
|
72 |
|
73 |
# "์ฌ์" ๋ฒํผ ํด๋ฆญ ์ ํธ์ถ๋๋ ํจ์
|
74 |
def play_story(current_text):
|
75 |
-
audio_file = generate_audio(current_text, filename="story.
|
76 |
return audio_file
|
77 |
|
78 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ์ค์
|
|
|
1 |
import os
|
|
|
|
|
2 |
import gradio as gr
|
3 |
+
from TTS.api import TTS
|
4 |
+
|
5 |
+
# Coqui TTS ๋ชจ๋ธ ์ค์ (jenny ์์ฑ)
|
6 |
+
TTS_MODEL = "tts_models/en/jenny/jenny"
|
7 |
+
tts = TTS(model_name=TTS_MODEL)
|
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 |
+
# ์์ฑ ํ์ผ ์์ฑ ํจ์ (Coqui TTS ์ด์ฉ)
|
25 |
+
def generate_audio(text, filename="story.wav"):
|
26 |
try:
|
27 |
+
tts.tts_to_file(text, file_path=filename)
|
28 |
+
print(f"โ
์์ฑ ํ์ผ ์์ฑ ์๋ฃ: {filename}")
|
|
|
29 |
except Exception as e:
|
30 |
print("TTS ์์ฑ ์ค๋ฅ:", e)
|
31 |
return filename
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# ์คํ ๋ฆฌ ํ
์คํธ๋ฅผ HTML ์คํ์ผ๋ก ํฌ๊ฒ ํ์ํ๊ณ ์ค์ ์ ๋ ฌํ๋ ํจ์
|
34 |
def format_story_text(text):
|
35 |
return f"""
|
|
|
51 |
story = stories[index]
|
52 |
text = story["text"]
|
53 |
image = story["image"]
|
54 |
+
audio_file = generate_audio(text, filename="story.wav")
|
55 |
return index, text, image, audio_file
|
56 |
|
57 |
# "๋ค์" ๋ฒํผ ํด๋ฆญ ์ ํธ์ถ๋๋ ํจ์
|
|
|
60 |
story = stories[new_index]
|
61 |
text = story["text"]
|
62 |
image = story["image"]
|
63 |
+
audio_file = generate_audio(text, filename="story.wav")
|
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.wav")
|
69 |
return audio_file
|
70 |
|
71 |
# ์ด๊ธฐ ๋ฐ์ดํฐ ์ค์
|