import os import shutil import zipfile import threading import time import humanize from flask import Flask, request, jsonify, render_template_string import gdown from huggingface_hub import HfApi, login, upload_folder, hf_hub_url from huggingface_hub.utils import HfHubHTTPError # --- Configuration & Initialization --- # Ensure Hugging Face cache and other temp data writes to /tmp os.environ["HF_HOME"] = "/tmp/hf_home" DOWNLOAD_DIR = "/tmp/backups" EXTRACT_DIR = "/tmp/extracted_backups" # Environment variables (set these in your Space secrets) FOLDER_URL = os.getenv("FOLDER_URL") REPO_ID = os.getenv("REPO_ID") TOKEN = os.getenv("HF_TOKEN") # --- Global State Management --- app_state = { "backup_status": "idle", # idle, running, success, error "backup_log": ["Awaiting first run."], "last_backup_time": "Never", "next_backup_time": "Scheduler disabled", "schedule_interval_minutes": 0, # 0 means disabled "scheduler_thread": None # This will hold the non-serializable Thread object } # --- Flask App Setup --- app = Flask(__name__) api = HfApi() # --- HTML, CSS, JS Template --- HTML_TEMPLATE = """
Files in {{ repo_id }}
File Path | Size | Actions |
---|