ngocdang83 commited on
Commit
4c5cf39
·
verified ·
1 Parent(s): 7ab534e

fix(space): them feedback_log.py (app.py HEAD import) + rebuild zip — sua ModuleNotFoundError

Browse files
Files changed (2) hide show
  1. hachimimt-local.zip +2 -2
  2. src/feedback_log.py +55 -0
hachimimt-local.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2fb31da9a2130921ed4eb7efec7e1ef809b7b566415b0982b11db5150392c8ea
3
- size 125402
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3f4be3ca50d7be36e3053ddbb6086a1c6b7f6c9db6116f89bc609eca3cae4a5
3
+ size 126412
src/feedback_log.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Ghi feedback/sửa câu dịch ra JSONL local (dev-only). KHÔNG import gradio."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import threading
8
+ from dataclasses import asdict, dataclass
9
+ from pathlib import Path
10
+
11
+ SCHEMA_VERSION = 1
12
+
13
+ ROOT = Path(__file__).resolve().parent.parent
14
+
15
+
16
+ def _default_log_path() -> Path:
17
+ env = os.environ.get("HACHIMIMT_FEEDBACK_LOG_PATH", "").strip()
18
+ if env:
19
+ return Path(env)
20
+ return ROOT / "feedback" / "corrections.jsonl"
21
+
22
+
23
+ DEFAULT_LOG_PATH = _default_log_path()
24
+
25
+ _WRITE_LOCK = threading.Lock()
26
+
27
+
28
+ @dataclass
29
+ class FeedbackEntry:
30
+ schema_version: int
31
+ ts: str
32
+ run_id: str
33
+ source_kind: str # "text" | "file"
34
+ model: str
35
+ backend: str
36
+ chunk_mode: str
37
+ normalize_mode: str
38
+ honorific: str # none|kinship|pronoun|kinship+pronoun
39
+ pronoun_v9: bool
40
+ category: str | None
41
+ idx: int
42
+ source: str # nguồn SAU normalize
43
+ mt_final: str # bản dịch SAU hậu kỳ
44
+ corrected: str | None
45
+ rating: str | None # "good" | "bad" | None
46
+
47
+
48
+ def append_feedback(entry: FeedbackEntry, log_path: Path = DEFAULT_LOG_PATH) -> None:
49
+ """Append 1 dòng JSON UTF-8. Tạo thư mục nếu chưa có. Lock để click đồng thời
50
+ không xen dòng. ensure_ascii=False giữ chữ Trung/dấu Việt."""
51
+ line = json.dumps(asdict(entry), ensure_ascii=False)
52
+ with _WRITE_LOCK:
53
+ log_path.parent.mkdir(parents=True, exist_ok=True)
54
+ with open(log_path, "a", encoding="utf-8") as fh:
55
+ fh.write(line + "\n")