| """DaRi โ ENโKO Technical Translation API | ๋ค๋ฆฌ(bridge) between languages""" |
| import gradio as gr |
| import requests |
|
|
| API_URL = "http://168.107.54.158:8000" |
| API_KEY = "kt_b22b7beb939da8b0e963679413b5b663" |
| HEADERS = {"X-API-Key": API_KEY, "Content-Type": "application/json"} |
|
|
|
|
| def translate(text, direction): |
| src = "en" if direction == "EN โ KO" else "ko" |
| tgt = "ko" if direction == "EN โ KO" else "en" |
| try: |
| r = requests.post(f"{API_URL}/v1/translate", json={ |
| "text": text, "source_lang": src, "target_lang": tgt, "use_tm": True |
| }, headers=HEADERS, timeout=15) |
| data = r.json() |
| translation = data.get("translation") or "" |
| suggestions = data.get("tm_suggestions", []) |
| tm_text = "" |
| for s in suggestions[:3]: |
| sim = s.get("similarity", 0) |
| tm_text += f"**[{sim:.0%}]** {s['source']}\nโ {s['target']}\n\n" |
| if not translation and tm_text: |
| translation = suggestions[0]["target"] if suggestions else "๋งค์นญ ์์" |
| return translation or "๋งค์นญ ์์ (MT ๋ชจ๋ธ ์ค๋น ์ค)", tm_text or "๋งค์นญ ์์" |
| except Exception as e: |
| return f"์ค๋ฅ: {e}", "" |
|
|
|
|
| def glossary(term): |
| try: |
| r = requests.get(f"{API_URL}/v1/glossary", params={"term": term}, headers=HEADERS, timeout=10) |
| results = r.json().get("results", []) |
| if not results: |
| return "๊ฒฐ๊ณผ ์์" |
| return "\n".join(f"**{g['source']}** โ {g['target']} `{g.get('domain','')}`" for g in results[:10]) |
| except Exception as e: |
| return f"์ค๋ฅ: {e}" |
|
|
|
|
| def quality(source, translation): |
| try: |
| r = requests.post(f"{API_URL}/v1/quality", json={ |
| "source": source, "translation": translation |
| }, headers=HEADERS, timeout=5) |
| m = r.json().get("metrics", {}) |
| score = m.get("quality_score", "N/A") |
| emoji = "๐ข" if score == 1 else "๐ก" if score >= 0.7 else "๐ด" |
| return f"""{emoji} **ํ์ง ์ ์**: {score} |
| ๐ **๊ธธ์ด ๋น์จ**: {m.get('length_ratio', 'N/A')} |
| ๐ **๋น ๋ฒ์ญ**: {'์ โ ๏ธ' if m.get('empty') else '์๋์ค โ
'} |
| ๐ **์์ค ๋ณต์ฌ**: {'๊ฐ์ง โ ๏ธ' if m.get('copy_detected') else '์ ์ โ
'}""" |
| except Exception as e: |
| return f"์ค๋ฅ: {e}" |
|
|
|
|
| def get_api_key(email, name): |
| try: |
| r = requests.post(f"{API_URL}/v1/auth/token", json={"email": email, "name": name}, timeout=5) |
| data = r.json() |
| key = data.get("api_key", "") |
| return f"""โ
**API Key**: `{key}` |
| |
| **์ฌ์ฉ๋ฒ**: |
| ```bash |
| curl -X POST {API_URL}/v1/translate \\ |
| -H "X-API-Key: {key}" \\ |
| -H "Content-Type: application/json" \\ |
| -d '{{"text":"patent application","source_lang":"en","target_lang":"ko"}}' |
| ``` |
| |
| ๋ฌด๋ฃ ํ๋: ์ 50,000์ | [API ๋ฌธ์]({API_URL}/docs)""" |
| except Exception as e: |
| return f"์ค๋ฅ: {e}" |
|
|
|
|
| CSS = """ |
| .gradio-container {max-width: 960px !important} |
| h1 {background: linear-gradient(90deg, #00d2ff, #3a7bd5); -webkit-background-clip: text; -webkit-text-fill-color: transparent} |
| """ |
|
|
| with gr.Blocks(title="DaRi โ ENโKO Translation API", theme=gr.themes.Soft(), css=CSS) as demo: |
| gr.Markdown(""" |
| # DaRi โ ๋ค๋ฆฌ |
| ### ENโKO Technical Translation API |
| |
| **62.9M** parallel pairs ยท **844K** glossary terms ยท Patent ยท Medical ยท IT ยท Legal ยท ESG |
| """) |
| |
| with gr.Tab("๐ค ๋ฒ์ญ"): |
| direction = gr.Radio(["EN โ KO", "KO โ EN"], value="EN โ KO", label="๋ฐฉํฅ") |
| input_text = gr.Textbox(label="์
๋ ฅ", lines=3, placeholder="The device shall comply with FDA regulations.") |
| translate_btn = gr.Button("๋ฒ์ญ", variant="primary") |
| output_text = gr.Textbox(label="๊ฒฐ๊ณผ", lines=3) |
| tm_output = gr.Markdown(label="Translation Memory ๋งค์นญ") |
| translate_btn.click(translate, [input_text, direction], [output_text, tm_output]) |
| |
| with gr.Tab("๐ ์ฉ์ด์ง"): |
| term_input = gr.Textbox(label="๊ฒ์์ด", placeholder="patent, surgery, device...") |
| term_btn = gr.Button("๊ฒ์", variant="primary") |
| term_output = gr.Markdown() |
| term_btn.click(glossary, term_input, term_output) |
| |
| with gr.Tab("โ
ํ์ง ํ๊ฐ"): |
| with gr.Row(): |
| qa_source = gr.Textbox(label="์๋ฌธ", lines=2, placeholder="medical device") |
| qa_trans = gr.Textbox(label="๋ฒ์ญ", lines=2, placeholder="์๋ฃ๊ธฐ๊ธฐ") |
| qa_btn = gr.Button("ํ๊ฐ", variant="primary") |
| qa_output = gr.Markdown() |
| qa_btn.click(quality, [qa_source, qa_trans], qa_output) |
| |
| with gr.Tab("๐ API Key"): |
| gr.Markdown("๋ฌด๋ฃ API ํค๋ฅผ ๋ฐ๊ธ๋ฐ์ผ์ธ์. ์ 50,000์๊น์ง ๋ฌด๋ฃ์
๋๋ค.") |
| with gr.Row(): |
| key_email = gr.Textbox(label="์ด๋ฉ์ผ") |
| key_name = gr.Textbox(label="์ด๋ฆ") |
| key_btn = gr.Button("๋ฐ๊ธ", variant="primary") |
| key_output = gr.Markdown() |
| key_btn.click(get_api_key, [key_email, key_name], key_output) |
| |
| gr.Markdown(f""" |
| --- |
| **DaRi** ยฉ 2026 | [API Docs]({API_URL}/docs) | [Contact](mailto:dogdoh1338@icloud.com) |
| |
| *DaRi(๋ค๋ฆฌ) = Bridge between ENโKO. Powered by 63M parallel corpus.* |
| """) |
|
|
| demo.launch() |
|
|