Spaces:
Running
Running
import datetime | |
import json | |
import os | |
import gradio as gr | |
import huggingface_hub as hfh | |
from apscheduler.schedulers.background import BackgroundScheduler | |
def greet(name): | |
return "Hello " + name + "!!" | |
iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch() | |
def update_datasets(): | |
datasets = hfh.list_datasets() | |
# | |
token = os.environ.get('HUB_TOKEN') | |
repo = hfh.Repository( | |
local_dir="dataset", | |
clone_from="albertvillanova/datasets-report", | |
repo_type="dataset", | |
use_auth_token=token, | |
) | |
repo.git_pull() | |
os.makedirs("dataset/data", exist_ok=True) | |
today = datetime.datetime.now(datetime.timezone.utc).date().isoformat() | |
with repo.commit(f"Add {today} data file"): | |
with open(f"data/{today}.json", "w") as f: | |
json.dump([ds.id for ds in sorted(datasets, key=lambda item: item.id)], f) | |
scheduler = BackgroundScheduler() | |
scheduler.add_job(update_datasets, trigger="cron", hour=0, minute=1, timezone=datetime.timezone.utc) | |
scheduler.start() | |
iface.launch() | |