Spaces:
Running
Running
File size: 1,054 Bytes
e9015b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """Shared progress state — polled by UI timer during long translation."""
from __future__ import annotations
import threading
from dataclasses import dataclass
@dataclass
class ProgressState:
pct: float = 0.0
message: str = "Sẵn sàng."
running: bool = False
_lock = threading.Lock()
_state = ProgressState()
def set_progress(pct: float, message: str, *, running: bool = True) -> None:
with _lock:
_state.pct = max(0.0, min(100.0, float(pct)))
_state.message = message
_state.running = running
def finish_progress(message: str) -> None:
with _lock:
_state.pct = 100.0
_state.message = message
_state.running = False
def reset_progress(message: str = "Sẵn sàng.") -> None:
with _lock:
_state.pct = 0.0
_state.message = message
_state.running = False
def snapshot() -> ProgressState:
with _lock:
return ProgressState(
pct=_state.pct,
message=_state.message,
running=_state.running,
) |