Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Upload folder using huggingface_hub
Browse files- app/feedback.py +7 -2
app/feedback.py
CHANGED
|
@@ -35,6 +35,7 @@ ADMIN_TOKEN = os.environ.get("OXT_ADMIN_TOKEN", "")
|
|
| 35 |
_FILE = FB_DIR / f"fb-{time.strftime('%Y%m%d')}-{uuid.uuid4().hex[:6]}.jsonl"
|
| 36 |
_lock = threading.Lock()
|
| 37 |
_scheduler = None
|
|
|
|
| 38 |
|
| 39 |
# (src, tgt, normalized original) -> {correction text -> set(voters)} ; trusted fixes win outright
|
| 40 |
_votes: dict[tuple, dict[str, set]] = defaultdict(lambda: defaultdict(set))
|
|
@@ -81,8 +82,10 @@ def _restore() -> None:
|
|
| 81 |
|
| 82 |
def start() -> None:
|
| 83 |
"""Call once at server start."""
|
| 84 |
-
global _scheduler
|
| 85 |
_restore()
|
|
|
|
|
|
|
| 86 |
if REPO and os.environ.get("HF_TOKEN"):
|
| 87 |
try:
|
| 88 |
from huggingface_hub import CommitScheduler
|
|
@@ -90,6 +93,7 @@ def start() -> None:
|
|
| 90 |
path_in_repo=".", every=5, private=True,
|
| 91 |
allow_patterns=["*.jsonl"])
|
| 92 |
except Exception as e: # noqa: BLE001
|
|
|
|
| 93 |
print("feedback sync disabled:", e)
|
| 94 |
|
| 95 |
|
|
@@ -136,7 +140,8 @@ def stats() -> dict:
|
|
| 136 |
fixes += bool(r.get("correction"))
|
| 137 |
return {"ratings": n, "thumbs_up": good, "thumbs_down": bad, "corrections": fixes,
|
| 138 |
"approved_fixes": len(_trusted) + sum(1 for k in _votes if lookup(*k)),
|
| 139 |
-
"synced_to": REPO or None
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def export_lines():
|
|
|
|
| 35 |
_FILE = FB_DIR / f"fb-{time.strftime('%Y%m%d')}-{uuid.uuid4().hex[:6]}.jsonl"
|
| 36 |
_lock = threading.Lock()
|
| 37 |
_scheduler = None
|
| 38 |
+
_sync_error = ""
|
| 39 |
|
| 40 |
# (src, tgt, normalized original) -> {correction text -> set(voters)} ; trusted fixes win outright
|
| 41 |
_votes: dict[tuple, dict[str, set]] = defaultdict(lambda: defaultdict(set))
|
|
|
|
| 82 |
|
| 83 |
def start() -> None:
|
| 84 |
"""Call once at server start."""
|
| 85 |
+
global _scheduler, _sync_error
|
| 86 |
_restore()
|
| 87 |
+
if REPO and not os.environ.get("HF_TOKEN"):
|
| 88 |
+
_sync_error = "HF_TOKEN secret is missing in the Space"
|
| 89 |
if REPO and os.environ.get("HF_TOKEN"):
|
| 90 |
try:
|
| 91 |
from huggingface_hub import CommitScheduler
|
|
|
|
| 93 |
path_in_repo=".", every=5, private=True,
|
| 94 |
allow_patterns=["*.jsonl"])
|
| 95 |
except Exception as e: # noqa: BLE001
|
| 96 |
+
_sync_error = f"{type(e).__name__}: {str(e)[:200]}"
|
| 97 |
print("feedback sync disabled:", e)
|
| 98 |
|
| 99 |
|
|
|
|
| 140 |
fixes += bool(r.get("correction"))
|
| 141 |
return {"ratings": n, "thumbs_up": good, "thumbs_down": bad, "corrections": fixes,
|
| 142 |
"approved_fixes": len(_trusted) + sum(1 for k in _votes if lookup(*k)),
|
| 143 |
+
"synced_to": REPO or None, "sync_active": _scheduler is not None,
|
| 144 |
+
"sync_error": _sync_error or None}
|
| 145 |
|
| 146 |
|
| 147 |
def export_lines():
|