Skip to content

Commit f8c6468

Browse files
authored
Merge branch 'master' into vae-picker
2 parents 7c8c371 + 198a1ff commit f8c6468

28 files changed

+1827
-1143
lines changed

javascript/extensions.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
function extensions_apply(_, _){
3+
disable = []
4+
update = []
5+
gradioApp().querySelectorAll('#extensions input[type="checkbox"]').forEach(function(x){
6+
if(x.name.startsWith("enable_") && ! x.checked)
7+
disable.push(x.name.substr(7))
8+
9+
if(x.name.startsWith("update_") && x.checked)
10+
update.push(x.name.substr(7))
11+
})
12+
13+
restart_reload()
14+
15+
return [JSON.stringify(disable), JSON.stringify(update)]
16+
}
17+
18+
function extensions_check(){
19+
gradioApp().querySelectorAll('#extensions .extension_status').forEach(function(x){
20+
x.innerHTML = "Loading..."
21+
})
22+
23+
return []
24+
}
25+
26+
function install_extension_from_index(button, url){
27+
button.disabled = "disabled"
28+
button.value = "Installing..."
29+
30+
textarea = gradioApp().querySelector('#extension_to_install textarea')
31+
textarea.value = url
32+
textarea.dispatchEvent(new Event("input", { bubbles: true }))
33+
34+
gradioApp().querySelector('#install_extension_button').click()
35+
}

launch.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import platform
88

99
dir_repos = "repositories"
10+
dir_extensions = "extensions"
1011
python = sys.executable
1112
git = os.environ.get('GIT', "git")
1213
index_url = os.environ.get('INDEX_URL', "")
@@ -16,11 +17,11 @@ def extract_arg(args, name):
1617
return [x for x in args if x != name], name in args
1718

1819

19-
def run(command, desc=None, errdesc=None):
20+
def run(command, desc=None, errdesc=None, custom_env=None):
2021
if desc is not None:
2122
print(desc)
2223

23-
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
24+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
2425

2526
if result.returncode != 0:
2627

@@ -101,9 +102,27 @@ def version_check(commit):
101102
else:
102103
print("Not a git clone, can't perform version check.")
103104
except Exception as e:
104-
print("versipm check failed",e)
105+
print("version check failed", e)
106+
107+
108+
def run_extensions_installers():
109+
if not os.path.isdir(dir_extensions):
110+
return
111+
112+
for dirname_extension in os.listdir(dir_extensions):
113+
path_installer = os.path.join(dir_extensions, dirname_extension, "install.py")
114+
if not os.path.isfile(path_installer):
115+
continue
116+
117+
try:
118+
env = os.environ.copy()
119+
env['PYTHONPATH'] = os.path.abspath(".")
120+
121+
print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {dirname_extension}", custom_env=env))
122+
except Exception as e:
123+
print(e, file=sys.stderr)
124+
105125

106-
107126
def prepare_enviroment():
108127
torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113")
109128
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
@@ -189,6 +208,8 @@ def prepare_enviroment():
189208

190209
run_pip(f"install -r {requirements_file}", "requirements for Web UI")
191210

211+
run_extensions_installers()
212+
192213
if update_check:
193214
version_check(commit)
194215

0 commit comments

Comments
 (0)