Spaces:
Runtime error
Runtime error
| 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}" | |