Spaces:
Running
Running
Download src/progress_tracker.py from ngocdang83/HachimiMT-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/ngocdang83/HachimiMT-demo/resolve/a9e1fba3326dfe8e57aaf9f9a8d2ef4df697cc06/src/progress_tracker.py
- Command line
-
hf download hf://spaces/ngocdang83/HachimiMT-demo@a9e1fba3326dfe8e57aaf9f9a8d2ef4df697cc06/src/progress_tracker.py
-
curl -L -o progress_tracker.py https://huggingface.co/spaces/ngocdang83/HachimiMT-demo/resolve/a9e1fba3326dfe8e57aaf9f9a8d2ef4df697cc06/src/progress_tracker.py
1.05 kB
| """Shared progress state — polled by UI timer during long translation.""" | |
| from __future__ import annotations | |
| import threading | |
| from dataclasses import 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, | |
| ) |