Spaces:
Running
Running
Download space/src/display/formatting.py from ThinkcatLab/LiveHouse-TS: direct link, hf CLI and curl.
- Browser
- Download file 780 Bytes
-
https://huggingface.co/spaces/ThinkcatLab/LiveHouse-TS/resolve/main/space/src/display/formatting.py
- Command line
-
hf download hf://spaces/ThinkcatLab/LiveHouse-TS/space/src/display/formatting.py
-
curl -L -o formatting.py https://huggingface.co/spaces/ThinkcatLab/LiveHouse-TS/resolve/main/space/src/display/formatting.py
780 Bytes
| from datetime import datetime, timedelta, timezone | |
| UTC8 = timezone(timedelta(hours=8)) | |
| def format_timestamp_utc8(iso: str) -> str: | |
| """Format ISO-8601 timestamp as readable UTC+8 datetime.""" | |
| if not iso or iso == "n/a": | |
| return "n/a" | |
| try: | |
| dt = datetime.fromisoformat(iso.replace("Z", "+00:00")) | |
| local = dt.astimezone(UTC8) | |
| return local.strftime("%Y-%m-%d %H:%M:%S") + " (UTC+8)" | |
| except (ValueError, TypeError): | |
| return iso | |
| def model_hyperlink(model_link: str, code_link: str, model_name: str) -> str: | |
| if not model_link: | |
| return model_name | |
| model_url = f"[{model_name}]({model_link})" | |
| if not code_link: | |
| return model_url | |
| code_url = f"[code]({code_link})" | |
| return f"{model_url} ({code_url})" | |