Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,372 +1,100 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import json
|
4 |
-
import base64
|
5 |
-
import numpy as np
|
6 |
-
import threading
|
7 |
-
import queue
|
8 |
import os
|
9 |
-
from
|
10 |
-
import pyaudio
|
11 |
-
import wave
|
12 |
-
import io
|
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 |
-
self.ws = websocket.WebSocketApp(
|
42 |
-
url,
|
43 |
-
header=headers,
|
44 |
-
on_open=self.on_open,
|
45 |
-
on_message=self.on_message,
|
46 |
-
on_error=self.on_error,
|
47 |
-
on_close=self.on_close
|
48 |
)
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
self.is_connected = True
|
62 |
-
print("WebSocket ์ฐ๊ฒฐ๋จ")
|
63 |
-
|
64 |
-
# ์ธ์
์ค์
|
65 |
-
session_update = {
|
66 |
-
"type": "session.update",
|
67 |
-
"session": {
|
68 |
-
"modalities": ["text", "audio"],
|
69 |
-
"instructions": f"You are a helpful translator. Translate between {self.get_language_name(self.source_lang)} and {self.get_language_name(self.target_lang)}. Respond with both the transcription and translation.",
|
70 |
-
"voice": "alloy",
|
71 |
-
"input_audio_format": "pcm16",
|
72 |
-
"output_audio_format": "pcm16",
|
73 |
-
"input_audio_transcription": {
|
74 |
-
"model": "whisper-1"
|
75 |
-
},
|
76 |
-
"turn_detection": {
|
77 |
-
"type": "server_vad",
|
78 |
-
"threshold": 0.5,
|
79 |
-
"prefix_padding_ms": 300,
|
80 |
-
"silence_duration_ms": 500
|
81 |
-
}
|
82 |
-
}
|
83 |
-
}
|
84 |
-
ws.send(json.dumps(session_update))
|
85 |
-
|
86 |
-
def on_message(self, ws, message):
|
87 |
-
"""๋ฉ์์ง ์์ ์ ํธ์ถ"""
|
88 |
-
try:
|
89 |
-
event = json.loads(message)
|
90 |
-
event_type = event.get("type")
|
91 |
-
|
92 |
-
if event_type == "conversation.item.input_audio_transcription.completed":
|
93 |
-
# ์์ฑ ์ ์ฌ ์๋ฃ
|
94 |
-
transcript = event.get("transcript", "")
|
95 |
-
self.transcript_queue.put(transcript)
|
96 |
-
|
97 |
-
# ๋ฒ์ญ ์์ฒญ
|
98 |
-
self.request_translation(transcript)
|
99 |
-
|
100 |
-
elif event_type == "response.text.delta":
|
101 |
-
# ๋ฒ์ญ ๊ฒฐ๊ณผ ์์
|
102 |
-
delta = event.get("delta", "")
|
103 |
-
self.translation_queue.put(delta)
|
104 |
-
|
105 |
-
elif event_type == "response.audio.delta":
|
106 |
-
# ์ค๋์ค ๋ฐ์ดํฐ ์์
|
107 |
-
audio_data = base64.b64decode(event.get("delta", ""))
|
108 |
-
self.audio_queue.put(audio_data)
|
109 |
-
|
110 |
-
elif event_type == "error":
|
111 |
-
error_msg = event.get("error", {}).get("message", "Unknown error")
|
112 |
-
print(f"Error: {error_msg}")
|
113 |
-
|
114 |
-
except Exception as e:
|
115 |
-
print(f"๋ฉ์์ง ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}")
|
116 |
-
|
117 |
-
def on_error(self, ws, error):
|
118 |
-
"""์ค๋ฅ ๋ฐ์ ์ ํธ์ถ"""
|
119 |
-
print(f"WebSocket ์ค๋ฅ: {error}")
|
120 |
-
self.is_connected = False
|
121 |
-
|
122 |
-
def on_close(self, ws, close_status_code, close_msg):
|
123 |
-
"""์ฐ๊ฒฐ ์ข
๋ฃ ์ ํธ์ถ"""
|
124 |
-
print("WebSocket ์ฐ๊ฒฐ ์ข
๋ฃ")
|
125 |
-
self.is_connected = False
|
126 |
-
|
127 |
-
def get_language_name(self, lang_code):
|
128 |
-
"""์ธ์ด ์ฝ๋๋ฅผ ์ธ์ด ์ด๋ฆ์ผ๋ก ๋ณํ"""
|
129 |
-
languages = {
|
130 |
-
"ko": "Korean",
|
131 |
-
"en": "English",
|
132 |
-
"ja": "Japanese",
|
133 |
-
"zh": "Chinese",
|
134 |
-
"es": "Spanish",
|
135 |
-
"fr": "French"
|
136 |
-
}
|
137 |
-
return languages.get(lang_code, lang_code)
|
138 |
-
|
139 |
-
def request_translation(self, text):
|
140 |
-
"""๋ฒ์ญ ์์ฒญ"""
|
141 |
-
if not self.ws or not self.is_connected:
|
142 |
-
return
|
143 |
-
|
144 |
-
message = {
|
145 |
-
"type": "conversation.item.create",
|
146 |
-
"item": {
|
147 |
-
"type": "message",
|
148 |
-
"role": "user",
|
149 |
-
"content": [{
|
150 |
-
"type": "input_text",
|
151 |
-
"text": f"Translate this {self.get_language_name(self.source_lang)} text to {self.get_language_name(self.target_lang)}: '{text}'"
|
152 |
-
}]
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
self.ws.send(json.dumps(message))
|
157 |
-
|
158 |
-
# ์๋ต ์์ฑ ์์ฒญ
|
159 |
-
response_create = {"type": "response.create"}
|
160 |
-
self.ws.send(json.dumps(response_create))
|
161 |
-
|
162 |
-
def send_audio_chunk(self, audio_data):
|
163 |
-
"""์ค๋์ค ์ฒญํฌ ์ ์ก"""
|
164 |
-
if not self.ws or not self.is_connected:
|
165 |
-
return
|
166 |
|
167 |
-
#
|
168 |
-
|
|
|
|
|
|
|
|
|
169 |
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
def process_audio(self, audio_file):
|
178 |
-
"""์ค๋์ค ํ์ผ ์ฒ๋ฆฌ ๋ฐ ์ ์ก"""
|
179 |
-
if not self.is_connected:
|
180 |
-
return "WebSocket์ด ์ฐ๊ฒฐ๋์ง ์์์ต๋๋ค.", ""
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
with wave.open(audio_file, 'rb') as wf:
|
185 |
-
# ์ค๋์ค๋ฅผ 24kHz PCM16์ผ๋ก ๋ณํ ํ์
|
186 |
-
audio_data = wf.readframes(wf.getnframes())
|
187 |
-
|
188 |
-
# ์ค๋์ค ๋ฐ์ดํฐ๋ฅผ ์ฒญํฌ๋ก ๋๋์ด ์ ์ก
|
189 |
-
chunk_size = 4096
|
190 |
-
for i in range(0, len(audio_data), chunk_size):
|
191 |
-
chunk = audio_data[i:i+chunk_size]
|
192 |
-
self.send_audio_chunk(chunk)
|
193 |
-
|
194 |
-
# ์ค๋์ค ๋ฒํผ ์ปค๋ฐ
|
195 |
-
commit_message = {"type": "input_audio_buffer.commit"}
|
196 |
-
self.ws.send(json.dumps(commit_message))
|
197 |
-
|
198 |
-
# ์ ์ฌ ๋ฐ ๋ฒ์ญ ๊ฒฐ๊ณผ ๋๊ธฐ
|
199 |
-
transcript = ""
|
200 |
-
translation = ""
|
201 |
-
|
202 |
-
# ํ์์์ ์ค์ (10์ด)
|
203 |
-
import time
|
204 |
-
timeout = 10
|
205 |
-
start_time = time.time()
|
206 |
-
|
207 |
-
while time.time() - start_time < timeout:
|
208 |
-
# ์ ์ฌ ๊ฒฐ๊ณผ ํ์ธ
|
209 |
-
try:
|
210 |
-
transcript = self.transcript_queue.get(timeout=0.1)
|
211 |
-
except queue.Empty:
|
212 |
-
pass
|
213 |
-
|
214 |
-
# ๋ฒ์ญ ๊ฒฐ๊ณผ ํ์ธ
|
215 |
-
try:
|
216 |
-
while not self.translation_queue.empty():
|
217 |
-
translation += self.translation_queue.get()
|
218 |
-
except queue.Empty:
|
219 |
-
pass
|
220 |
-
|
221 |
-
if transcript and translation:
|
222 |
-
break
|
223 |
-
|
224 |
-
return transcript, translation
|
225 |
-
|
226 |
-
except Exception as e:
|
227 |
-
return f"์ค๋ฅ: {str(e)}", ""
|
228 |
-
|
229 |
-
def disconnect(self):
|
230 |
-
"""WebSocket ์ฐ๊ฒฐ ์ข
๋ฃ"""
|
231 |
-
if self.ws:
|
232 |
-
self.ws.close()
|
233 |
-
self.is_connected = False
|
234 |
-
return "์ฐ๊ฒฐ ์ข
๋ฃ๋จ"
|
235 |
|
236 |
-
# Gradio ์ธํฐํ์ด์ค
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
|
|
249 |
|
250 |
-
|
251 |
-
if not audio_file:
|
252 |
-
return "์ค๋์ค ํ์ผ์ ์ ํํ์ธ์.", "", None
|
253 |
-
|
254 |
-
translator.source_lang = source_lang
|
255 |
-
translator.target_lang = target_lang
|
256 |
-
|
257 |
-
transcript, translation = translator.process_audio(audio_file)
|
258 |
-
|
259 |
-
# ์ค๋์ค ์๋ต ์ฒ๋ฆฌ (ํ์ฌ๋ ํ
์คํธ๋ง ๋ฐํ)
|
260 |
-
return transcript, translation, None
|
261 |
|
262 |
-
|
263 |
-
|
|
|
264 |
|
265 |
-
|
266 |
-
gr.Markdown("# ๐๏ธ OpenAI Realtime API ์์ฑ ๋ฒ์ญ๊ธฐ")
|
267 |
-
gr.Markdown("์ค์๊ฐ์ผ๋ก ์์ฑ์ ์ ์ฌํ๊ณ ๋ฒ์ญํฉ๋๋ค.")
|
268 |
-
|
269 |
-
with gr.Row():
|
270 |
-
with gr.Column(scale=1):
|
271 |
-
gr.Markdown("### ์ฐ๊ฒฐ ์ํ")
|
272 |
-
connection_status = gr.Checkbox(label="์ฐ๊ฒฐ๋จ", value=False, interactive=False)
|
273 |
-
connect_btn = gr.Button("์ฐ๊ฒฐ", variant="primary")
|
274 |
-
disconnect_btn = gr.Button("์ฐ๊ฒฐ ์ข
๋ฃ", variant="secondary")
|
275 |
-
status_text = gr.Textbox(label="์ํ ๋ฉ์์ง", value="์ฐ๊ฒฐ๋์ง ์์")
|
276 |
-
|
277 |
-
with gr.Row():
|
278 |
-
with gr.Column(scale=2):
|
279 |
-
gr.Markdown("### ์ธ์ด ์ค์ ")
|
280 |
-
with gr.Row():
|
281 |
-
source_lang = gr.Dropdown(
|
282 |
-
choices=[("ํ๊ตญ์ด", "ko"), ("์์ด", "en"), ("์ผ๋ณธ์ด", "ja"),
|
283 |
-
("์ค๊ตญ์ด", "zh"), ("์คํ์ธ์ด", "es"), ("ํ๋์ค์ด", "fr")],
|
284 |
-
value="ko",
|
285 |
-
label="์
๋ ฅ ์ธ์ด"
|
286 |
-
)
|
287 |
-
swap_btn = gr.Button("โ๏ธ", scale=0)
|
288 |
-
target_lang = gr.Dropdown(
|
289 |
-
choices=[("ํ๊ตญ์ด", "ko"), ("์์ด", "en"), ("์ผ๋ณธ์ด", "ja"),
|
290 |
-
("์ค๊ตญ์ด", "zh"), ("์คํ์ธ์ด", "es"), ("ํ๋์ค์ด", "fr")],
|
291 |
-
value="en",
|
292 |
-
label="์ถ๋ ฅ ์ธ์ด"
|
293 |
-
)
|
294 |
-
|
295 |
-
with gr.Row():
|
296 |
-
with gr.Column():
|
297 |
-
gr.Markdown("### ์์ฑ ์
๋ ฅ")
|
298 |
-
audio_input = gr.Audio(
|
299 |
-
source="microphone",
|
300 |
-
type="filepath",
|
301 |
-
label="๋
น์ํ๊ธฐ"
|
302 |
-
)
|
303 |
-
translate_btn = gr.Button("๋ฒ์ญํ๊ธฐ", variant="primary")
|
304 |
-
|
305 |
-
with gr.Row():
|
306 |
-
with gr.Column():
|
307 |
-
gr.Markdown("### ๊ฒฐ๊ณผ")
|
308 |
-
transcript_output = gr.Textbox(
|
309 |
-
label="์ ์ฌ๋ ํ
์คํธ",
|
310 |
-
placeholder="์์ฑ ์ ์ฌ ๊ฒฐ๊ณผ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...",
|
311 |
-
lines=3
|
312 |
-
)
|
313 |
-
translation_output = gr.Textbox(
|
314 |
-
label="๋ฒ์ญ๋ ํ
์คํธ",
|
315 |
-
placeholder="๋ฒ์ญ ๊ฒฐ๊ณผ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค...",
|
316 |
-
lines=3
|
317 |
-
)
|
318 |
-
audio_output = gr.Audio(
|
319 |
-
label="๋ฒ์ญ๋ ์์ฑ",
|
320 |
-
type="filepath"
|
321 |
-
)
|
322 |
-
|
323 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
324 |
-
connect_btn.click(
|
325 |
-
fn=connect,
|
326 |
-
outputs=[status_text, connection_status]
|
327 |
-
)
|
328 |
-
|
329 |
-
disconnect_btn.click(
|
330 |
-
fn=disconnect,
|
331 |
-
outputs=[status_text, connection_status]
|
332 |
-
)
|
333 |
-
|
334 |
-
swap_btn.click(
|
335 |
-
fn=swap_languages,
|
336 |
-
inputs=[source_lang, target_lang],
|
337 |
-
outputs=[source_lang, target_lang]
|
338 |
-
)
|
339 |
-
|
340 |
-
translate_btn.click(
|
341 |
-
fn=translate_audio,
|
342 |
-
inputs=[audio_input, source_lang, target_lang],
|
343 |
-
outputs=[transcript_output, translation_output, audio_output]
|
344 |
-
)
|
345 |
-
|
346 |
-
gr.Markdown("""
|
347 |
-
### ๐ ์ฌ์ฉ ๋ฐฉ๋ฒ
|
348 |
-
1. **์ฐ๊ฒฐ** ๋ฒํผ์ ํด๋ฆญํ์ฌ OpenAI Realtime API์ ์ฐ๊ฒฐํฉ๋๋ค.
|
349 |
-
2. ์
๋ ฅ ์ธ์ด์ ์ถ๋ ฅ ์ธ์ด๋ฅผ ์ ํํฉ๋๋ค.
|
350 |
-
3. ๋ง์ดํฌ ๋ฒํผ์ ํด๋ฆญํ์ฌ ์์ฑ์ ๋
น์ํฉ๋๋ค.
|
351 |
-
4. **๋ฒ์ญํ๊ธฐ** ๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ ์ฌ ๋ฐ ๋ฒ์ญ์ด ์งํ๋ฉ๋๋ค.
|
352 |
-
|
353 |
-
### โ ๏ธ ์ฃผ์์ฌํญ
|
354 |
-
- ํ๊ฒฝ ๋ณ์ `OPENAI_API_KEY`๊ฐ ์ค์ ๋์ด ์์ด์ผ ํฉ๋๋ค.
|
355 |
-
- ๊ธด ์ค๋์ค์ ๊ฒฝ์ฐ ์ฒ๋ฆฌ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆด ์ ์์ต๋๋ค.
|
356 |
-
""")
|
357 |
|
358 |
-
|
|
|
|
|
|
|
|
|
359 |
|
360 |
-
# ์คํ
|
361 |
if __name__ == "__main__":
|
362 |
-
|
363 |
-
print("""
|
364 |
-
ํ์ํ ํจํค์ง:
|
365 |
-
pip install gradio websocket-client pyaudio wave numpy
|
366 |
-
|
367 |
-
ํ๊ฒฝ ๋ณ์ ์ค์ :
|
368 |
-
export OPENAI_API_KEY="your-api-key-here"
|
369 |
-
""")
|
370 |
-
|
371 |
-
demo = create_interface()
|
372 |
-
demo.launch(share=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
|
|
|
|
|
|
|
|
|
|
3 |
import os
|
4 |
+
from dotenv import load_dotenv
|
|
|
|
|
|
|
5 |
|
6 |
+
# ํ๊ฒฝ๋ณ์ ๋ก๋
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# OpenAI ํด๋ผ์ด์ธํธ ์ค์
|
10 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
11 |
+
if not api_key:
|
12 |
+
print("โ ๏ธ OPENAI_API_KEY๋ฅผ .env ํ์ผ์ ์ค์ ํ์ธ์!")
|
13 |
+
print("์: OPENAI_API_KEY=sk-...")
|
14 |
+
|
15 |
+
client = openai.OpenAI(api_key=api_key)
|
16 |
+
|
17 |
+
def translate_audio(audio_file, source_lang, target_lang):
|
18 |
+
"""์์ฑ ํ์ผ์ ๋ฒ์ญํ๋ ํจ์"""
|
19 |
+
if not audio_file:
|
20 |
+
return "์ค๋์ค ํ์ผ์ ์
๋ก๋ํ๊ฑฐ๋ ๋
น์ํ์ธ์.", "", None
|
21 |
+
|
22 |
+
if not api_key:
|
23 |
+
return "API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.", "", None
|
24 |
+
|
25 |
+
try:
|
26 |
+
# 1. Whisper๋ก ์์ฑ์ ํ
์คํธ๋ก ๋ณํ
|
27 |
+
with open(audio_file, "rb") as f:
|
28 |
+
transcript = client.audio.transcriptions.create(
|
29 |
+
model="whisper-1",
|
30 |
+
file=f
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
+
original_text = transcript.text
|
33 |
+
|
34 |
+
# 2. GPT-4๋ก ๋ฒ์ญ
|
35 |
+
response = client.chat.completions.create(
|
36 |
+
model="gpt-4",
|
37 |
+
messages=[
|
38 |
+
{"role": "system", "content": f"Translate from {source_lang} to {target_lang}. Only provide the translation without any explanation."},
|
39 |
+
{"role": "user", "content": original_text}
|
40 |
+
],
|
41 |
+
temperature=0.3
|
42 |
+
)
|
43 |
+
translated_text = response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# 3. TTS๋ก ๋ฒ์ญ๋ ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํ
|
46 |
+
tts_response = client.audio.speech.create(
|
47 |
+
model="tts-1",
|
48 |
+
voice="alloy",
|
49 |
+
input=translated_text
|
50 |
+
)
|
51 |
|
52 |
+
# ์์ฑ ํ์ผ ์ ์ฅ
|
53 |
+
output_file = "translated_audio.mp3"
|
54 |
+
with open(output_file, "wb") as f:
|
55 |
+
f.write(tts_response.content)
|
56 |
|
57 |
+
return original_text, translated_text, output_file
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
except Exception as e:
|
60 |
+
return f"์ค๋ฅ ๋ฐ์: {str(e)}", "", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
# Gradio ์ธํฐํ์ด์ค
|
63 |
+
with gr.Blocks(title="์์ฑ ๋ฒ์ญ๊ธฐ") as app:
|
64 |
+
gr.Markdown("# ๐๏ธ AI ์์ฑ ๋ฒ์ญ๊ธฐ")
|
65 |
+
gr.Markdown("์์ฑ์ ๋
น์ํ๊ฑฐ๋ ์
๋ก๋ํ๋ฉด ์๋์ผ๋ก ๋ฒ์ญํฉ๋๋ค.")
|
66 |
+
|
67 |
+
with gr.Row():
|
68 |
+
source_lang = gr.Dropdown(
|
69 |
+
["Korean", "English", "Japanese", "Chinese", "Spanish", "French"],
|
70 |
+
value="Korean",
|
71 |
+
label="์
๋ ฅ ์ธ์ด"
|
72 |
+
)
|
73 |
+
target_lang = gr.Dropdown(
|
74 |
+
["Korean", "English", "Japanese", "Chinese", "Spanish", "French"],
|
75 |
+
value="English",
|
76 |
+
label="์ถ๋ ฅ ์ธ์ด"
|
77 |
+
)
|
78 |
|
79 |
+
audio_input = gr.Audio(
|
80 |
+
sources=["microphone", "upload"],
|
81 |
+
type="filepath",
|
82 |
+
label="์์ฑ ์
๋ ฅ (๋
น์ ๋๋ ํ์ผ ์
๋ก๋)"
|
83 |
+
)
|
84 |
|
85 |
+
translate_btn = gr.Button("๋ฒ์ญํ๊ธฐ", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
with gr.Row():
|
88 |
+
original_text = gr.Textbox(label="์๋ณธ ํ
์คํธ", lines=3)
|
89 |
+
translated_text = gr.Textbox(label="๋ฒ์ญ๋ ํ
์คํธ", lines=3)
|
90 |
|
91 |
+
audio_output = gr.Audio(label="๋ฒ์ญ๋ ์์ฑ", type="filepath")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
translate_btn.click(
|
94 |
+
translate_audio,
|
95 |
+
inputs=[audio_input, source_lang, target_lang],
|
96 |
+
outputs=[original_text, translated_text, audio_output]
|
97 |
+
)
|
98 |
|
|
|
99 |
if __name__ == "__main__":
|
100 |
+
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|