File size: 2,640 Bytes
396be42 229dbf4 ecf3aeb f2f1406 ecf3aeb 229dbf4 4d30656 1e15258 4d30656 f2f1406 ecf3aeb f2f1406 229dbf4 ecf3aeb 229dbf4 ecf3aeb f2f1406 ecf3aeb f2f1406 ecf3aeb 229dbf4 1dfe147 229dbf4 f2f1406 ecf3aeb 396be42 f2f1406 229dbf4 ecf3aeb f2f1406 ecf3aeb 36d7a36 1e15258 ecf3aeb 229dbf4 1dfe147 f37df6a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import subprocess, sys, os, time, errno, shlex
from IPython.display import clear_output, Image, display
from IPython import get_ipython
from pathlib import Path
xxx = Path('/kaggle/working')
script = xxx / 'venv.py'
img = xxx / "loading.png"
vnv = Path('/kaggle/venv')
url = 'https://huggingface.co/pantat88/back_up/resolve/main/venv-torch241-cu121.tar.lz4'
fn = Path(url).name
os.chdir(xxx)
sys.path.append(str(xxx))
get_ipython().system('curl -sLO https://raw.githubusercontent.com/gutris1/segsmaker/main/script/loading.png')
get_ipython().system('curl -sLO https://raw.githubusercontent.com/gutris1/segsmaker/main/kaggle/script/pantat88.py')
display(Image(filename=str(img)))
time.sleep(1)
from pantat88 import say, download
say('【{red} Installing VENV{d} 】{red}')
req_list = [
"curl -LO https://github.com/DEX-1101/sd-webui-notebook/raw/main/res/new_tunnel",
"curl -Lo /usr/bin/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64",
"apt-get update",
"apt -y install pv",
"pip install -q aria2 cloudpickle",
"chmod +x /usr/bin/cl"
]
for items in req_list:
subprocess.run(shlex.split(items), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def she_bang():
vnv_bin = vnv / 'bin'
old_shebang = b'#!/home/studio-lab-user/tmp/venv/bin/python3\n'
new_shebang = f"#!{vnv}/bin/python3\n"
for script in vnv_bin.glob('*'):
if script.is_file():
try:
with open(script, 'r+b') as file:
lines = file.readlines()
if lines and lines[0] == old_shebang:
lines[0] = new_shebang.encode('utf-8')
file.seek(0)
file.writelines(lines)
file.truncate()
print(f"Updated shebang in {script.name} to {new_shebang.strip()}")
except OSError as e:
if e.errno == 26:
print(f"Skipped {script.name}")
else:
print(f"Failed to update {script.name}: {e}")
def venv_install():
os.chdir('/kaggle')
download(url)
extract_venv = f'pv {fn} | lz4 -d | tar xf -'
get_ipython().system(extract_venv)
Path(fn).unlink()
get_ipython().system(f'rm -rf {vnv / "bin" / "pip*"}')
get_ipython().system(f'rm -rf {vnv / "bin" / "python*"}')
get_ipython().system(f'python3 -m venv {vnv}')
get_ipython().system(f'{vnv}/bin/python3 -m pip install -q --upgrade --force-reinstall pip')
venv_install()
she_bang()
clear_output(wait=True)
script.unlink()
os.chdir(xxx) |