MogensR commited on
Commit
52c1994
·
1 Parent(s): 05b25c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -10,6 +10,35 @@
10
  from pathlib import Path
11
  from typing import Optional, Tuple, Dict, Any, Callable
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # 1️⃣ Set CSP-safe environment variables BEFORE any imports (Gradio will see these)
14
  os.environ['GRADIO_ALLOW_FLAGGING'] = 'never'
15
  os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
@@ -31,7 +60,7 @@ def patched_get_type(schema):
31
  return "string"
32
  return orig_get_type(schema)
33
  gc_utils.get_type = patched_get_type
34
- except Exception as e:
35
  pass # No fatal error if Gradio patch fails
36
 
37
  # 3️⃣ Set up logging early for debugging
@@ -175,7 +204,6 @@ def safe_process(vid, style, custom_bg_file):
175
  demo.queue().launch(
176
  server_name="0.0.0.0",
177
  server_port=7860,
178
- share=True,
179
  show_error=True,
180
  debug=False,
181
  inbrowser=False # Never open browser (CSP fails)
 
10
  from pathlib import Path
11
  from typing import Optional, Tuple, Dict, Any, Callable
12
 
13
+ # 0️⃣ Early threading/OMP sanitization (prevents libgomp + interop warnings)
14
+ def _clean_int_env(name: str, default: str | None = None):
15
+ val = os.environ.get(name)
16
+ if val is None:
17
+ if default is not None:
18
+ os.environ[name] = str(default)
19
+ return
20
+ try:
21
+ int(str(val).strip())
22
+ except ValueError:
23
+ if default is None:
24
+ os.environ.pop(name, None)
25
+ else:
26
+ os.environ[name] = str(default)
27
+
28
+ _clean_int_env("OMP_NUM_THREADS", "2")
29
+ _clean_int_env("MKL_NUM_THREADS", "2")
30
+ _clean_int_env("OPENBLAS_NUM_THREADS", "2")
31
+ _clean_int_env("NUMEXPR_NUM_THREADS", "2")
32
+
33
+ try:
34
+ import torch # call thread setters BEFORE heavy parallel work starts
35
+ if hasattr(torch, "set_num_interop_threads"):
36
+ torch.set_num_interop_threads(2)
37
+ if hasattr(torch, "set_num_threads"):
38
+ torch.set_num_threads(2)
39
+ except Exception:
40
+ pass
41
+
42
  # 1️⃣ Set CSP-safe environment variables BEFORE any imports (Gradio will see these)
43
  os.environ['GRADIO_ALLOW_FLAGGING'] = 'never'
44
  os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
 
60
  return "string"
61
  return orig_get_type(schema)
62
  gc_utils.get_type = patched_get_type
63
+ except Exception:
64
  pass # No fatal error if Gradio patch fails
65
 
66
  # 3️⃣ Set up logging early for debugging
 
204
  demo.queue().launch(
205
  server_name="0.0.0.0",
206
  server_port=7860,
 
207
  show_error=True,
208
  debug=False,
209
  inbrowser=False # Never open browser (CSP fails)