Spaces:
Runtime error
Runtime error
Delete demo.ipynb
Browse files- demo.ipynb +0 -114
demo.ipynb
DELETED
|
@@ -1,114 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": null,
|
| 6 |
-
"id": "538a3f0c-50c1-4952-9fcc-070d365c9a0f",
|
| 7 |
-
"metadata": {
|
| 8 |
-
"id": "538a3f0c-50c1-4952-9fcc-070d365c9a0f",
|
| 9 |
-
"scrolled": true
|
| 10 |
-
},
|
| 11 |
-
"outputs": [],
|
| 12 |
-
"source": [
|
| 13 |
-
"import os\n",
|
| 14 |
-
"import subprocess\n",
|
| 15 |
-
"from threading import Timer\n",
|
| 16 |
-
"from queue import Queue\n",
|
| 17 |
-
"\n",
|
| 18 |
-
"def is_colab():\n",
|
| 19 |
-
" try:\n",
|
| 20 |
-
" import google.colab\n",
|
| 21 |
-
" return True\n",
|
| 22 |
-
" except ImportError:\n",
|
| 23 |
-
" return False\n",
|
| 24 |
-
"\n",
|
| 25 |
-
"ROOT_DIR = \"/workspace/\" if not is_colab() else \"/content/\"\n",
|
| 26 |
-
"REPO_URL = \"https://huggingface.co/spaces/Tasty-Rice/Magic_on_paper\"\n",
|
| 27 |
-
"REPO_DIR = os.path.join(ROOT_DIR, \"Magic_on_paper\")\n",
|
| 28 |
-
"\n",
|
| 29 |
-
"NGROK_TOKEN = \"\"\n",
|
| 30 |
-
"NGROK_SUBDOMAIN = \"\"\n",
|
| 31 |
-
"PORT = 7860\n",
|
| 32 |
-
"\n",
|
| 33 |
-
"# os.environ[\"HF_TOKEN\"] = \"\"\n",
|
| 34 |
-
"os.environ[\"IS_COLAB\"] = \"1\"\n",
|
| 35 |
-
"os.environ[\"MODEL\"] = \"https://huggingface.co/Tasty-Rice/Magic_on_paper/blob/main/Magic_on_paper-SDXL-v3.safetensors\"\n",
|
| 36 |
-
"os.environ[\"CACHE_EXAMPLES\"] = \"1\"\n",
|
| 37 |
-
"\n",
|
| 38 |
-
"def clone_repository(url, directory, branch=None):\n",
|
| 39 |
-
" subprocess.run([\"git\", \"clone\", url, directory], check=True)\n",
|
| 40 |
-
" if branch:\n",
|
| 41 |
-
" subprocess.run([\"git\", \"checkout\", branch], cwd=directory, check=True)\n",
|
| 42 |
-
"\n",
|
| 43 |
-
"def install_dependencies(directory):\n",
|
| 44 |
-
" dependencies = [\"accelerate==0.27.2\", \"diffusers==0.26.3\", \"gradio==4.20.0\",\n",
|
| 45 |
-
" \"invisible-watermark==0.2.0\", \"spaces==0.24.0\", \"omegaconf==2.3.0\", \"timm==0.9.10\"]\n",
|
| 46 |
-
" if is_colab():\n",
|
| 47 |
-
" subprocess.run([\"pip\", \"install\"] + dependencies, check=True)\n",
|
| 48 |
-
" else:\n",
|
| 49 |
-
" requirements_path = os.path.join(directory, \"requirements.txt\")\n",
|
| 50 |
-
" subprocess.run([\"pip\", \"install\", \"-r\", requirements_path], check=True)\n",
|
| 51 |
-
"\n",
|
| 52 |
-
"def setup_ngrok_tunnel(port, queue, auth_token, subdomain):\n",
|
| 53 |
-
" ngrok.set_auth_token(auth_token)\n",
|
| 54 |
-
" url = ngrok.connect(port, bind_tls=True, subdomain=subdomain)\n",
|
| 55 |
-
" queue.put(url)\n",
|
| 56 |
-
"\n",
|
| 57 |
-
"def main():\n",
|
| 58 |
-
" if not os.path.exists(REPO_DIR):\n",
|
| 59 |
-
" print(f\"Cloning repository to {REPO_DIR}\")\n",
|
| 60 |
-
" clone_repository(REPO_URL, REPO_DIR)\n",
|
| 61 |
-
"\n",
|
| 62 |
-
" print(\"Installing required Python libraries\")\n",
|
| 63 |
-
" install_dependencies(REPO_DIR)\n",
|
| 64 |
-
" print(\"Done!\")\n",
|
| 65 |
-
"\n",
|
| 66 |
-
" os.chdir(REPO_DIR)\n",
|
| 67 |
-
"\n",
|
| 68 |
-
" if NGROK_TOKEN:\n",
|
| 69 |
-
" try:\n",
|
| 70 |
-
" from pyngrok import conf, ngrok\n",
|
| 71 |
-
" except ImportError:\n",
|
| 72 |
-
" subprocess.run([\"pip\", \"install\", \"-qqqq\", \"--upgrade\", \"setuptools\"], check=True)\n",
|
| 73 |
-
" subprocess.run([\"pip\", \"install\", \"-qqqq\", \"-U\", \"pyngrok\"], check=True)\n",
|
| 74 |
-
" from pyngrok import conf, ngrok\n",
|
| 75 |
-
"\n",
|
| 76 |
-
" ngrok.kill()\n",
|
| 77 |
-
" ngrok_output_queue = Queue()\n",
|
| 78 |
-
" ngrok_thread = Timer(2, setup_ngrok_tunnel, args=(PORT, ngrok_output_queue, NGROK_TOKEN, NGROK_SUBDOMAIN))\n",
|
| 79 |
-
" ngrok_thread.start()\n",
|
| 80 |
-
" ngrok_thread.join()\n",
|
| 81 |
-
" print(ngrok_output_queue.get())\n",
|
| 82 |
-
"\n",
|
| 83 |
-
" !python app.py\n",
|
| 84 |
-
"\n",
|
| 85 |
-
"if __name__ == \"__main__\":\n",
|
| 86 |
-
" main()"
|
| 87 |
-
]
|
| 88 |
-
}
|
| 89 |
-
],
|
| 90 |
-
"metadata": {
|
| 91 |
-
"colab": {
|
| 92 |
-
"provenance": []
|
| 93 |
-
},
|
| 94 |
-
"kernelspec": {
|
| 95 |
-
"display_name": "Python 3 (ipykernel)",
|
| 96 |
-
"language": "python",
|
| 97 |
-
"name": "python3"
|
| 98 |
-
},
|
| 99 |
-
"language_info": {
|
| 100 |
-
"codemirror_mode": {
|
| 101 |
-
"name": "ipython",
|
| 102 |
-
"version": 3
|
| 103 |
-
},
|
| 104 |
-
"file_extension": ".py",
|
| 105 |
-
"mimetype": "text/x-python",
|
| 106 |
-
"name": "python",
|
| 107 |
-
"nbconvert_exporter": "python",
|
| 108 |
-
"pygments_lexer": "ipython3",
|
| 109 |
-
"version": "3.10.12"
|
| 110 |
-
}
|
| 111 |
-
},
|
| 112 |
-
"nbformat": 4,
|
| 113 |
-
"nbformat_minor": 5
|
| 114 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|