File size: 6,065 Bytes
2753efc
30d363f
 
 
 
46b7ff2
033c24d
f4b17cb
2753efc
8d3b576
30d363f
2753efc
8d3b576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30d363f
 
 
 
 
 
 
8d3b576
30d363f
 
 
8d3b576
 
30d363f
8d3b576
30d363f
 
8d3b576
 
 
30d363f
8d3b576
30d363f
 
 
 
 
 
 
 
 
 
 
 
8d3b576
 
 
30d363f
8d3b576
 
30d363f
 
8d3b576
7529d5e
30d363f
8d3b576
 
f4b17cb
8d3b576
 
 
 
 
 
 
 
 
 
 
 
 
30d363f
8d3b576
 
30d363f
8d3b576
30d363f
 
8d3b576
 
30d363f
8d3b576
30d363f
 
8d3b576
30d363f
8d3b576
30d363f
 
 
8d3b576
e255572
d2952aa
 
e255572
d2952aa
 
e255572
d2952aa
 
e255572
647764f
d2952aa
 
 
 
 
033c24d
e255572
30d363f
 
d940385
30d363f
 
8d3b576
 
d04ec54
2753efc
 
8d3b576
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import gradio as gr
from deep_translator import GoogleTranslator
from gtts import gTTS
import pykakasi
import os

# ๋ฒ„์ „ ์ •๋ณด
__version__ = "1.8.13"

# Kakasi ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐ ์„ค์ •
kakasi = pykakasi.kakasi()

def convert_text(japanese_text, conversion_type):
    if conversion_type == "ํžˆ๋ผ๊ฐ€๋‚˜":
        kakasi.setMode("H", "H")  # ํžˆ๋ผ๊ฐ€๋‚˜ ์œ ์ง€
        kakasi.setMode("K", "H")  # ๊ฐ€ํƒ€์นด๋‚˜๋ฅผ ํžˆ๋ผ๊ฐ€๋‚˜๋กœ ๋ณ€ํ™˜
        kakasi.setMode("J", "H")  # ํ•œ์ž๋ฅผ ํžˆ๋ผ๊ฐ€๋‚˜๋กœ ๋ณ€ํ™˜
    elif conversion_type == "๊ฐ€ํƒ€์นด๋‚˜":
        kakasi.setMode("H", "K")  # ํžˆ๋ผ๊ฐ€๋‚˜๋ฅผ ๊ฐ€ํƒ€์นด๋‚˜๋กœ ๋ณ€ํ™˜
        kakasi.setMode("K", "K")  # ๊ฐ€ํƒ€์นด๋‚˜ ์œ ์ง€
        kakasi.setMode("J", "K")  # ํ•œ์ž๋ฅผ ๊ฐ€ํƒ€์นด๋‚˜๋กœ ๋ณ€ํ™˜
    else:  # ๊ธฐ๋ณธ ๋˜๋Š” ํ•œ์ž
        return japanese_text  # ๋ณ€ํ™˜ ์—†์ด ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜

    converter = kakasi.getConverter()
    converted = converter.do(japanese_text)
    return converted

def search_and_update_history(keyword, conversion_type):
    result, japanese_keyword = search(keyword, conversion_type)

    if japanese_keyword:
        audio_path = generate_audio_file(japanese_keyword)
        return result, gr.update(value=audio_path, visible=True)
    else:
        return result, gr.update(visible=False)

def search(keyword, conversion_type):
    try:
        translator = GoogleTranslator(source='ko', target='ja')
        japanese_keyword = translator.translate(keyword)

        converted_keyword = convert_text(japanese_keyword, conversion_type)
        
        url = f"https://www.irasutoya.com/search?q={converted_keyword}"
        result_text = (
            f"**๊ฒ€์ƒ‰์–ด:** {keyword}\n"
            f"**์ผ๋ณธ์–ด ๋ฒˆ์—ญ ({conversion_type}):** {converted_keyword}\n"
            f"[๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ๋ณด๊ธฐ]({url})\n\n"
            f"**์•ˆ๋‚ด:** ์„ ํƒํ•œ ๋ณ€ํ™˜ ์œ ํ˜•์— ๋”ฐ๋ผ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
        )
        return result_text, converted_keyword
    except Exception as e:
        return f"๋ฒˆ์—ญ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {e}", None

def generate_audio_file(japanese_text):
    try:
        tts = gTTS(japanese_text, lang='ja')
        file_path = "japanese_audio.mp3"
        tts.save(file_path)
        return file_path
    except Exception as e:
        return None

def clear_inputs():
    return "", "", gr.update(visible=False)

with gr.Blocks(css="""
    #container {
        width: 50%;
        margin: auto;
    }
    #search_button, #clear_button {
        width: 100%;
    }
""") as demo:
    with gr.Column(elem_id="container"):
        gr.Markdown("<h2 style='text-align: center;'>์ด๋ผ์Šคํ† ์•ผ ์ผ๋Ÿฌ์ŠคํŠธ ๊ฒ€์ƒ‰๊ธฐ</h2>")

        keyword_input = gr.Textbox(label="ํ•œ๊ธ€ ๊ฒ€์ƒ‰์–ด ์ž…๋ ฅ", placeholder="ํ•œ๊ธ€๋กœ ๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”", elem_id="keyword_input")
        conversion_type = gr.Radio(
            label="๋ณ€ํ™˜ ์œ ํ˜• ์„ ํƒ",
            choices=["๊ธฐ๋ณธ", "ํžˆ๋ผ๊ฐ€๋‚˜", "๊ฐ€ํƒ€์นด๋‚˜", "ํ•œ์ž"],
            value="๊ธฐ๋ณธ",
            elem_id="conversion_type"
        )
        search_button = gr.Button("๊ฒ€์ƒ‰", elem_id="search_button")
        clear_button = gr.Button("์ง€์šฐ๊ธฐ", elem_id="clear_button")
    
        result_output = gr.Markdown()
        play_audio = gr.Audio(visible=False, label="์ผ๋ณธ์–ด ๋ฐœ์Œ ๋“ฃ๊ธฐ")

        # ์—”ํ„ฐํ‚ค๋กœ ๊ฒ€์ƒ‰ ์‹คํ–‰ ์ถ”๊ฐ€
        keyword_input.submit(
            fn=search_and_update_history,
            inputs=[keyword_input, conversion_type],
            outputs=[result_output, play_audio],
        )

        search_button.click(
            fn=search_and_update_history,
            inputs=[keyword_input, conversion_type],
            outputs=[result_output, play_audio],
        )

        clear_button.click(
            fn=clear_inputs,
            outputs=[keyword_input, result_output, play_audio],
        )

        # ์•ˆ๋‚ด ๋ฌธ๊ตฌ๋ฅผ UI ๋‚ด๋ถ€๋กœ ์ด๋™
        gr.Markdown("""
        **โœจ ์ด๋ผ์Šคํ† ์•ผ(Irasutoya.com)** ๋Š” ์ผ๋ณธ์˜ ์ผ๋Ÿฌ์ŠคํŠธ๋ ˆ์ดํ„ฐ ๋ฏธ์ฆˆํƒ€๋‹ˆ ํƒ€์นด์‹œ(Takashi Mizutani)๊ฐ€ ์šด์˜ํ•˜๋Š” ๋ฌด๋ฃŒ ์ผ๋Ÿฌ์ŠคํŠธ ์‚ฌ์ดํŠธ์ž…๋‹ˆ๋‹ค.  
        ๊ท€์—ฝ๊ณ  ๋‹จ์ˆœํ•œ ์Šคํƒ€์ผ์˜ ์ผ๋Ÿฌ์ŠคํŠธ๋ฅผ ์›น์‚ฌ์ดํŠธ, ๋ธ”๋กœ๊ทธ, ํ”„๋ ˆ์  ํ…Œ์ด์…˜, ์ธ์‡„๋ฌผ ๋“ฑ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ผ๋ณธ ๋‚ด์—์„œ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

        **๐ŸŽฅ ์œ ํŠœ๋ธŒ ์‡ผ์ธ ์™€ ์˜์ƒ ์ œ์ž‘์— ํ•„์š”ํ•œ ์ด๋ฏธ์ง€๋ฅผ ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ์ง€๋งŒ,**  
        ์ผ๋ณธ์–ด๋กœ ๋˜์–ด ์žˆ์–ด ๋ถˆํŽธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ•œ๊ธ€๋กœ ์ž…๋ ฅํ•ด๋„ ๋ฒˆ์—ญ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” ํˆด์„ ๊ฐœ๋ฐœํ–ˆ์Šต๋‹ˆ๋‹ค.

        **๐ŸŽ“ ์ด ํˆด์€ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ผ๋ณธ์–ด ๋ฐœ์Œ์„ ๋“ค์œผ๋ฉฐ ๊ฐ„๋‹จํ•œ ์ผ๋ณธ์–ด ๊ณต๋ถ€๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.**  
        ์ด ํˆด์ด ๋„์›€์ด ๋˜์…จ๋‹ค๋ฉด, ์•„๋ž˜ ๋งํฌ๋ฅผ ํ†ตํ•ด ํ›„์›ํ•ด ์ฃผ์„ธ์š”. ์—ฌ๋Ÿฌ๋ถ„์˜ ํ›„์›์ด ๋” ๋‚˜์€ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ฐ ํฐ ํž˜์ด ๋ฉ๋‹ˆ๋‹ค. ๐Ÿ’–

        **โš ๏ธ ์ด๋ผ์Šคํ† ์•ผ ์ผ๋Ÿฌ์ŠคํŠธ ์ด์šฉ ์ฃผ์˜ ์‚ฌํ•ญ:**  
        - ๊ฐœ์ธ, ๋ฒ•์ธ, ์ƒ์—…์  ์‚ฌ์šฉ ๋ชจ๋‘ ๋ฌด๋ฃŒ์ž…๋‹ˆ๋‹ค.  
        - ๋‹จ, ํ•œ ์ €์ž‘๋ฌผ๋‹น 20๊ฐœ๊นŒ์ง€๋งŒ ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, 21๊ฐœ ์ด์ƒ ์‚ฌ์šฉ ์‹œ ์œ ์ƒ์œผ๋กœ ์ „ํ™˜๋ฉ๋‹ˆ๋‹ค.  
        - ์ €์ž‘๊ถŒ ํ‘œ๊ธฐ ์˜๋ฌด๋Š” ์—†์œผ๋ฉฐ, ์ž์œ ๋กญ๊ฒŒ ํŽธ์ง‘ ๋ฐ ๊ฐ€๊ณต์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.  
        - ์ด ์‚ฌ์ดํŠธ๋Š” ๋‹จ์ˆœํžˆ ์ด๋ผ์Šคํ† ์•ผ์˜ ์ด๋ฏธ์ง€๋ฅผ ๊ฒ€์ƒ‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ผ๋ณธ์–ด๋กœ ๋ฒˆ์—ญํ•ด ์ „๋‹ฌํ•˜๋Š” ๊ธฐ๋Šฅ๋งŒ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.  
        - ๊ฒ€์ƒ‰๋œ ์ด๋ฏธ์ง€์˜ ์‚ฌ์šฉ ์กฐ๊ฑด์€ ์ด๋ผ์Šคํ† ์•ผ์˜ ๊ทœ์ •์„ ๋”ฐ๋ฅด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
        """)

        gr.Markdown("""
        <div style="text-align: center;">
            <a href="https://litt.ly/goverse" target="_blank" style="color: #2980b9; text-decoration: underline;">๊ณ ๋ฒ„์Šค์—๊ฒŒ ํ”ผ๋“œ๋ฐฑํ•˜๊ธฐ</a>
        </div>
        """)

        gr.Markdown("<p style='text-align: center;'>์ œ์ž‘์ž: ๊ณ ๋ฒ„์ŠคTV</p>")
        gr.Markdown(f"<p style='text-align: center;'>๋ฒ„์ „: {__version__}</p>")

# ์•ฑ ์‹คํ–‰
if __name__ == "__main__":
    demo.launch(share=False)