potamides commited on
Commit
efdce2e
1 Parent(s): 81b7736

fix: use abort instead of execl

Browse files
Files changed (2) hide show
  1. Dockerfile +2 -1
  2. app.py +9 -9
Dockerfile CHANGED
@@ -79,4 +79,5 @@ COPY --chown=user . $HOME/app
79
  # -----------------------------------------------------------------------------
80
  USER user
81
 
82
- CMD ["python", "app.py"]
 
 
79
  # -----------------------------------------------------------------------------
80
  USER user
81
 
82
+ # repeat cmd on abort
83
+ CMD while python app.py; [ $? -eq 134 ]; do :; done
app.py CHANGED
@@ -1,5 +1,5 @@
1
- from os import execl, getenv
2
- from sys import argv, exception, executable
3
  from textwrap import dedent
4
  import traceback
5
 
@@ -11,13 +11,10 @@ from detikzify.webui import BANNER, build_ui, make_light
11
  def is_official_demo():
12
  return getenv("SPACE_AUTHOR_NAME") == "nllg"
13
 
14
- # Hack to temporarily work around memory leak, see:
15
- # * https://huggingface.co/spaces/nllg/DeTikZify/discussions/2
16
- # * https://github.com/gradio-app/gradio/issues/8503
17
- def reload_on_oom_hook(func):
18
  def wrapper(*args, **kwargs):
19
- if isinstance(exception(), (MemoryError, cuda.OutOfMemoryError)):
20
- execl(executable, executable, *argv)
21
  return func(*args, **kwargs)
22
  return wrapper
23
 
@@ -37,7 +34,10 @@ else:
37
  use_big_models = cuda.is_available() and cuda.get_device_properties(0).total_memory > 15835660288
38
  model = f"detikzify-ds-{'7' if use_big_models else '1.3'}b"
39
  demo = build_ui(lock=is_official_demo(), model=model, light=True).queue()
40
- traceback.print_exc = reload_on_oom_hook(traceback.print_exc)
 
 
 
41
 
42
  if __name__ == "__main__":
43
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ from os import abort, getenv
2
+ from sys import exception
3
  from textwrap import dedent
4
  import traceback
5
 
 
11
  def is_official_demo():
12
  return getenv("SPACE_AUTHOR_NAME") == "nllg"
13
 
14
+ def add_abort_hook(func, *errors):
 
 
 
15
  def wrapper(*args, **kwargs):
16
+ if isinstance(exception(), errors):
17
+ abort()
18
  return func(*args, **kwargs)
19
  return wrapper
20
 
 
34
  use_big_models = cuda.is_available() and cuda.get_device_properties(0).total_memory > 15835660288
35
  model = f"detikzify-ds-{'7' if use_big_models else '1.3'}b"
36
  demo = build_ui(lock=is_official_demo(), model=model, light=True).queue()
37
+ # Hack to temporarily work around memory leak, see:
38
+ # * https://huggingface.co/spaces/nllg/DeTikZify/discussions/2
39
+ # * https://github.com/gradio-app/gradio/issues/8503
40
+ traceback.print_exc = add_abort_hook(traceback.print_exc, MemoryError, cuda.OutOfMemoryError)
41
 
42
  if __name__ == "__main__":
43
  demo.launch(server_name="0.0.0.0", server_port=7860)