carloscar commited on
Commit
42192c2
1 Parent(s): f54fe10

Modifies sys.argv depending on 'IS_SHARED_UI' env value + GPU presence

Browse files
Files changed (3) hide show
  1. Dockerfile +1 -1
  2. header_patch.py +2 -1
  3. run.py +26 -6
Dockerfile CHANGED
@@ -121,4 +121,4 @@ RUN chmod +x on_start.sh
121
 
122
  EXPOSE 7860
123
 
124
- CMD ["/opt/venv/bin/python", "run.py", "--listen", "--enable-insecure-extension-access", "--ui-config-file", "ui-config.json", "--ui-settings-file", "config.json", "--disable-console-progressbars", "--cors-allow-origins", "huggingface.co,hf.space", "--no-progressbar-hiding", "--enable-console-prompts", "--no-download-sd-model", "--api", "--skip-version-check"]
 
121
 
122
  EXPOSE 7860
123
 
124
+ CMD ["/opt/venv/bin/python", "run.py", "--listen", "--ui-config-file", "ui-config.json", "--ui-settings-file", "config.json", "--disable-console-progressbars", "--cors-allow-origins", "huggingface.co,hf.space", "--no-progressbar-hiding", "--enable-console-prompts", "--no-download-sd-model", "--api", "--skip-version-check"]
header_patch.py CHANGED
@@ -1,5 +1,6 @@
1
  with gr.Box(visible=os.environ.get("SPACE_ID")):
2
- if os.environ.get("SPACE_ID") and str(os.environ.get("IS_SHARED_UI", "") or "") not in ("", "0"):
 
3
  import torch
4
  if not torch.cuda.is_available():
5
  gr.HTML(f"""
 
1
  with gr.Box(visible=os.environ.get("SPACE_ID")):
2
+ is_shared_ui = str(os.environ.get("IS_SHARED_UI", "") or "").strip().lower() not in ("", "0", "false", "none", "no")
3
+ if is_shared_ui:
4
  import torch
5
  if not torch.cuda.is_available():
6
  gr.HTML(f"""
run.py CHANGED
@@ -13,23 +13,43 @@ def on_start():
13
 
14
 
15
  def start():
16
- on_start()
17
-
18
  print("---------------")
19
  print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")
20
  print("---------------")
21
  import webui # type: ignore # noqa
22
- if '--nowebui' in sys.argv:
 
23
  webui.api_only()
24
  else:
25
  webui.webui()
26
 
27
 
28
- if __name__ == "__main__":
29
- import torch
 
30
  if not torch.cuda.is_available():
31
- sys.argv.extend(["--precision", "full", "--no-half", "--use-cpu", "SD", "BSRGAN", "ESRGAN", "SCUNet", "CodeFormer", "--all"])
 
 
 
 
 
 
 
 
 
 
32
  else:
 
33
  sys.argv.extend(["--force-enable-xformers", "--xformers"])
34
 
 
 
 
 
 
 
 
 
 
35
  start()
 
13
 
14
 
15
  def start():
 
 
16
  print("---------------")
17
  print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")
18
  print("---------------")
19
  import webui # type: ignore # noqa
20
+
21
+ if "--nowebui" in sys.argv:
22
  webui.api_only()
23
  else:
24
  webui.webui()
25
 
26
 
27
+ def set_options():
28
+ import torch # type: ignore # noqa
29
+
30
  if not torch.cuda.is_available():
31
+ # If no GPU is available, uninstall xformers and apply "--precision full --no-half --use-cpu all" to sys.argv.
32
+ os.system(f"{sys.executable} -m pip uninstall -y xformers")
33
+ sys.argv.extend(
34
+ [
35
+ "--precision",
36
+ "full",
37
+ "--no-half",
38
+ "--use-cpu",
39
+ "all",
40
+ ]
41
+ )
42
  else:
43
+ # Applies "--force-enable-xformers --xformers" to sys.argv when there's a GPU present.
44
  sys.argv.extend(["--force-enable-xformers", "--xformers"])
45
 
46
+ is_shared_ui = str(os.environ.get("IS_SHARED_UI", "") or "").strip().lower() not in ("", "0", "false", "none", "no")
47
+ if not is_shared_ui:
48
+ # Provide access to extensions only if IS_SHARED_UI isn't set.
49
+ sys.argv.extend(["--enable-insecure-extension-access"])
50
+
51
+
52
+ if __name__ == "__main__":
53
+ set_options()
54
+ on_start()
55
  start()