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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from IPython.display import display, HTML, clear_output, Image
|
| 2 |
+
from IPython import get_ipython
|
| 3 |
+
from ipywidgets import widgets
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import subprocess
|
| 6 |
+
import shlex
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
home = Path.home()
|
| 10 |
+
src = home / '.gutris1'
|
| 11 |
+
css = src / 'segsmaker.css'
|
| 12 |
+
startup = home / '.ipython/profile_default/startup'
|
| 13 |
+
nenen = startup / 'nenen88.py'
|
| 14 |
+
key_file = src / 'api-key.json'
|
| 15 |
+
img = src / 'loading.png'
|
| 16 |
+
|
| 17 |
+
R = '\033[0m'
|
| 18 |
+
T = f'鈻秢R}'
|
| 19 |
+
BLUE = f'\033[38;5;33m{T}'
|
| 20 |
+
CYAN = f'\033[36m{T}'
|
| 21 |
+
PURPLE = f'\033[38;5;135m{T}'
|
| 22 |
+
PINK = f'\033[38;5;201m{T}'
|
| 23 |
+
RED = f'\033[31m{T}'
|
| 24 |
+
GREEN = f'\033[38;5;35m{T}'
|
| 25 |
+
|
| 26 |
+
Path(src).mkdir(parents=True, exist_ok=True)
|
| 27 |
+
|
| 28 |
+
SyS = get_ipython().system
|
| 29 |
+
|
| 30 |
+
main_output = widgets.Output()
|
| 31 |
+
save_button = widgets.Button(description='Save')
|
| 32 |
+
civitai_key_box = widgets.Text(placeholder='Enter Your Civitai API Key Here', layout=widgets.Layout(width='350px'))
|
| 33 |
+
hf_token_box = widgets.Text(placeholder='Huggingface READ Token (optional)', layout=widgets.Layout(width='350px'))
|
| 34 |
+
input_widget = widgets.Box(
|
| 35 |
+
[civitai_key_box, hf_token_box, save_button],
|
| 36 |
+
layout=widgets.Layout(
|
| 37 |
+
width='500px',
|
| 38 |
+
height='200px',
|
| 39 |
+
display='flex',
|
| 40 |
+
flex_flow='column',
|
| 41 |
+
align_items='center',
|
| 42 |
+
justify_content='space-around',
|
| 43 |
+
padding='10px'
|
| 44 |
+
)
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
save_button.add_class('save-button')
|
| 48 |
+
civitai_key_box.add_class('api-input')
|
| 49 |
+
hf_token_box.add_class('api-input')
|
| 50 |
+
input_widget.add_class('boxs')
|
| 51 |
+
|
| 52 |
+
def CondaInstall():
|
| 53 |
+
try:
|
| 54 |
+
display(Image(filename=str(img)))
|
| 55 |
+
print(f"{BLUE} Iniciando actualizaci贸n forzada a Python 3.10.13...")
|
| 56 |
+
|
| 57 |
+
cmd_list = [
|
| 58 |
+
(f'rm -rf {home}/.condarc', None),
|
| 59 |
+
('conda config --add channels conda-forge', None),
|
| 60 |
+
('conda install -qy mamba', f'{BLUE} Installing Anaconda'),
|
| 61 |
+
('mamba install -y conda', None),
|
| 62 |
+
# Forzar reinstalaci贸n de Python 3.10.13
|
| 63 |
+
('mamba install -y --force-reinstall python=3.10.13', f'{CYAN} Installing Python 3.10.13 (Forced)'),
|
| 64 |
+
('mamba install -y glib gperftools openssh pv gputil curl', f'{PURPLE} Installing Conda Packages'),
|
| 65 |
+
('pip install psutil aria2 gdown', f'{PINK} Installing Python Packages'),
|
| 66 |
+
('conda clean -qy --all', None)
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
for cmd, msg in cmd_list:
|
| 70 |
+
if msg is not None: print(msg)
|
| 71 |
+
try:
|
| 72 |
+
result = subprocess.run(shlex.split(cmd), capture_output=True, text=True)
|
| 73 |
+
if result.returncode != 0 and result.stderr:
|
| 74 |
+
print(f"Command '{cmd}' failed with error: {result.stderr}")
|
| 75 |
+
except Exception as e:
|
| 76 |
+
print(f"Error executing '{cmd}': {e}")
|
| 77 |
+
|
| 78 |
+
# Verificar la versi贸n de Python despu茅s de la instalaci贸n
|
| 79 |
+
try:
|
| 80 |
+
python_ver = subprocess.run(['python', '--version'], capture_output=True, text=True)
|
| 81 |
+
print(f"{GREEN} Python version after installation: {python_ver.stdout.strip()}")
|
| 82 |
+
except Exception as e:
|
| 83 |
+
print(f"Error checking Python version: {e}")
|
| 84 |
+
|
| 85 |
+
SyS(f'rm -rf {home}/.cache/* {home}/.condarc')
|
| 86 |
+
clear_output()
|
| 87 |
+
print(f'{GREEN} Done! Python 3.10.13 installation completed')
|
| 88 |
+
|
| 89 |
+
get_ipython().kernel.do_shutdown(True)
|
| 90 |
+
|
| 91 |
+
except KeyboardInterrupt:
|
| 92 |
+
clear_output()
|
| 93 |
+
print('^ Canceled')
|
| 94 |
+
|
| 95 |
+
def LoadCSS():
|
| 96 |
+
display(HTML(f'<style>{open(css).read()}</style>'))
|
| 97 |
+
|
| 98 |
+
def KeyInject(civitai_key, hf_token):
|
| 99 |
+
SyS(f'curl -sLo {nenen} https://github.com/gutris1/segsmaker/raw/main/script/nenen88.py')
|
| 100 |
+
|
| 101 |
+
p = Path(nenen)
|
| 102 |
+
v = p.read_text()
|
| 103 |
+
v = v.replace("TOKET = ''", f"TOKET = '{civitai_key}'")
|
| 104 |
+
v = v.replace("TOBRUT = ''", f"TOBRUT = '{hf_token}'")
|
| 105 |
+
p.write_text(v)
|
| 106 |
+
|
| 107 |
+
def KeyWidget(civitai_key='', hf_token=''):
|
| 108 |
+
civitai_key_box.value = civitai_key
|
| 109 |
+
hf_token_box.value = hf_token
|
| 110 |
+
|
| 111 |
+
def KeyInputs(b):
|
| 112 |
+
civitai_key = civitai_key_box.value.strip()
|
| 113 |
+
hf_token = hf_token_box.value.strip()
|
| 114 |
+
|
| 115 |
+
with main_output:
|
| 116 |
+
if not civitai_key:
|
| 117 |
+
print('Please enter your Civitai API Key')
|
| 118 |
+
return
|
| 119 |
+
|
| 120 |
+
if len(civitai_key) < 32:
|
| 121 |
+
print('API key must be at least 32 characters long')
|
| 122 |
+
return
|
| 123 |
+
|
| 124 |
+
civitai_key_value = {'civitai-api-key': civitai_key}
|
| 125 |
+
hf_token_value = {'huggingface-read-token': hf_token}
|
| 126 |
+
|
| 127 |
+
secrets = {**civitai_key_value, **hf_token_value}
|
| 128 |
+
key_file.write_text(json.dumps(secrets, indent=4))
|
| 129 |
+
|
| 130 |
+
KeyInject(civitai_key, hf_token)
|
| 131 |
+
|
| 132 |
+
input_widget.close()
|
| 133 |
+
main_output.clear_output()
|
| 134 |
+
|
| 135 |
+
# Siempre forzar la actualizaci贸n a Python 3.10.13
|
| 136 |
+
with main_output:
|
| 137 |
+
print(f"{CYAN} Forzando actualizaci贸n a Python 3.10.13...")
|
| 138 |
+
CondaInstall()
|
| 139 |
+
|
| 140 |
+
save_button.on_click(KeyInputs)
|
| 141 |
+
|
| 142 |
+
def KeyCheck():
|
| 143 |
+
if key_file.exists():
|
| 144 |
+
v = json.loads(key_file.read_text())
|
| 145 |
+
|
| 146 |
+
civitai_key = v.get('civitai-api-key', '')
|
| 147 |
+
hf_token = v.get('huggingface-read-token', '')
|
| 148 |
+
|
| 149 |
+
if not civitai_key or not hf_token:
|
| 150 |
+
display(input_widget, main_output)
|
| 151 |
+
KeyWidget(civitai_key, hf_token)
|
| 152 |
+
else:
|
| 153 |
+
KeyInject(civitai_key, hf_token)
|
| 154 |
+
display(main_output)
|
| 155 |
+
# Forzar la actualizaci贸n sin importar la versi贸n actual de Conda
|
| 156 |
+
CondaInstall()
|
| 157 |
+
else:
|
| 158 |
+
display(input_widget, main_output)
|
| 159 |
+
KeyWidget()
|
| 160 |
+
|
| 161 |
+
def CondaMisc():
|
| 162 |
+
for scr in [
|
| 163 |
+
f'curl -sLo {css} https://github.com/gutris1/segsmaker/raw/main/script/SM/segsmaker.css',
|
| 164 |
+
f'curl -sLo {startup}/00-startup.py https://github.com/gutris1/segsmaker/raw/main/script/SM/00-startup.py',
|
| 165 |
+
f'curl -sLo {startup}/util.py https://github.com/gutris1/segsmaker/raw/main/script/SM/util.py',
|
| 166 |
+
f'curl -sLo {img} https://github.com/gutris1/segsmaker/raw/main/script/loading.png',
|
| 167 |
+
f'curl -sLo {startup}/cupang.py https://github.com/gutris1/segsmaker/raw/main/script/cupang.py'
|
| 168 |
+
]: SyS(scr)
|
| 169 |
+
|
| 170 |
+
CondaMisc()
|
| 171 |
+
LoadCSS()
|
| 172 |
+
KeyCheck()
|