import os import csv import gradio as gr from gradio import inputs import huggingface_hub print("hfh", huggingface_hub.__version__) from huggingface_hub import hf_hub_download, upload_file from datetime import datetime DATASET_REPO_ID = "datasets/elonmuskceo/persistent-space-dataset" DATASET_REPO_URL = f"https://huggingface.co/{DATASET_REPO_ID}" DATA_DIRNAME = "data" DATA_FILENAME = "data.csv" DATA_FILE = os.path.join(DATA_DIRNAME, DATA_FILENAME) HF_TOKEN = os.environ.get("HF_TOKEN") print("hfh", huggingface_hub.__version__) # overriding/appending to the gradio template SCRIPT = """ """ with open(os.path.join(gr.networking.STATIC_TEMPLATE_LIB, "frontend", "index.html"), "a") as f: f.write(SCRIPT) try: hf_hub_download( repo_id=DATASET_REPO_ID, filename=DATA_FILENAME, cache_dir=DATA_DIRNAME, force_filename=DATA_FILENAME ) except: # file not found, we'll create it on the fly. print("file not found, probably") def generate_html() -> str: with open(DATA_FILE) as csvfile: reader = csv.DictReader(csvfile) rows = [] for row in reader: rows.append(row) rows.reverse() if len(rows) == 0: return "no messages yet" else: html = "