Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,25 +3,31 @@ from deep_translator import GoogleTranslator
|
|
3 |
from gtts import gTTS
|
4 |
import pykakasi
|
5 |
import os
|
6 |
-
import webbrowser
|
7 |
-
from datetime import datetime
|
8 |
|
9 |
# ๋ฒ์ ์ ๋ณด
|
10 |
-
__version__ = "1.
|
11 |
|
12 |
-
# Kakasi
|
13 |
kakasi = pykakasi.kakasi()
|
14 |
-
conv = kakasi.convert
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
if japanese_keyword:
|
27 |
audio_path = generate_audio_file(japanese_keyword)
|
@@ -29,25 +35,24 @@ def search_and_update_history(keyword):
|
|
29 |
else:
|
30 |
return result, gr.update(visible=False)
|
31 |
|
32 |
-
|
33 |
-
def search(keyword):
|
34 |
try:
|
35 |
translator = GoogleTranslator(source='ko', target='ja')
|
36 |
japanese_keyword = translator.translate(keyword)
|
|
|
|
|
37 |
|
38 |
-
url = f"https://www.irasutoya.com/search?q={
|
39 |
-
romaji = to_romaji(japanese_keyword)
|
40 |
result_text = (
|
41 |
f"**๊ฒ์์ด:** {keyword}\n"
|
42 |
-
f"**์ผ๋ณธ์ด
|
43 |
-
f"
|
44 |
-
f"**์๋ด:**
|
45 |
)
|
46 |
-
return result_text,
|
47 |
except Exception as e:
|
48 |
return f"๋ฒ์ญ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}", None
|
49 |
|
50 |
-
# ์ผ๋ณธ์ด ์์ฑ ์์ฑ ํจ์
|
51 |
def generate_audio_file(japanese_text):
|
52 |
try:
|
53 |
tts = gTTS(japanese_text, lang='ja')
|
@@ -57,101 +62,53 @@ def generate_audio_file(japanese_text):
|
|
57 |
except Exception as e:
|
58 |
return None
|
59 |
|
60 |
-
|
|
|
|
|
61 |
with gr.Blocks(css="""
|
62 |
-
|
63 |
-
|
64 |
margin: auto;
|
65 |
-
padding: 10px;
|
66 |
-
}
|
67 |
-
.input-box {
|
68 |
-
width: 100%; /* ๊ธฐ๋ณธ ๊ฐ๋ก ๊ธธ์ด */
|
69 |
-
height: auto; /* ๋์ด๋ฅผ ์๋์ผ๋ก ์ค์ */
|
70 |
-
padding: 12px 20px; /* ํจ๋ฉ ์ถ๊ฐ */
|
71 |
-
border: 2px solid #ddd;
|
72 |
-
border-radius: 4px;
|
73 |
-
font-size: 18px;
|
74 |
-
box-sizing: border-box;
|
75 |
-
}
|
76 |
-
.result-output {
|
77 |
-
background-color: #fff;
|
78 |
-
padding: 10px;
|
79 |
-
border: 1px solid #ddd;
|
80 |
-
border-radius: 4px;
|
81 |
-
font-size: 16px;
|
82 |
-
width: 100%;
|
83 |
-
margin-top: 15px;
|
84 |
-
}
|
85 |
-
.title {
|
86 |
-
font-size: 24px;
|
87 |
-
font-weight: bold;
|
88 |
-
color: #2C3E50;
|
89 |
-
margin-bottom: 10px;
|
90 |
-
text-align: center;
|
91 |
}
|
92 |
-
|
93 |
-
font-size: 16px;
|
94 |
-
padding: 10px 20px;
|
95 |
-
border-radius: 4px;
|
96 |
-
margin-top: 10px;
|
97 |
-
cursor: pointer;
|
98 |
width: 100%;
|
99 |
-
box-sizing: border-box;
|
100 |
-
border: none;
|
101 |
}
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
.
|
118 |
-
max-width: 100%; /* ๋ชจ๋ฐ์ผ์์๋ ์ ์ฒด ๊ฐ๋ก ํญ ์ฌ์ฉ */
|
119 |
-
}
|
120 |
-
.input-box {
|
121 |
-
width: 100%; /* ๋ชจ๋ฐ์ผ์์ ๊ฐ๋ก ๊ธธ์ด 100% */
|
122 |
-
}
|
123 |
-
}
|
124 |
-
""") as demo:
|
125 |
-
|
126 |
-
with gr.Column(elem_classes="container"):
|
127 |
-
gr.Markdown(f"## Irasutoya ํ๊ธ ๊ฒ์๊ธฐ - ๋ฒ์ {__version__}", elem_classes="title")
|
128 |
-
|
129 |
-
keyword_input = gr.Textbox(label="ํ๊ธ ๊ฒ์์ด ์
๋ ฅ", placeholder="ํ๊ธ๋ก ๊ฒ์์ด๋ฅผ ์
๋ ฅํ์ธ์", elem_classes="input-box")
|
130 |
-
|
131 |
-
search_button = gr.Button("๊ฒ์", elem_classes="btn-large btn-search")
|
132 |
-
clear_button = gr.Button("์ง์ฐ๊ธฐ", elem_classes="btn-large btn-clear")
|
133 |
-
|
134 |
-
result_output = gr.Markdown(elem_classes="result-output")
|
135 |
-
play_audio = gr.Audio(visible=False) # ์์ฑ ํ์ผ์ ์ฌ์ํ๋ ์ปดํฌ๋ํธ
|
136 |
|
137 |
-
|
|
|
138 |
fn=search_and_update_history,
|
139 |
-
inputs=[keyword_input],
|
140 |
outputs=[result_output, play_audio],
|
141 |
)
|
142 |
-
|
143 |
-
|
144 |
fn=search_and_update_history,
|
145 |
-
inputs=[keyword_input],
|
146 |
outputs=[result_output, play_audio],
|
147 |
)
|
148 |
-
|
149 |
clear_button.click(
|
150 |
-
fn=
|
151 |
outputs=[keyword_input, result_output, play_audio],
|
152 |
)
|
153 |
|
154 |
-
# ์๋ด
|
155 |
gr.Markdown("""
|
156 |
**โจ ์ด๋ผ์คํ ์ผ(Irasutoya.com)** ๋ ์ผ๋ณธ์ ์ผ๋ฌ์คํธ๋ ์ดํฐ ๋ฏธ์ฆํ๋ ํ์นด์(Takashi Mizutani)๊ฐ ์ด์ํ๋ ๋ฌด๋ฃ ์ผ๋ฌ์คํธ ์ฌ์ดํธ์
๋๋ค.
|
157 |
๊ท์ฝ๊ณ ๋จ์ํ ์คํ์ผ์ ์ผ๋ฌ์คํธ๋ฅผ ์น์ฌ์ดํธ, ๋ธ๋ก๊ทธ, ํ๋ ์ ํ
์ด์
, ์ธ์๋ฌผ ๋ฑ์ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, ์ผ๋ณธ ๋ด์์ ๋๋ฆฌ ์ฌ์ฉ๋๊ณ ์์ต๋๋ค.
|
@@ -170,14 +127,14 @@ with gr.Blocks(css="""
|
|
170 |
- ๊ฒ์๋ ์ด๋ฏธ์ง์ ์ฌ์ฉ ์กฐ๊ฑด์ ์ด๋ผ์คํ ์ผ์ ๊ท์ ์ ๋ฐ๋ฅด์๊ธฐ ๋ฐ๋๋๋ค.
|
171 |
""")
|
172 |
|
173 |
-
# ์ ์์ ์ ๋ณด ์น์
์ถ๊ฐ
|
174 |
gr.Markdown("""
|
175 |
<div style="text-align: center;">
|
176 |
<a href="https://litt.ly/goverse" target="_blank" style="color: #2980b9; text-decoration: underline;">๊ณ ๋ฒ์ค์๊ฒ ํผ๋๋ฐฑํ๊ธฐ</a>
|
177 |
</div>
|
178 |
""")
|
179 |
-
|
180 |
-
gr.Markdown("
|
181 |
|
182 |
# ์ฑ ์คํ
|
183 |
-
|
|
|
|
3 |
from gtts import gTTS
|
4 |
import pykakasi
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
# ๋ฒ์ ์ ๋ณด
|
8 |
+
__version__ = "1.8.10"
|
9 |
|
10 |
+
# Kakasi ์ธ์คํด์ค ์์ฑ ๋ฐ ์ค์
|
11 |
kakasi = pykakasi.kakasi()
|
|
|
12 |
|
13 |
+
def convert_text(japanese_text, conversion_type):
|
14 |
+
if conversion_type == "ํ๋ผ๊ฐ๋":
|
15 |
+
kakasi.setMode("H", "H") # ํ๋ผ๊ฐ๋ ์ ์ง
|
16 |
+
kakasi.setMode("K", "H") # ๊ฐํ์นด๋๋ฅผ ํ๋ผ๊ฐ๋๋ก ๋ณํ
|
17 |
+
kakasi.setMode("J", "H") # ํ์๋ฅผ ํ๋ผ๊ฐ๋๋ก ๋ณํ
|
18 |
+
elif conversion_type == "๊ฐํ์นด๋":
|
19 |
+
kakasi.setMode("H", "K") # ํ๋ผ๊ฐ๋๋ฅผ ๊ฐํ์นด๋๋ก ๋ณํ
|
20 |
+
kakasi.setMode("K", "K") # ๊ฐํ์นด๋ ์ ์ง
|
21 |
+
kakasi.setMode("J", "K") # ํ์๋ฅผ ๊ฐํ์นด๋๋ก ๋ณํ
|
22 |
+
else: # ๊ธฐ๋ณธ ๋๋ ํ์
|
23 |
+
return japanese_text # ๋ณํ ์์ด ๊ทธ๋๋ก ๋ฐํ
|
24 |
+
|
25 |
+
converter = kakasi.getConverter()
|
26 |
+
converted = converter.do(japanese_text)
|
27 |
+
return converted
|
28 |
+
|
29 |
+
def search_and_update_history(keyword, conversion_type):
|
30 |
+
result, japanese_keyword = search(keyword, conversion_type)
|
31 |
|
32 |
if japanese_keyword:
|
33 |
audio_path = generate_audio_file(japanese_keyword)
|
|
|
35 |
else:
|
36 |
return result, gr.update(visible=False)
|
37 |
|
38 |
+
def search(keyword, conversion_type):
|
|
|
39 |
try:
|
40 |
translator = GoogleTranslator(source='ko', target='ja')
|
41 |
japanese_keyword = translator.translate(keyword)
|
42 |
+
|
43 |
+
converted_keyword = convert_text(japanese_keyword, conversion_type)
|
44 |
|
45 |
+
url = f"https://www.irasutoya.com/search?q={converted_keyword}"
|
|
|
46 |
result_text = (
|
47 |
f"**๊ฒ์์ด:** {keyword}\n"
|
48 |
+
f"**์ผ๋ณธ์ด ๋ฒ์ญ ({conversion_type}):** {converted_keyword}\n"
|
49 |
+
f"[๊ฒ์ ๊ฒฐ๊ณผ ๋ณด๊ธฐ]({url})\n\n"
|
50 |
+
f"**์๋ด:** ์ ํํ ๋ณํ ์ ํ์ ๋ฐ๋ผ ๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ๋ฌ๋ผ์ง ์ ์์ต๋๋ค."
|
51 |
)
|
52 |
+
return result_text, converted_keyword
|
53 |
except Exception as e:
|
54 |
return f"๋ฒ์ญ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}", None
|
55 |
|
|
|
56 |
def generate_audio_file(japanese_text):
|
57 |
try:
|
58 |
tts = gTTS(japanese_text, lang='ja')
|
|
|
62 |
except Exception as e:
|
63 |
return None
|
64 |
|
65 |
+
def clear_inputs():
|
66 |
+
return "", "", gr.update(visible=False)
|
67 |
+
|
68 |
with gr.Blocks(css="""
|
69 |
+
#container {
|
70 |
+
width: 50%;
|
71 |
margin: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
+
#search_button, #clear_button {
|
|
|
|
|
|
|
|
|
|
|
74 |
width: 100%;
|
|
|
|
|
75 |
}
|
76 |
+
""") as demo:
|
77 |
+
with gr.Column(elem_id="container"):
|
78 |
+
gr.Markdown(f"## Irasutoya ํ๊ธ ๊ฒ์๊ธฐ - ๋ฒ์ {__version__}")
|
79 |
+
|
80 |
+
keyword_input = gr.Textbox(label="ํ๊ธ ๊ฒ์์ด ์
๋ ฅ", placeholder="ํ๊ธ๋ก ๊ฒ์์ด๋ฅผ ์
๋ ฅํ์ธ์", elem_id="keyword_input")
|
81 |
+
conversion_type = gr.Radio(
|
82 |
+
label="๋ณํ ์ ํ ์ ํ",
|
83 |
+
choices=["๊ธฐ๋ณธ", "ํ๋ผ๊ฐ๋", "๊ฐํ์นด๋", "ํ์"],
|
84 |
+
value="๊ธฐ๋ณธ",
|
85 |
+
elem_id="conversion_type"
|
86 |
+
)
|
87 |
+
search_button = gr.Button("๊ฒ์", elem_id="search_button")
|
88 |
+
clear_button = gr.Button("์ง์ฐ๊ธฐ", elem_id="clear_button")
|
89 |
+
|
90 |
+
result_output = gr.Markdown()
|
91 |
+
play_audio = gr.Audio(visible=False, label="์ผ๋ณธ์ด ๋ฐ์ ๋ฃ๊ธฐ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
# ์ํฐํค๋ก ๊ฒ์ ์คํ ์ถ๊ฐ
|
94 |
+
keyword_input.submit(
|
95 |
fn=search_and_update_history,
|
96 |
+
inputs=[keyword_input, conversion_type],
|
97 |
outputs=[result_output, play_audio],
|
98 |
)
|
99 |
+
|
100 |
+
search_button.click(
|
101 |
fn=search_and_update_history,
|
102 |
+
inputs=[keyword_input, conversion_type],
|
103 |
outputs=[result_output, play_audio],
|
104 |
)
|
105 |
+
|
106 |
clear_button.click(
|
107 |
+
fn=clear_inputs,
|
108 |
outputs=[keyword_input, result_output, play_audio],
|
109 |
)
|
110 |
|
111 |
+
# ์๋ด ๋ฌธ๊ตฌ๋ฅผ UI ๋ด๋ถ๋ก ์ด๋
|
112 |
gr.Markdown("""
|
113 |
**โจ ์ด๋ผ์คํ ์ผ(Irasutoya.com)** ๋ ์ผ๋ณธ์ ์ผ๋ฌ์คํธ๋ ์ดํฐ ๋ฏธ์ฆํ๋ ํ์นด์(Takashi Mizutani)๊ฐ ์ด์ํ๋ ๋ฌด๋ฃ ์ผ๋ฌ์คํธ ์ฌ์ดํธ์
๋๋ค.
|
114 |
๊ท์ฝ๊ณ ๋จ์ํ ์คํ์ผ์ ์ผ๋ฌ์คํธ๋ฅผ ์น์ฌ์ดํธ, ๋ธ๋ก๊ทธ, ํ๋ ์ ํ
์ด์
, ์ธ์๋ฌผ ๋ฑ์ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, ์ผ๋ณธ ๋ด์์ ๋๋ฆฌ ์ฌ์ฉ๋๊ณ ์์ต๋๋ค.
|
|
|
127 |
- ๊ฒ์๋ ์ด๋ฏธ์ง์ ์ฌ์ฉ ์กฐ๊ฑด์ ์ด๋ผ์คํ ์ผ์ ๊ท์ ์ ๋ฐ๋ฅด์๊ธฐ ๋ฐ๋๋๋ค.
|
128 |
""")
|
129 |
|
|
|
130 |
gr.Markdown("""
|
131 |
<div style="text-align: center;">
|
132 |
<a href="https://litt.ly/goverse" target="_blank" style="color: #2980b9; text-decoration: underline;">๊ณ ๋ฒ์ค์๊ฒ ํผ๋๋ฐฑํ๊ธฐ</a>
|
133 |
</div>
|
134 |
""")
|
135 |
+
|
136 |
+
gr.Markdown("<p style='text-align: center;'>์ ์์: ๊ณ ๋ฒ์คTV</p>")
|
137 |
|
138 |
# ์ฑ ์คํ
|
139 |
+
if __name__ == "__main__":
|
140 |
+
demo.launch(share=False)
|