{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "7d1d5c42", "metadata": {}, "outputs": [], "source": [ "\n", "import re\n", "import time\n", "from dotenv import dotenv_values\n", "from huggingface_hub import HfApi\n", "\n", "SPACE = \"Cyberlgl/CyberLegalAIendpoint\"\n", "ENV_FILE = \".env\"\n", "SLEEP = 0.15\n", "SECRET_RE = re.compile(r\"(KEY|TOKEN|SECRET|PASS|PASSWORD)\", re.I)\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "9ed85967", "metadata": {}, "outputs": [], "source": [ "\n", "env = {k: v for k, v in dotenv_values(ENV_FILE).items() if k and v is not None}" ] }, { "cell_type": "code", "execution_count": 3, "id": "ebc2564d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Uploaded 80 secrets to Cyberlgl/CyberLegalAIendpoint.\n" ] } ], "source": [ "\n", "env.pop(\"PORT\", None) # HF sets this; don't override it\n", "\n", "api = HfApi()\n", "\n", "# Optional: pause to avoid many restarts while pushing lots of vars\n", "# api.pause_space(repo_id=SPACE)\n", "\n", "for k, v in env.items():\n", " api.add_space_secret(repo_id=SPACE, key=k, value=str(v).strip().strip('\"').strip(\"'\"))\n", "api.restart_space(repo_id=SPACE)\n", "print(f\"Uploaded {len(env)} secrets to {SPACE}.\")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "c417b680", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "dc2a1cb2", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "cyberlgl", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.12" } }, "nbformat": 4, "nbformat_minor": 5 }