Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async cloudflare file-get #2922

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions fast_stable_diffusion_AUTOMATIC1111.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@
"import fileinput\n",
"from pyngrok import ngrok, conf\n",
"import re\n",
"import aiofiles\n",
"import asyncio\n",
"import re\n",
"from typing import Optional\n",
"\n",
"\n",
"Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n",
Expand All @@ -602,7 +606,7 @@
" !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n",
" !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n",
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n",
" \n",
"\n",
" !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n",
" #!sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n",
" !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n",
Expand All @@ -614,6 +618,27 @@
" !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n",
" !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n",
"\n",
"\n",
"async def get_cloudflare_url(filename: str, timeout: int = 60) -> Optional[str]:\n",
" pattern = r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\"\n",
" start_time = asyncio.get_event_loop().time()\n",
"\n",
" async def read_file():\n",
" async with aiofiles.open(filename, mode='r') as file:\n",
" while True:\n",
" line = await file.readline()\n",
" if line:\n",
" yield line\n",
" else:\n",
" await asyncio.sleep(0.1)\n",
"\n",
" async for line in read_file():\n",
" if asyncio.get_event_loop().time() - start_time > timeout:\n",
" return None\n",
" match = re.search(pattern, line)\n",
" if match:\n",
" return match.group(0)\n",
"\n",
"share=''\n",
"if Ngrok_token!=\"\":\n",
" ngrok.kill()\n",
Expand All @@ -633,22 +658,33 @@
"elif Use_Cloudflare_Tunnel:\n",
" with capture.capture_output() as cap:\n",
" !pkill cloudflared\n",
" time.sleep(4)\n",
" !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n",
" time.sleep(4)\n",
" with open('/content/srv.txt', \"r\") as file: text = file.read()\n",
" srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n",
"\n",
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
" if line.strip().startswith('self.server_name ='):\n",
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
" if line.strip().startswith('self.protocol = \"https\"'):\n",
" line = ' self.protocol = \"https\"\\n'\n",
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
" line = ''\n",
" if line.strip().startswith('else \"http\"'):\n",
" line = ''\n",
" sys.stdout.write(line)\n",
" try:\n",
" loop = asyncio.get_event_loop()\n",
" if loop.is_running():\n",
" !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n",
" future = asyncio.ensure_future(get_cloudflare_url('/content/srv.txt'))\n",
" srv = await future\n",
" else:\n",
" raise RuntimeError()\n",
" except RuntimeError:\n",
" time.sleep(2)\n",
" !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n",
" time.sleep(4)\n",
" with open('/content/srv.txt', \"r\") as file:\n",
" text = file.read()\n",
" srv = re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n",
"\n",
" if srv:\n",
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
" if line.strip().startswith('self.server_name ='):\n",
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
" if line.strip().startswith('self.protocol = \"https\"'):\n",
" line = ' self.protocol = \"https\"\\n'\n",
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
" line = ''\n",
" if line.strip().startswith('else \"http\"'):\n",
" line = ''\n",
" sys.stdout.write(line)\n",
"\n",
" !rm /content/srv.txt\n",
"\n",
Expand Down Expand Up @@ -686,4 +722,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}