Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,4 +1,3 @@
# coding=utf-8
# Copyright 2025-present, the HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -16,12 +15,11 @@
import re
import time
from typing import Dict
RE_NUMBER_WITH_UNIT = re.compile(r"(\d+)([a-z]+)", re.IGNORECASE)
BYTE_UNITS: Dict[str, int] = {
BYTE_UNITS: dict[str, int] = {
"k": 1_000,
"m": 1_000_000,
"g": 1_000_000_000,
@ -29,7 +27,7 @@ BYTE_UNITS: Dict[str, int] = {
"p": 1_000_000_000_000_000,
}
TIME_UNITS: Dict[str, int] = {
TIME_UNITS: dict[str, int] = {
"s": 1,
"m": 60,
"h": 60 * 60,
@ -50,7 +48,7 @@ def parse_duration(value: str) -> int:
return _parse_with_unit(value, TIME_UNITS)
def _parse_with_unit(value: str, units: Dict[str, int]) -> int:
def _parse_with_unit(value: str, units: dict[str, int]) -> int:
"""Parse a numeric value with optional unit."""
stripped = value.strip()
if not stripped:
@ -73,6 +71,21 @@ def _parse_with_unit(value: str, units: Dict[str, int]) -> int:
return number * units[unit]
def format_duration(secs: int | None) -> str:
"""Format a duration in seconds as a short human-readable string (e.g. `"1m 32s"`, `"2h 15m"`, `"45s"`).
Returns `"--"` when `secs` is `None` so it can be used directly as a CLI table cell.
"""
if secs is None:
return "--"
secs = int(secs)
if secs < 60:
return f"{secs}s"
if secs < 3600:
return f"{secs // 60}m {secs % 60}s"
return f"{secs // 3600}h {(secs % 3600) // 60}m"
def format_timesince(ts: float) -> str:
"""Format timestamp in seconds into a human-readable string, relative to now.