File size: 1,085 Bytes
f93d5f5
 
 
 
 
2262d15
 
 
 
 
 
 
f93d5f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"