Spaces:
Sleeping
Sleeping
File size: 1,516 Bytes
2a33d82 050be50 2d0cd91 050be50 b33480a 2d0cd91 b33480a 050be50 |
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 35 36 37 38 39 40 41 42 |
import os
import json
import huggingface_hub
from huggingface_hub import Repository
from datetime import datetime
# Define the path to your JSON file
DATASET_REPO_URL = "https://huggingface.co/datasets/bupa1018/Test"
DATA_FILENAME = "repo_data.json"
DATA_FILE = os.path.join("data", DATA_FILENAME)
# Function to retrieve the last download entry from the JSON file
def store_message_from_json(hf_token):
try:
repo = Repository(
local_dir="data", clone_from=DATASET_REPO_URL, use_auth_token=hf_token
)
# Open and load the JSON file
with open(DATA_FILE, "r") as jsonfile:
data = json.load(jsonfile)
# Check if the "downloads" list exists and is not empty
if "downloads" in data and len(data["downloads"]) > 0:
# Retrieve the last item in the "downloads" list
last_download = data["downloads"][-1]
version = last_download["version"]
commit_hash = last_download["commit_hash"]
download_date = last_download["download_date"]
# Print or return the extracted data
return f"Version: {version}, Commit Hash: {commit_hash}, Download Date: {download_date}"
else:
return "No downloads found in the JSON file."
except FileNotFoundError:
return "The JSON file does not exist."
except json.JSONDecodeError:
return "Error decoding the JSON file."
except Exception as e:
return f"An error occurred: {e}"
|