Spaces:
Running
Running
Commit ·
e92517a
1
Parent(s): 61d7017
Move blindtest tab first; add RLS policies and error surfacing
Browse files- app.py +8 -8
- blindtest/db.py +46 -17
- blindtest/schema.sql +16 -0
- blindtest/ui.py +5 -1
app.py
CHANGED
|
@@ -124,6 +124,14 @@ with gr.Blocks(title="Chosun 교정교열 데모") as demo:
|
|
| 124 |
gr.Markdown("# Chosun 교정교열 데모")
|
| 125 |
|
| 126 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
with gr.Tab("파이프라인 비교"):
|
| 128 |
gr.Markdown("Baseline(251231 Pro2×3)과 신규 v16(Pro3×1)을 나란히 비교합니다.")
|
| 129 |
|
|
@@ -177,14 +185,6 @@ with gr.Blocks(title="Chosun 교정교열 데모") as demo:
|
|
| 177 |
],
|
| 178 |
)
|
| 179 |
|
| 180 |
-
with gr.Tab("블라인드 테스트"):
|
| 181 |
-
build_blindtest_tab(
|
| 182 |
-
client=client,
|
| 183 |
-
vocabulary=vocabulary,
|
| 184 |
-
baseline_config=("251231_default", "solar-pro2", _default_prompt_a),
|
| 185 |
-
candidate_config=("260408_v16", "solar-pro3", _default_prompt_b),
|
| 186 |
-
)
|
| 187 |
-
|
| 188 |
_SHORTCUT_JS = """
|
| 189 |
() => {
|
| 190 |
if (window.__chosunShortcutBound) return;
|
|
|
|
| 124 |
gr.Markdown("# Chosun 교정교열 데모")
|
| 125 |
|
| 126 |
with gr.Tabs():
|
| 127 |
+
with gr.Tab("블라인드 테스트"):
|
| 128 |
+
build_blindtest_tab(
|
| 129 |
+
client=client,
|
| 130 |
+
vocabulary=vocabulary,
|
| 131 |
+
baseline_config=("251231_default", "solar-pro2", _default_prompt_a),
|
| 132 |
+
candidate_config=("260408_v16", "solar-pro3", _default_prompt_b),
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
with gr.Tab("파이프라인 비교"):
|
| 136 |
gr.Markdown("Baseline(251231 Pro2×3)과 신규 v16(Pro3×1)을 나란히 비교합니다.")
|
| 137 |
|
|
|
|
| 185 |
],
|
| 186 |
)
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
_SHORTCUT_JS = """
|
| 189 |
() => {
|
| 190 |
if (window.__chosunShortcutBound) return;
|
blindtest/db.py
CHANGED
|
@@ -72,9 +72,13 @@ def save_article(source_text: str) -> int | None:
|
|
| 72 |
c = get_client()
|
| 73 |
if c is None:
|
| 74 |
return None
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
def save_pipeline_run(
|
|
@@ -96,9 +100,13 @@ def save_pipeline_run(
|
|
| 96 |
"output": output,
|
| 97 |
"processing_time_s": processing_time_s,
|
| 98 |
}
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
def save_task(
|
|
@@ -109,23 +117,44 @@ def save_task(
|
|
| 109 |
c = get_client()
|
| 110 |
if c is None or article_id is None:
|
| 111 |
return None
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
def save_vote(task_id: int | None, choice: str, comment: str) -> bool:
|
| 122 |
c = get_client()
|
| 123 |
if c is None or task_id is None:
|
| 124 |
return False
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
def fetch_summary() -> list[dict]:
|
|
|
|
| 72 |
c = get_client()
|
| 73 |
if c is None:
|
| 74 |
return None
|
| 75 |
+
try:
|
| 76 |
+
resp = c.table("articles").insert({"source_text": source_text}).execute()
|
| 77 |
+
data = resp.data or []
|
| 78 |
+
return data[0]["id"] if data else None
|
| 79 |
+
except Exception as exc:
|
| 80 |
+
_record_error("save_article", exc)
|
| 81 |
+
return None
|
| 82 |
|
| 83 |
|
| 84 |
def save_pipeline_run(
|
|
|
|
| 100 |
"output": output,
|
| 101 |
"processing_time_s": processing_time_s,
|
| 102 |
}
|
| 103 |
+
try:
|
| 104 |
+
resp = c.table("pipeline_runs").insert(row).execute()
|
| 105 |
+
data = resp.data or []
|
| 106 |
+
return data[0]["id"] if data else None
|
| 107 |
+
except Exception as exc:
|
| 108 |
+
_record_error("save_pipeline_run", exc)
|
| 109 |
+
return None
|
| 110 |
|
| 111 |
|
| 112 |
def save_task(
|
|
|
|
| 117 |
c = get_client()
|
| 118 |
if c is None or article_id is None:
|
| 119 |
return None
|
| 120 |
+
try:
|
| 121 |
+
resp = (
|
| 122 |
+
c.table("tasks")
|
| 123 |
+
.insert({"article_id": article_id, "run_a_id": run_a_id, "run_b_id": run_b_id})
|
| 124 |
+
.execute()
|
| 125 |
+
)
|
| 126 |
+
data = resp.data or []
|
| 127 |
+
return data[0]["id"] if data else None
|
| 128 |
+
except Exception as exc:
|
| 129 |
+
_record_error("save_task", exc)
|
| 130 |
+
return None
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
_last_error: str | None = None
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def last_error() -> str | None:
|
| 137 |
+
return _last_error
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
def _record_error(where: str, exc: Exception) -> None:
|
| 141 |
+
global _last_error
|
| 142 |
+
_last_error = f"{where}: {exc}"
|
| 143 |
+
print(f"[blindtest.db] {_last_error}")
|
| 144 |
|
| 145 |
|
| 146 |
def save_vote(task_id: int | None, choice: str, comment: str) -> bool:
|
| 147 |
c = get_client()
|
| 148 |
if c is None or task_id is None:
|
| 149 |
return False
|
| 150 |
+
try:
|
| 151 |
+
c.table("votes").insert(
|
| 152 |
+
{"task_id": task_id, "choice": choice, "comment": comment or None}
|
| 153 |
+
).execute()
|
| 154 |
+
return True
|
| 155 |
+
except Exception as exc:
|
| 156 |
+
_record_error("save_vote", exc)
|
| 157 |
+
return False
|
| 158 |
|
| 159 |
|
| 160 |
def fetch_summary() -> list[dict]:
|
blindtest/schema.sql
CHANGED
|
@@ -38,6 +38,22 @@ create table if not exists votes (
|
|
| 38 |
|
| 39 |
create index if not exists votes_task_idx on votes (task_id);
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
-- Aggregation view: winner is identified by pipeline_key (un-blinded).
|
| 42 |
create or replace view vote_summary as
|
| 43 |
select
|
|
|
|
| 38 |
|
| 39 |
create index if not exists votes_task_idx on votes (task_id);
|
| 40 |
|
| 41 |
+
-- Allow anon key (used by the Gradio app) to insert/select.
|
| 42 |
+
-- RLS is enabled by default on public tables; without policies, anon writes silently fail.
|
| 43 |
+
alter table articles enable row level security;
|
| 44 |
+
alter table pipeline_runs enable row level security;
|
| 45 |
+
alter table tasks enable row level security;
|
| 46 |
+
alter table votes enable row level security;
|
| 47 |
+
|
| 48 |
+
create policy "anon insert articles" on articles for insert to anon with check (true);
|
| 49 |
+
create policy "anon select articles" on articles for select to anon using (true);
|
| 50 |
+
create policy "anon insert pipeline_runs" on pipeline_runs for insert to anon with check (true);
|
| 51 |
+
create policy "anon select pipeline_runs" on pipeline_runs for select to anon using (true);
|
| 52 |
+
create policy "anon insert tasks" on tasks for insert to anon with check (true);
|
| 53 |
+
create policy "anon select tasks" on tasks for select to anon using (true);
|
| 54 |
+
create policy "anon insert votes" on votes for insert to anon with check (true);
|
| 55 |
+
create policy "anon select votes" on votes for select to anon using (true);
|
| 56 |
+
|
| 57 |
-- Aggregation view: winner is identified by pipeline_key (un-blinded).
|
| 58 |
create or replace view vote_summary as
|
| 59 |
select
|
blindtest/ui.py
CHANGED
|
@@ -198,9 +198,13 @@ def build_blindtest_tab(
|
|
| 198 |
else:
|
| 199 |
label_a = candidate_config[0]
|
| 200 |
label_b = baseline_config[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
reveal_md = (
|
| 202 |
f"**공개** — A: `{label_a}` · B: `{label_b}`\n\n"
|
| 203 |
-
f"선택: **{choice}**" +
|
| 204 |
)
|
| 205 |
summary = _format_summary(db.fetch_summary(), db.fetch_vote_counts())
|
| 206 |
return gr.update(value=reveal_md), gr.update(value=summary)
|
|
|
|
| 198 |
else:
|
| 199 |
label_a = candidate_config[0]
|
| 200 |
label_b = baseline_config[0]
|
| 201 |
+
err = db.last_error()
|
| 202 |
+
save_note = ""
|
| 203 |
+
if not saved:
|
| 204 |
+
save_note = f" _(저장 실패: {err})_" if err else " _(저장 안 됨 · Supabase 미설정)_"
|
| 205 |
reveal_md = (
|
| 206 |
f"**공개** — A: `{label_a}` · B: `{label_b}`\n\n"
|
| 207 |
+
f"선택: **{choice}**" + save_note
|
| 208 |
)
|
| 209 |
summary = _format_summary(db.fetch_summary(), db.fetch_vote_counts())
|
| 210 |
return gr.update(value=reveal_md), gr.update(value=summary)
|