Spaces:
Sleeping
Sleeping
import json | |
from huggingface_hub import hf_hub_download | |
from datetime import datetime | |
def hf_pull_skill(repo_id, huggingface_skill_path): | |
try: | |
return_path = hf_hub_download(repo_id=repo_id, subfolder=huggingface_skill_path, repo_type="space", filename="skill.json") | |
with open(return_path) as f: | |
skill_json = json.load(f) | |
return skill_json | |
except Exception as e: | |
return e | |
def time_ago(updated_at_str): | |
now = datetime.now() | |
updated_at = datetime.strptime(updated_at_str, '%Y-%m-%d %H:%M:%S') | |
delta = now - updated_at | |
minutes = delta.total_seconds() / 60 | |
hours = minutes / 60 | |
days = hours / 24 | |
months = days / 30.44 # An average month length | |
years = days / 365.25 # Account for leap years | |
if minutes < 60: | |
return f"{int(minutes)} minutes ago" | |
elif hours < 24: | |
return f"{int(hours)} hours ago" | |
elif days < 30.44: | |
return f"{int(days)} days ago" | |
elif months < 12: | |
return f"{int(months)} months ago" | |
else: | |
return f"{int(years)} years ago" |