Spaces:
Sleeping

dev-strender Claude Opus 4.7 (1M context) commited on
Commit
f338c84
ยท
1 Parent(s): 43bd06b

feat: add title proofreading sandbox tab

Browse files

Solar-pro2 vs solar-pro3 side-by-side comparison for Korean newspaper
title proofreading. Default prompt loaded internally and not exposed
in the UI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Dockerfile CHANGED
@@ -15,6 +15,7 @@ RUN pip install -r requirements.txt
15
 
16
  COPY app.py pipelines.py pipelines_v24.py postprocess.py text_splitter.py diff_utils.py ./
17
  COPY blindtest ./blindtest
 
18
  COPY prompts ./prompts
19
  COPY data ./data
20
 
 
15
 
16
  COPY app.py pipelines.py pipelines_v24.py postprocess.py text_splitter.py diff_utils.py ./
17
  COPY blindtest ./blindtest
18
+ COPY title_proofread ./title_proofread
19
  COPY prompts ./prompts
20
  COPY data ./data
21
 
app.py CHANGED
@@ -1,9 +1,11 @@
1
  """Chosun proofreading demo โ€” Gradio UI.
2
 
3
- Two tabs:
4
- - v16 (legacy): solar-pro3 with the 260408_v16 single-pass pipeline.
5
  - v24 (new): solar-pro3 with FT + self-consistency ร— 2 + tool-calling
6
  judge. paragraph F1 47.04 (vs solar-pro2 prod_251231 mean 44.86).
 
 
 
7
  """
8
 
9
  import os
@@ -15,6 +17,7 @@ from pipelines import list_prompts
15
  from postprocess import load_vocabulary
16
 
17
  from blindtest import build_feedback_tab
 
18
 
19
  load_dotenv()
20
 
@@ -40,7 +43,6 @@ _v24_prompt = _default_prompt("dev_260429_v24", "dev_260429_v24")
40
 
41
  with gr.Blocks(title="Chosun ๊ต์ •๊ต์—ด ๋ฐ๋ชจ") as demo:
42
  gr.Markdown("# Chosun ๊ต์ •๊ต์—ด ๋ฐ๋ชจ")
43
- gr.Markdown("solar-pro3 ๊ธฐ๋ฐ˜ ๊ต์ • ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•˜๊ณ  ํ”ผ๋“œ๋ฐฑ์„ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.")
44
 
45
  with gr.Tabs():
46
  with gr.Tab("v24 (new ยท 260429)"):
@@ -59,27 +61,29 @@ with gr.Blocks(title="Chosun ๊ต์ •๊ต์—ด ๋ฐ๋ชจ") as demo:
59
  elem_id_prefix="v16",
60
  )
61
 
 
 
 
62
  _SHORTCUT_JS = """
63
  () => {
64
  if (window.__chosunShortcutBound) return;
65
  window.__chosunShortcutBound = true;
 
66
  document.addEventListener('keydown', (e) => {
67
- if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
 
 
 
 
 
 
 
68
  e.preventDefault();
69
- // Find the run button inside the currently visible tab. Tab
70
- // panels gradio doesn't render get hidden via CSS, so checking
71
- // offsetParent / getBoundingClientRect filters them out.
72
- const candidates = document.querySelectorAll(
73
- '#v16-run-btn, #v24-run-btn, #v16-run-btn button, #v24-run-btn button'
74
- );
75
- for (const el of candidates) {
76
- if (el.offsetParent !== null) {
77
- el.click();
78
- return;
79
- }
80
- }
81
  }
82
- });
83
  }
84
  """
85
  demo.load(None, None, None, js=_SHORTCUT_JS)
 
1
  """Chosun proofreading demo โ€” Gradio UI.
2
 
3
+ Tabs:
 
4
  - v24 (new): solar-pro3 with FT + self-consistency ร— 2 + tool-calling
5
  judge. paragraph F1 47.04 (vs solar-pro2 prod_251231 mean 44.86).
6
+ - v16 (legacy): solar-pro3 with the 260408_v16 single-pass pipeline.
7
+ - ์ œ๋ชฉ ๊ต์—ด (sandbox): solar-pro2 vs solar-pro3 side-by-side comparison
8
+ for newspaper title proofreading (default prompt hidden in UI).
9
  """
10
 
11
  import os
 
17
  from postprocess import load_vocabulary
18
 
19
  from blindtest import build_feedback_tab
20
+ from title_proofread import build_title_proofread_tab
21
 
22
  load_dotenv()
23
 
 
43
 
44
  with gr.Blocks(title="Chosun ๊ต์ •๊ต์—ด ๋ฐ๋ชจ") as demo:
45
  gr.Markdown("# Chosun ๊ต์ •๊ต์—ด ๋ฐ๋ชจ")
 
46
 
47
  with gr.Tabs():
48
  with gr.Tab("v24 (new ยท 260429)"):
 
61
  elem_id_prefix="v16",
62
  )
63
 
64
+ with gr.Tab("์ œ๋ชฉ ๊ต์—ด (sandbox)"):
65
+ build_title_proofread_tab(client=client)
66
+
67
  _SHORTCUT_JS = """
68
  () => {
69
  if (window.__chosunShortcutBound) return;
70
  window.__chosunShortcutBound = true;
71
+ // Capture phase so Code-editor (Monaco) doesn't swallow the keystroke.
72
  document.addEventListener('keydown', (e) => {
73
+ if (!((e.metaKey || e.ctrlKey) && e.key === 'Enter')) return;
74
+ // Pick the run button on the *visible* tab (others' buttons are hidden).
75
+ const ids = ['title-proofread-run-btn', 'v24-run-btn', 'v16-run-btn'];
76
+ for (const id of ids) {
77
+ const root = document.getElementById(id);
78
+ if (!root) continue;
79
+ if (root.offsetParent === null) continue; // hidden (different tab)
80
+ const btn = root.querySelector('button') || root;
81
  e.preventDefault();
82
+ e.stopPropagation();
83
+ btn.click();
84
+ return;
 
 
 
 
 
 
 
 
 
85
  }
86
+ }, true);
87
  }
88
  """
89
  demo.load(None, None, None, js=_SHORTCUT_JS)
title_proofread/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ """์ œ๋ชฉ ๊ต์—ด ๋ฐ๋ชจ ๋ชจ๋“ˆ โ€” ํŽธ์ง‘ ๊ฐ€๋Šฅํ•œ ํ”„๋กฌํ”„ํŠธ sandbox."""
2
+
3
+ from .ui import build_title_proofread_tab
4
+
5
+ __all__ = ["build_title_proofread_tab"]
title_proofread/prompts/prompt_dev_v1/system.txt ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ์—ญํ• 
2
+
3
+ ๋‹น์‹ ์€ ํ•œ๊ตญ ์‹ ๋ฌธ ์ œ๋ชฉ์„ ๋‹ค๋ฃจ๋Š” **๊ต์—ด ์ „๋ฌธ๊ฐ€** ๋‹ค.
4
+ ๋‹น์‹ ์€ *์ œ๋ชฉ ์ƒ์„ฑ๊ธฐยท๋ฆฌ๋ผ์ดํ„ฐ๊ฐ€ ์•„๋‹ˆ๋‹ค*. ๋‹น์‹ ์˜ ๋‹จ ํ•˜๋‚˜์˜ ์ž„๋ฌด๋Š”
5
+ ๋ช…๋ฐฑํ•œ ์˜คํƒˆ์žยท๋งž์ถค๋ฒ•ยท๋„์–ด์“ฐ๊ธฐยท์กฐ์‚ฌ ์˜ค๋ฅ˜๋งŒ ์žก๋Š” ๊ฒƒ์ด๋‹ค.
6
+
7
+ # ์ž‘์—… ์ •์˜
8
+
9
+ ์ž…๋ ฅ์œผ๋กœ ํ•œ๊ตญ ์‹ ๋ฌธ ์ œ๋ชฉ 1๊ฐœ์™€ ๊ทธ ์ œ๋ชฉ์˜ ์นดํ…Œ๊ณ ๋ฆฌ (`์นผ๋Ÿผ` ๋˜๋Š” `์ผ๋ฐ˜๊ธฐ์‚ฌ`) ๋ฅผ ๋ฐ›๋Š”๋‹ค.
10
+ ๋‹ค์Œ ์ ˆ์ฐจ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ผ:
11
+
12
+ 1. ์ œ๋ชฉ์„ ํ•œ ๊ธ€์ž์”ฉ ๊ฒ€ํ† ํ•œ๋‹ค.
13
+ 2. **๋ช…๋ฐฑํ•œ ์˜คํƒˆ์žยท๋งž์ถค๋ฒ•ยท๋„์–ด์“ฐ๊ธฐยท์กฐ์‚ฌ ์˜ค๋ฅ˜๋งŒ** ์‹๋ณ„ํ•œ๋‹ค.
14
+ 3. ์‹๋ณ„๋œ ์˜ค๋ฅ˜๋งŒ *์ตœ์†Œํ•œ์œผ๋กœ* ์ˆ˜์ •ํ•œ๋‹ค.
15
+ 4. **์ˆ˜์ •ํ•  ๊ฒƒ์ด ์—†์œผ๋ฉด ์›๋ฌธ์„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•œ๋‹ค.**
16
+
17
+ ==================================================
18
+ === CRITICAL: ์˜์‹ฌ๋˜๋ฉด ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค (do no harm > catch all) ===
19
+ ์ œ๋ชฉ์€ ์งง๋‹ค. ํ•œ ๊ธ€์ž๋งŒ ์ž˜๋ชป ๊ณ ์ณ๋„ ์˜๋ฏธ๊ฐ€ ๋ง๊ฐ€์ง„๋‹ค.
20
+ ==================================================
21
+
22
+ # CRITICAL ๋ณด์กด ๊ทœ์น™ (PRIORITY ์ˆœ์„œ)
23
+
24
+ ## PRIORITY 1: ์˜๋ฏธยท๊ตฌ์กฐ ์ ˆ๋Œ€ ๋ณด์กด (MANDATORY)
25
+
26
+ NEVER ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค:
27
+ - ์˜๋ฏธยทํ•ต์‹ฌ ํ‚ค์›Œ๋“œยท๊ณ ์œ ๋ช…์‚ฌยท์ˆ˜์น˜ยท๊ฐ•์กฐ์  ๋ณ€๊ฒฝ
28
+ - ๋™์˜์–ด ๊ต์ฒด ("์ง„์ž…" โ†’ "์‹œ์ž‘" ๊ธˆ์ง€)
29
+ - ์ œ๋ชฉ ๊ธธ์ด ์กฐ์ • (์ค„์ด๊ธฐยท๋Š˜๋ฆฌ๊ธฐ ๋ชจ๋‘ ๊ธˆ์ง€)
30
+ - ์–ด์ˆœยท์ ‘์†์–ด ๋ณ€๊ฒฝ
31
+ - ์ถ”์ƒํ™”ยท์ผ๋ฐ˜ํ™” ("30%" โ†’ "๋งŽ์ด" ๊ธˆ์ง€)
32
+
33
+ ## PRIORITY 2: ์˜๋„๋œ ๊ฐ•์กฐ ํ‘œ๊ธฐ ๋ณด์กด (MANDATORY)
34
+
35
+ ๋‹ค์Œ ํ‘œ๊ธฐ๋“ค์€ ์˜๋„๋œ ์‹ ํ˜ธ๋‹ค. **์ข…๋ฅ˜ยท์œ„์น˜ยท๊ฐœ์ˆ˜ ๋ชจ๋‘ ๋ณ€๊ฒฝ ๊ธˆ์ง€**:
36
+
37
+ - **ํฐ๋”ฐ์˜ดํ‘œ `" "`**: ํ•ต์‹ฌ ์ธ๋ฌผ์˜ ์ง์ ‘ ๋ฐœ์–ธ
38
+ ์˜ˆ: `"๋‚˜๋Š” ์ง€์‹œํ•œ ์  ์—†๋‹ค"โ€ฆ ๅ‰์žฅ๊ด€, ๋ฒ•์ •์„œ ํ˜์˜ ๋ถ€์ธ`
39
+ - **์ž‘์€๋”ฐ์˜ดํ‘œ `' '`**: ์‹ ์กฐ์–ดยท์€์–ดยท๋ณ„๋ช…ยท์‚ฌ๊ฑด๋ช…
40
+ ์˜ˆ: `'ํ›„์ฒœ์  ๋‚œ๋…'`, `'ํ—ˆ๋ฆฌ'`, `'์žฅ๋Œ€ํ•œ ๋ถ„๋…ธ'`, `'๊ฐœ๋ฅด์‹ '`
41
+ - **ํ•œ์ž ์•ฝ์–ด**: `้ซ˜์ˆ˜์ต`, `็”ท`, `ๅฅณ`, `ๅ‰`, `ๅ…จ` ๋“ฑ 1~2์ž ์••์ถ• ํ‘œํ˜„
42
+ โ†’ ํ’€์–ด์“ฐ์ง€ ์•Š๋Š”๋‹ค. NEVER `้ซ˜์ˆ˜์ต` โ†’ `๊ณ ์ˆ˜์ต`
43
+ - **๋ง์ค„์ž„ํ‘œ `โ€ฆ`**: ํŒฉํŠธ์™€ ์‹œ์‚ฌ์ ยท๊ฒฐ๋ก ์„ ์—ฐ๊ฒฐํ•˜๋Š” ์˜๋„๋œ ๊ตฌ๋‘์ 
44
+ โ†’ ์œ„์น˜ยท๊ฐœ์ˆ˜ ๊ทธ๋Œ€๋กœ ์œ ์ง€
45
+ - **์ˆ˜์น˜ ํ‘œ๊ธฐ ์–‘์‹**: `40์กฐ์›`, `1๋งŒ9585๊ฑด`, `22๋งŒ8000๋ช…`, `30%`, `2๋ฐฐ`
46
+ โ†’ ๋งŒยท์–ตยท์กฐ ํ•œ๊ธ€ ๋ณ‘๊ธฐ ์–‘์‹ ๋ณ€๊ฒฝ ๊ธˆ์ง€, ๋‹จ์œ„ยท๊ธฐํ˜ธ (`%`ยท`๋ฐฐ`ยท`๋ช…`ยท`์›`) ๋ณ€๊ฒฝ ๊ธˆ์ง€
47
+ - **๋”ฐ์˜ดํ‘œ ์ข…๋ฅ˜ ๋ณ€ํ™˜ ์ ˆ๋Œ€ ๊ธˆ์ง€**: ํฐ๋”ฐ์˜ดํ‘œ โ†” ์ž‘์€๋”ฐ์˜ดํ‘œ ๋ณ€ํ™˜์€ ์˜๋ฏธ๋ฅผ ์™„์ „ํžˆ ๋ฐ”๊พผ๋‹ค
48
+
49
+ ## PRIORITY 3: ์ •๋ณด ์ถ”๊ฐ€/์‚ญ์ œ ๊ธˆ์ง€ (MANDATORY)
50
+
51
+ NEVER ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค:
52
+ - ์›๋ฌธ์— ์—†๋˜ ์ธ๋ฌผยท์ˆ˜์น˜ยท์‚ฌ๊ฑดยทํ‰๊ฐ€ ์ถ”๊ฐ€
53
+ - ํ•ต์‹ฌ ์ •๋ณด ์ž„์˜ ์‚ญ์ œ
54
+ - ๊ด„ํ˜ธ `()` ๋ฅผ ์‚ฌ์šฉํ•œ ๋ถ€์—ฐ ์„ค๋ช… ์ถ”๊ฐ€
55
+
56
+ ## PRIORITY 4: ํ†คยท์–ด๋ฏธ ๊ฐ•๋„ ๋ณด์กด (HIGH)
57
+
58
+ NEVER ๋‹จ์ •ํ˜• โ†” ์™„ํ™”ํ˜•์„ ์ž„์˜ ๋ณ€ํ™˜:
59
+ - `~๋ฌด๋„ˆ์ง„๋‹ค` โ†’ `~๋ฌด๋„ˆ์งˆ ์ˆ˜ ์žˆ๋‹ค` ์•ฝํ™” ๊ธˆ์ง€
60
+ - `๊ตฌ์†` โ†’ `๊ตฌ์†๋  ๊ฐ€๋Šฅ์„ฑ` ์•ฝํ™” ๊ธˆ์ง€
61
+ - ๋ฐ˜๋Œ€๋กœ ์™„ํ™”ํ˜•์„ ๋‹จ์ •ํ˜•์œผ๋กœ ๊ฐ•ํ™”๋„ ๊ธˆ์ง€
62
+
63
+ ## PRIORITY 5: ๋ฒ•์กฐ ์šฉ์–ด ์ •ํ™•์„ฑ (CRITICAL โ€” ํ•ด๋‹น ์‹œ)
64
+
65
+ ๋ฒ•์กฐยท์ˆ˜์‚ฌยท์žฌํŒ ๊ด€๋ จ ํ‘œํ˜„์ด ๋“ฑ์žฅํ•˜๋ฉด **๊ฐ€์žฅ ๋ณด์ˆ˜์ ์œผ๋กœ** ์ฒ˜๋ฆฌํ•˜๋ผ:
66
+
67
+ - **๋‹จ๊ณ„ ํ‘œ๊ธฐ ๋ณ€๊ฒฝ ๊ธˆ์ง€**: ์••์ˆ˜์ˆ˜์ƒ‰ โ†’ ์†Œํ™˜ โ†’ ๊ตฌ์† โ†’ ๊ธฐ์†Œ โ†’ ๊ตฌํ˜• โ†’ ์„ ๊ณ  โ†’ ํ•ญ์†Œ
68
+ - ๊ฐ ๋‹จ๊ณ„๋Š” ๋ฒ•์  ์˜๋ฏธ๊ฐ€ ๋‹ค๋ฅด๋‹ค. ๋‹จ๊ณ„ ๊ฐ„ ์ž„์˜ ์ด๋™ยท์•ฝํ™” ๊ธˆ์ง€
69
+ - ์˜ˆ: `๊ตฌ์†` ์„ `์ฒดํฌ` ๋กœ ๋ณ€๊ฒฝ ๊ธˆ์ง€, `๊ธฐ์†Œ๋๋‹ค` ๋ฅผ `์žฌํŒ์— ๋„˜๊ฒผ๋‹ค` ๋กœ ๋ณ€๊ฒฝ ๊ธˆ์ง€
70
+
71
+ - **์‹ ๋ถ„ ํ‘œ๊ธฐ ์ •ํ™•์„ฑ**: `ๅ‰์žฅ๊ด€`, `์ „์ง โ—‹โ—‹`, `โ—‹โ—‹ ์ „ ๋Œ€ํ‘œ`
72
+ - `ๅ‰` ๋ฅผ ํ’€์–ด์“ฐ๊ฑฐ๋‚˜ ํ˜„์ง ํ‘œ๊ธฐ๋กœ ๋ณ€๊ฒฝ ๊ธˆ์ง€
73
+
74
+ - **๋ฏธํ™•์ • ์‚ฌ์‹ค ๋‹จ์ • ์ ˆ๋Œ€ ๊ธˆ์ง€** (๊ฐ€์žฅ ์ค‘์š”): NEVER ๋‹ค์Œ ๋ณ€ํ™˜์„ ์ˆ˜ํ–‰ํ•œ๋‹ค
75
+ - `ํ˜์˜๋ฅผ ๋ฐ›๋Š”๋‹ค` โ†’ `์œ ์ฃ„๋‹ค` ๊ธˆ์ง€
76
+ - `๊ธฐ์†Œ๋๋‹ค` โ†’ `~๋‹ค` ๋‹จ์ • ๊ธˆ์ง€
77
+ - `~์œผ๋กœ ์•Œ๋ ค์กŒ๋‹ค` โ†’ `~ํ–ˆ๋‹ค` ๊ธˆ์ง€
78
+ - `์˜ํ˜น` โ†’ ๋‹จ์ • ํ‘œํ˜„ ๊ธˆ์ง€
79
+ - ๋ฐ˜๋Œ€ ๋ฐฉํ–ฅ(๋‹จ์ •ํ˜• โ†’ ์™„ํ™”)๋„ ์ž„์˜ ๋ณ€ํ™˜ ๊ธˆ์ง€
80
+
81
+ ## PRIORITY 6: ์นผ๋Ÿผ ํ†ค ๋ณด์กด (HIGH โ€” `category=์นผ๋Ÿผ` ์‹œ)
82
+
83
+ ์นผ๋Ÿผ/์‚ฌ์„ค ์ œ๋ชฉ์€ *ํ•„์ž์˜ ์ž…์žฅ* ์ด ํ•ต์‹ฌ์ด๋‹ค.
84
+
85
+ NEVER ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค:
86
+ - ๋น„ํŒยทํ’์žยท๋„๋ฐœ ํ†ค์„ ํ‰ํƒ„ํ•œ ๊ฐ๊ด€ ํ†ค์œผ๋กœ ์ค‘ํ™”
87
+ - ์˜๋ฌธยท์ฃผ์žฅํ˜• ์–ด๋ฏธ๋ฅผ ํ‰์„œํ˜•์œผ๋กœ ์ž„์˜ ๋ณ€ํ™˜
88
+ - `ยทยทยท์ธ๊ฐ€` โ†’ `ยทยทยท์ด๋‹ค` ๊ธˆ์ง€
89
+ - `ยทยทยทํ•ด์•ผ ํ•œ๋‹ค` โ†’ `ยทยทยทํ•œ๋‹ค` ๊ธˆ์ง€
90
+ - `ยทยทยท๋‹ค๋Š” ์ฐฉ๊ฐ` โ†’ `ยทยทยท๋‹ค` ๊ธˆ์ง€
91
+ - ์‚ฌ์ž์„ฑ์–ดยท๊ณ ์‚ฌยท์ธ์šฉยท์—ญ์„ค (`์•„ํ‚ฌ๋ ˆ์Šค๊ฑด`ยท`ํ”ผ๋กœ์Šค์˜ ์Šน๋ฆฌ` ๋“ฑ) ํ’€์–ด์“ฐ๊ธฐ ๊ธˆ์ง€
92
+ - ์˜๋„๋œ ์ˆ˜์‚ฌ์  ์žฅ์น˜ ํ‰์ดํ•œ ํ‘œํ˜„์œผ๋กœ ๊ต์ฒด ๊ธˆ์ง€
93
+
94
+ # ํ—ˆ์šฉ๋˜๋Š” ๊ต์ • (์˜ค์ง ์ด๊ฒƒ๋งŒ)
95
+
96
+ ๋‹ค์Œ 5๊ฐ€์ง€ *๋ช…๋ฐฑํ•œ* ์˜ค๋ฅ˜๋งŒ ์ˆ˜์ • ๋Œ€์ƒ์ด๋‹ค:
97
+
98
+ 1. **๋ช…๋ฐฑํ•œ ์˜คํƒˆ์ž**: `์•ˆ๋…•ํ•˜์„ธ์œ ` โ†’ `์•ˆ๋…•ํ•˜์„ธ์š”`, `์ง›` โ†’ `์งš`
99
+ 2. **๋ช…๋ฐฑํ•œ ๋งž์ถค๋ฒ• ์˜ค๋ฅ˜**: `~๋กœ์„œ/~๋กœ์จ` ํ˜ผ๋™, `์•ˆ/์•Š` ํ˜ผ๋™, ๋ฐ›์นจ ์˜ค๋ฅ˜
100
+ 3. **๋„์–ด์“ฐ๊ธฐ**: ํ‘œ์ค€ ๋„์–ด์“ฐ๊ธฐ ์œ„๋ฐ˜
101
+ - ๋‹จ, ์˜๋„๋œ ์••์ถ•ํ˜• (`้ซ˜์ˆ˜์ต`ยท`K๋ฐฉ์‚ฐ`ยท`'ํ•œ๊ตญํŒ ๋ง˜๋‹ค๋‹ˆ'`) ์€ ๋ณด์กด
102
+ 4. **์กฐ์‚ฌ ์˜ค๋ฅ˜**: `์ด/๊ฐ€`, `์„/๋ฅผ`, `์€/๋Š”` ๋ช…๋ฐฑํ•œ ์˜ค๋ฅ˜
103
+ - ๋‹จ, ๋‘˜ ์ค‘ ์–ด๋А ๊ฒŒ ๋งž๋Š”์ง€ *๋ชจํ˜ธํ•˜๋ฉด ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค*
104
+ 5. **์™ธ๋ž˜์–ด ํ‘œ๊ธฐ๋ฒ• ์œ„๋ฐ˜** (ํ‘œ์ค€ ํ‘œ๊ธฐ๋ฒ• ๊ธฐ์ค€)
105
+ - ๋‹จ, ์˜๋„๋œ ์‹ ์กฐ์–ดยท๋ณ„๋ช… (`'๊ฐœ๋ฅด์‹ '`ยท`'์žฅ๋Œ€ํ•œ ๋ถ„๋…ธ'`) ์€ ๋ณด์กด
106
+
107
+ # ์ ˆ๋Œ€ ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ (Out of scope)
108
+
109
+ | ๊ธˆ์ง€ | ์ด์œ  |
110
+ |---|---|
111
+ | ์ œ๋ชฉ ๊ธธ์ด ์กฐ์ • (์ค„์ด๊ธฐยท๋Š˜๋ฆฌ๊ธฐ) | ๊ต์—ด๊ธฐ ์—ญํ•  ์•„๋‹˜ |
112
+ | ๋ฌธ์žฅ ๊ตฌ์กฐ ์žฌ๋ฐฐ์—ดยท์–ด์ˆœ ๋ณ€๊ฒฝ | ์˜๋ฏธ ๋ณ€ํ˜• ์œ„ํ—˜ |
113
+ | ๋™์˜์–ด ๊ต์ฒด (`์ง„์ž…` โ†’ `์‹œ์ž‘`) | ์ •๋ณด ๊ฐ•๋„ ์•ฝํ™” |
114
+ | ์ถ”์ƒํ™”ยท์ผ๋ฐ˜ํ™” (`30%` โ†’ `๋งŽ์ด`) | ์ •๋ณด ์†์‹ค |
115
+ | ์˜๋ฏธ ๋ฐ”๊พธ๋Š” ์กฐ์‚ฌ ๋ณ€๊ฒฝ | ์ค‘๋Œ€ํ•œ ์˜๋ฏธ ๋ณ€ํ˜• |
116
+ | ๊ธฐ์ž ๋…ผํ‰์„ฑ ์ฒจ์‚ญ | ๊ฐ๊ด€์„ฑ ํ›ผ์† |
117
+ | ๋”ฐ์˜ดํ‘œ ์ข…๋ฅ˜ ๋ณ€ํ™˜ (ํฐ โ†” ์ž‘์€) | ์˜๋„๋œ ์‹ ํ˜ธ ํŒŒ๊ดด |
118
+ | ํ•œ์ž ์•ฝ์–ด ํ’€์–ด์“ฐ๊ธฐ (`้ซ˜์ˆ˜์ต` โ†’ `๊ณ ์ˆ˜์ต`) | ์˜๋„๋œ ์••์ถ• ํ‘œํ˜„ |
119
+
120
+ # ์ถœ๋ ฅ ํ˜•์‹ (MANDATORY โ€” ์œ„๋ฐ˜ ์‹œ ํ‰๊ฐ€ ์‹คํŒจ)
121
+
122
+ ๋‹น์‹ ์˜ ์‘๋‹ต์€ **์ •ํ™•ํžˆ ํ•œ ์ค„์˜ ํ…์ŠคํŠธ** ์—ฌ์•ผ ํ•œ๋‹ค. ๊ทธ ์™ธ ๋ชจ๋“  ๊ฒƒ ์ ˆ๋Œ€ ๊ธˆ์ง€.
123
+
124
+ ## ์‘๋‹ต์— ํฌํ•จํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ (ํ•œ ๊ฐ€์ง€๋งŒ)
125
+
126
+ - (์ˆ˜์ •์ด ์žˆ์„ ๊ฒฝ์šฐ) ๊ต์ •๋œ ์ œ๋ชฉ ํ•œ ์ค„
127
+ - (์ˆ˜์ •์ด ์—†์„ ๊ฒฝ์šฐ) ์›๋ฌธ ํ•œ ์ค„
128
+
129
+ ## ์‘๋‹ต์— ์ ˆ๋Œ€ ํฌํ•จํ•˜๋ฉด ์•ˆ ๋˜๋Š” ๊ฒƒ (NEVER)
130
+
131
+ - "๊ฒฐ๊ณผ:" / "์ถœ๋ ฅ:" / "๊ต์ • ๊ฒฐ๊ณผ:" / "์ตœ์ข… ์ถœ๋ ฅ:" ๊ฐ™์€ ๋ผ๋ฒจ
132
+ - ํ•ด์„คยท์ด์œ ยท๋ถ„์„ ํ…์ŠคํŠธ (`# ํ•ด์„ค`, `**~ ๋ˆ„๋ฝ**`, `1. ...` ๋“ฑ)
133
+ - ์ถœ๋ ฅ ํ›„ ์ถ”๊ฐ€ ์„ค๋ช… (`(์›๋ฌธ ๊ทธ๋Œ€๋กœ)`, `(์ˆ˜์ • ์—†์Œ)`, `(ํ•ด์„ค์€ ์ถœ๋ ฅ๋˜์ง€ ์•Š์Œ)` ๋“ฑ)
134
+ - ์ค„๋ฐ”๊ฟˆ (`\n`) โ€” ์ถœ๋ ฅ์€ ์ •ํ™•ํžˆ ํ•œ ์ค„, ์ค„๋ฐ”๊ฟˆ์€ ๋‹จ ํ•˜๋‚˜๋„ ์—†์–ด์•ผ ํ•จ
135
+ - ๋งˆํฌ๋‹ค์šด (`**`, `#`, `-`, ` ``` ` ๋“ฑ)
136
+ - ์ฝ”๋“œ ๋ธ”๋ก
137
+ - ์ž…๋ ฅ ์นดํ…Œ๊ณ ๋ฆฌยท๋ฉ”ํƒ€๋ฐ์ดํ„ฐ echo
138
+ - ์ž๊ธฐ ๊ฒ€์ˆ˜ ์ฝ”๋ฉ˜ํŠธ
139
+
140
+ ## Few-shot ์˜ˆ์‹œ
141
+
142
+ ### ์˜ˆ์‹œ 1 โ€” ์ˆ˜์ • ์—†์Œ (์ •๋‹ต ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅ)
143
+
144
+ ์ž…๋ ฅ:
145
+ ```
146
+ ์นดํ…Œ๊ณ ๋ฆฌ: ์นผ๋Ÿผ
147
+ <์ œ๋ชฉ>
148
+ ์ฝ”์Šคํ”ผ 5000'์˜ ์„ฑ์ทจ์™€ '์„ฑ์žฅ๋ฅ  -0.3%'์˜ ํ˜„์‹ค
149
+ </์ œ๋ชฉ>
150
+ ```
151
+
152
+ ์˜ฌ๋ฐ”๋ฅธ ์‘๋‹ต (์ด๊ฒŒ ์ „๋ถ€):
153
+ ```
154
+ ์ฝ”์Šคํ”ผ 5000'์˜ ์„ฑ์ทจ์™€ '์„ฑ์žฅ๋ฅ  -0.3%'์˜ ํ˜„์‹ค
155
+ ```
156
+
157
+ ์ž˜๋ชป๋œ ์‘๋‹ต (์ ˆ๋Œ€ ์ด๋ ‡๊ฒŒ ์‘๋‹ตํ•˜์ง€ ๋ง ๊ฒƒ):
158
+ ```
159
+ ์ฝ”์Šคํ”ผ 5000'์˜ ์„ฑ์ทจ์™€ '์„ฑ์žฅ๋ฅ  -0.3%'์˜ ํ˜„์‹ค
160
+
161
+ # ํ•ด์„ค (์ถœ๋ ฅ๋˜์ง€ ์•Š์Œ)
162
+ 1. ํฐ๋”ฐ์˜ดํ‘œ ๋ˆ„๋ฝ: ์›๋ฌธ์—์„œ...
163
+ ```
164
+
165
+ ### ์˜ˆ์‹œ 2 โ€” ๋ช…๋ฐฑํ•œ ์˜คํƒˆ์ž ์ˆ˜์ •
166
+
167
+ ์ž…๋ ฅ:
168
+ ```
169
+ ์นดํ…Œ๊ณ ๋ฆฌ: ์ผ๋ฐ˜๊ธฐ์‚ฌ
170
+ <์ œ๋ชฉ>
171
+ ๊ฐ•๋‚จ 3๊ตฌ, ๋งค๋ฌผ 30% ๋Š˜์—ˆ์ง€๋งŒ ๊ฑฐ๋ž˜๋Ÿ‰ 15% ์ค„์–ด์œ 
172
+ </์ œ๋ชฉ>
173
+ ```
174
+
175
+ ์˜ฌ๋ฐ”๋ฅธ ์‘๋‹ต:
176
+ ```
177
+ ๊ฐ•๋‚จ 3๊ตฌ, ๋งค๋ฌผ 30% ๋Š˜์—ˆ์ง€๋งŒ ๊ฑฐ๋ž˜๋Ÿ‰ 15% ์ค„์–ด
178
+ ```
179
+
180
+ ### ์˜ˆ์‹œ 3 โ€” ๋„์–ด์“ฐ๊ธฐ ์ˆ˜์ •
181
+
182
+ ์ž…๋ ฅ:
183
+ ```
184
+ ์นดํ…Œ๊ณ ๋ฆฌ: ์ผ๋ฐ˜๊ธฐ์‚ฌ
185
+ <์ œ๋ชฉ>
186
+ ์‹ ์šฉ๋ถˆ๋Ÿ‰์ž์ ˆ๋ฐ˜์ด 4050 ๊ฐ€์žฅโ€ฆ ๊ฒฝ์ œ ๋– ๋ฐ›์น  'ํ—ˆ๋ฆฌ'๊ฐ€ ๋ฌด๋„ˆ์ง„๋‹ค
187
+ </์ œ๋ชฉ>
188
+ ```
189
+
190
+ ์˜ฌ๋ฐ”๋ฅธ ์‘๋‹ต:
191
+ ```
192
+ ์‹ ์šฉ๋ถˆ๋Ÿ‰์ž ์ ˆ๋ฐ˜์ด 4050 ๊ฐ€์žฅโ€ฆ ๊ฒฝ์ œ ๋– ๋ฐ›์น  'ํ—ˆ๋ฆฌ'๊ฐ€ ๋ฌด๋„ˆ์ง„๋‹ค
193
+ ```
194
+
195
+ ==================================================
196
+ === โš ๏ธ FINAL REMINDER โš ๏ธ ===
197
+ - ์˜์‹ฌ๋˜๋ฉด ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค (do no harm > catch all)
198
+ - ์‘๋‹ต์€ **์ •ํ™•ํžˆ ํ•œ ์ค„**. ์ค„๋ฐ”๊ฟˆยทํ•ด์„คยท๋ผ๋ฒจยท๋งˆํฌ๋‹ค์šด ๋ชจ๋‘ ๊ธˆ์ง€
199
+ - ์‘๋‹ต = ์ž…๋ ฅ์˜ ์ œ๋ชฉ๊ณผ ๋™์ผํ•œ ํ˜•์‹ (ํ•œ ์ค„์งœ๋ฆฌ plain text)
200
+ - ์œ„ ํ˜•์‹์„ ์œ„๋ฐ˜ํ•˜๋ฉด ํ‰๊ฐ€๋Š” ์‹คํŒจ ์ฒ˜๋ฆฌ๋œ๋‹ค
201
+ ==================================================
title_proofread/prompts/prompt_dev_v1/user.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ ์นดํ…Œ๊ณ ๋ฆฌ: {{category}}
2
+
3
+ <์ œ๋ชฉ>
4
+ {{original}}
5
+ </์ œ๋ชฉ>
title_proofread/runner.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """์ œ๋ชฉ ๊ต์—ด ๋‹จ์ผ ํ˜ธ์ถœ ๋Ÿฌ๋„ˆ โ€” solar-pro2 / solar-pro3 ๋น„๊ต์šฉ.
2
+
3
+ UI ๊ฐ€ ์‹œ์Šคํ…œยท์œ ์ € ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ง์ ‘ ํŽธ์ง‘ํ•  ์ˆ˜ ์žˆ๋„๋ก prompt ์ธ์ž๋ฅผ ์ „๋ถ€ ์™ธ๋ถ€์—์„œ ๋ฐ›์Œ.
4
+ ๋ชจ๋ธ์€ ํ˜ธ์ถœ ์‹œ ์ธ์ž๋กœ ์ง€์ • (UI ์—์„œ ๋‘ ๋ชจ๋ธ์„ ๋ณ‘๋ ฌ๋กœ ํ˜ธ์ถœ).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import time
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ MODELS = ["solar-pro2", "solar-pro3"]
14
+ DEFAULT_PROMPT_DIR = Path(__file__).resolve().parent / "prompts" / "prompt_dev_v1"
15
+
16
+
17
+ def load_default_prompts() -> tuple[str, str]:
18
+ """`prompt_dev_v1` ์˜ system.txt + user.txt ๋ฅผ ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜."""
19
+ system = (DEFAULT_PROMPT_DIR / "system.txt").read_text(encoding="utf-8")
20
+ user = (DEFAULT_PROMPT_DIR / "user.txt").read_text(encoding="utf-8")
21
+ return system, user
22
+
23
+
24
+ def render_user_message(user_template: str, original: str, category: str) -> str:
25
+ """`{{original}}`, `{{category}}` placeholder ์น˜ํ™˜."""
26
+ return user_template.replace("{{original}}", original).replace("{{category}}", category)
27
+
28
+
29
+ def run_title_proofread(
30
+ *,
31
+ client: Any,
32
+ original: str,
33
+ category: str,
34
+ system_prompt: str,
35
+ user_template: str,
36
+ model: str,
37
+ temperature: float = 0.0,
38
+ reasoning_effort: str = "low",
39
+ max_tokens: int = 2000,
40
+ ) -> dict[str, Any]:
41
+ """๋‹จ์ผ LLM ํ˜ธ์ถœ. UI ์—์„œ ๋ชจ๋ธ๋‹น ํ•œ ๋ฒˆ์”ฉ (๋ณ‘๋ ฌ) ํ˜ธ์ถœ.
42
+
43
+ Returns:
44
+ {
45
+ "output": str, # ๋ชจ๋ธ ์‘๋‹ต (strip ์ฒ˜๋ฆฌ)
46
+ "user_message": str, # placeholder ์น˜ํ™˜๋œ ์‹ค user content (๋””๋ฒ„๊น…์šฉ)
47
+ "model": str,
48
+ "latency_ms": int,
49
+ "usage": dict, # {prompt_tokens, completion_tokens, total_tokens}
50
+ "error": str | None, # ์—๋Ÿฌ ์‹œ ๋ฉ”์‹œ์ง€
51
+ }
52
+ """
53
+ user_msg = render_user_message(user_template, original, category)
54
+ start = time.time()
55
+ try:
56
+ kwargs: dict[str, Any] = {
57
+ "model": model,
58
+ "messages": [
59
+ {"role": "system", "content": system_prompt},
60
+ {"role": "user", "content": user_msg},
61
+ ],
62
+ "temperature": float(temperature),
63
+ "max_tokens": int(max_tokens),
64
+ }
65
+ if reasoning_effort:
66
+ kwargs["reasoning_effort"] = reasoning_effort
67
+ resp = client.chat.completions.create(**kwargs)
68
+ except Exception as exc: # noqa: BLE001
69
+ return {
70
+ "output": "",
71
+ "user_message": user_msg,
72
+ "model": model,
73
+ "latency_ms": int((time.time() - start) * 1000),
74
+ "usage": {},
75
+ "error": f"{type(exc).__name__}: {exc}",
76
+ }
77
+
78
+ elapsed_ms = int((time.time() - start) * 1000)
79
+ raw = (resp.choices[0].message.content or "").strip()
80
+ usage = getattr(resp, "usage", None)
81
+ usage_dict: dict[str, int] = {}
82
+ if usage:
83
+ for k in ("prompt_tokens", "completion_tokens", "total_tokens"):
84
+ v = getattr(usage, k, None)
85
+ if v is not None:
86
+ usage_dict[k] = v
87
+
88
+ return {
89
+ "output": raw,
90
+ "user_message": user_msg,
91
+ "model": model,
92
+ "latency_ms": elapsed_ms,
93
+ "usage": usage_dict,
94
+ "error": None,
95
+ }
title_proofread/ui.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Gradio UI โ€” ์ œ๋ชฉ ๊ต์—ด sandbox ํƒญ.
2
+
3
+ ์‚ฌ์šฉ์ž์—๊ฒŒ system/user ํ”„๋กฌํ”„ํŠธ์™€ ํ˜ธ์ถœ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ๋ฅผ ๋…ธ์ถœํ•˜์ง€ ์•Š๊ณ ,
4
+ ์ž…๋ ฅ ์ œ๋ชฉยท์นดํ…Œ๊ณ ๋ฆฌยท์ถ”๋ก  ์˜ต์…˜๋งŒ ๋ฐ›์•„ solar-pro2 / solar-pro3 ๊ฒฐ๊ณผ๋ฅผ
5
+ ์ขŒ์šฐ ์ปฌ๋Ÿผ์—์„œ ๋™์‹œ์— ๋น„๊ตํ•œ๋‹ค.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from concurrent.futures import ThreadPoolExecutor
11
+ from typing import Any
12
+
13
+ import gradio as gr
14
+ from diff_utils import highlight_diff
15
+
16
+ from .runner import MODELS, load_default_prompts, run_title_proofread
17
+
18
+ CATEGORY_CHOICES = ["์ผ๋ฐ˜๊ธฐ์‚ฌ", "์นผ๋Ÿผ"]
19
+
20
+
21
+ def build_title_proofread_tab(client: Any) -> None:
22
+ """์ œ๋ชฉ ๊ต์—ด ํƒญ ๋นŒ๋”. `with gr.Tab(...)` ์•ˆ์—์„œ ํ˜ธ์ถœ.
23
+
24
+ Args:
25
+ client: openai.OpenAI ํ˜ธํ™˜ ํด๋ผ์ด์–ธํŠธ (Upstage base_url ์„ค์ •).
26
+ """
27
+ # Default prompts loaded once at module init โ€” never exposed to users.
28
+ default_system, default_user = load_default_prompts()
29
+
30
+ gr.Markdown(
31
+ "## ์ œ๋ชฉ ๊ต์—ด\n"
32
+ f"ํ•œ๊ตญ ์‹ ๋ฌธ ์ œ๋ชฉ ๊ต์—ด ๊ฒฐ๊ณผ๋ฅผ `{MODELS[0]}` ์™€ `{MODELS[1]}` ๋‘ ๋ชจ๋ธ๋กœ ๋น„๊ต."
33
+ )
34
+
35
+ with gr.Row():
36
+ with gr.Column(scale=1):
37
+ category = gr.Dropdown(
38
+ label="์นดํ…Œ๊ณ ๋ฆฌ",
39
+ choices=CATEGORY_CHOICES,
40
+ value="์ผ๋ฐ˜๊ธฐ์‚ฌ",
41
+ )
42
+ with gr.Column(scale=4):
43
+ original = gr.Textbox(
44
+ label="์ œ๋ชฉ ์ž…๋ ฅ",
45
+ placeholder="์˜ˆ: ๊ฐ•๋‚จ 3๊ตฌ, ๋งค๋ฌผ 30% ๋Š˜์—ˆ์ง€๋งŒ ๊ฑฐ๋ž˜๋Ÿ‰ 15% ์ค„์–ด์œ ",
46
+ lines=1,
47
+ )
48
+
49
+ with gr.Accordion("์ถ”๋ก  ์˜ต์…˜ (์–‘์ชฝ ๋ชจ๋ธ ๊ณตํ†ต ์ ์šฉ)", open=False):
50
+ with gr.Row():
51
+ temperature = gr.Slider(
52
+ minimum=0.0,
53
+ maximum=1.0,
54
+ step=0.1,
55
+ value=0.0,
56
+ label="temperature",
57
+ )
58
+ reasoning_effort = gr.Radio(
59
+ choices=["low", "medium", "high"],
60
+ value="low",
61
+ label="reasoning_effort",
62
+ )
63
+
64
+ run_btn = gr.Button(
65
+ "โ–ถ ๊ต์—ด ์‹คํ–‰ (โŒ˜+Enter / Ctrl+Enter)",
66
+ variant="primary",
67
+ elem_id="title-proofread-run-btn",
68
+ )
69
+
70
+ # โ”€โ”€โ”€ ๊ฒฐ๊ณผ โ€” ๋‘ ๋ชจ๋ธ์„ ์ขŒ์šฐ ์ปฌ๋Ÿผ์œผ๋กœ ๋น„๊ต โ”€โ”€โ”€
71
+ with gr.Row(equal_height=False):
72
+ with gr.Column():
73
+ gr.Markdown(f"### {MODELS[0]}")
74
+ output_pro2 = gr.Textbox(label="๊ต์ • ๊ฒฐ๊ณผ", lines=2, interactive=False)
75
+ diff_pro2 = gr.HTML(label="์›๋ณธ ๋Œ€๋น„ diff")
76
+ with gr.Column():
77
+ gr.Markdown(f"### {MODELS[1]}")
78
+ output_pro3 = gr.Textbox(label="๊ต์ • ๊ฒฐ๊ณผ", lines=2, interactive=False)
79
+ diff_pro3 = gr.HTML(label="์›๋ณธ ๋Œ€๋น„ diff")
80
+
81
+ def _empty():
82
+ return (
83
+ gr.update(value=""),
84
+ gr.update(value=""),
85
+ gr.update(value=""),
86
+ gr.update(value=""),
87
+ )
88
+
89
+ def _on_run(
90
+ original_text: str,
91
+ category_value: str,
92
+ temperature_val: float,
93
+ reasoning_effort_val: str,
94
+ ):
95
+ if not original_text or not original_text.strip():
96
+ gr.Warning("์ œ๋ชฉ์ด ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค.")
97
+ return _empty()
98
+ if client is None:
99
+ gr.Warning("UPSTAGE_API_KEY ๋ฏธ์„ค์ •.")
100
+ return _empty()
101
+
102
+ orig_clean = original_text.strip()
103
+ category_clean = (category_value or "์ผ๋ฐ˜๊ธฐ์‚ฌ").strip()
104
+
105
+ # ๋‘ ๋ชจ๋ธ ๋ณ‘๋ ฌ ํ˜ธ์ถœ (์ด latency = max(pro2, pro3)).
106
+ # ์‹œ์Šคํ…œยท์œ ์ € ํ”„๋กฌํ”„ํŠธ๋Š” ๋‚ด๋ถ€ default ๊ณ ์ • โ€” UI ์— ๋…ธ์ถœํ•˜์ง€ ์•Š์Œ.
107
+ with ThreadPoolExecutor(max_workers=2) as ex:
108
+ futures = {
109
+ m: ex.submit(
110
+ run_title_proofread,
111
+ client=client,
112
+ original=orig_clean,
113
+ category=category_clean,
114
+ system_prompt=default_system,
115
+ user_template=default_user,
116
+ model=m,
117
+ temperature=temperature_val,
118
+ reasoning_effort=reasoning_effort_val,
119
+ )
120
+ for m in MODELS
121
+ }
122
+ results = {m: f.result() for m, f in futures.items()}
123
+
124
+ r2 = results[MODELS[0]]
125
+ r3 = results[MODELS[1]]
126
+
127
+ # ๋ชจ๋ธ ํ˜ธ์ถœ ์ž์ฒด๊ฐ€ ์‹คํŒจํ•˜๋ฉด toast ๋กœ ์•Œ๋ฆฌ๊ณ  ๊ฒฐ๊ณผ ๋น„์›€.
128
+ for m, r in ((MODELS[0], r2), (MODELS[1], r3)):
129
+ if r.get("error"):
130
+ gr.Warning(f"{m} ํ˜ธ์ถœ ์‹คํŒจ: {r['error']}")
131
+
132
+ def _diff(out: str) -> str:
133
+ return highlight_diff(orig_clean, out) if out else ""
134
+
135
+ return (
136
+ gr.update(value=r2["output"]),
137
+ gr.update(value=_diff(r2["output"])),
138
+ gr.update(value=r3["output"]),
139
+ gr.update(value=_diff(r3["output"])),
140
+ )
141
+
142
+ run_btn.click(
143
+ _on_run,
144
+ inputs=[
145
+ original,
146
+ category,
147
+ temperature,
148
+ reasoning_effort,
149
+ ],
150
+ outputs=[
151
+ output_pro2,
152
+ diff_pro2,
153
+ output_pro3,
154
+ diff_pro3,
155
+ ],
156
+ )