Spaces:
Running
on
Zero
Running
on
Zero
Set MPLCONFIGDIR for matplotlib and safely run GPU warmup in request context
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ print(f"Starting up: {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
|
| 5 |
# Standard library imports
|
| 6 |
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
#Enforce local cching:
|
| 10 |
|
|
@@ -238,12 +239,10 @@ def no_op_decorator(func):
|
|
| 238 |
# decorator_to_use = spaces.GPU() if is_running_in_hf_space() else no_op_decorator
|
| 239 |
# #duration=120
|
| 240 |
|
| 241 |
-
@spaces.GPU(duration=1)
|
| 242 |
-
def _warmup():
|
| 243 |
print("Warming up...")
|
| 244 |
|
| 245 |
-
_warmup()
|
| 246 |
-
|
| 247 |
|
| 248 |
# if is_running_in_hf_space():
|
| 249 |
@spaces.GPU(duration=30)
|
|
@@ -1423,6 +1422,9 @@ with gr.Blocks(theme=theme, css=f"""
|
|
| 1423 |
outputs=query_display
|
| 1424 |
)
|
| 1425 |
|
|
|
|
|
|
|
|
|
|
| 1426 |
|
| 1427 |
# demo.static_dirs = {
|
| 1428 |
# "static": str(static_dir)
|
|
|
|
| 5 |
# Standard library imports
|
| 6 |
|
| 7 |
import os
|
| 8 |
+
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib" # set BEFORE importing matplotlib
|
| 9 |
|
| 10 |
#Enforce local cching:
|
| 11 |
|
|
|
|
| 239 |
# decorator_to_use = spaces.GPU() if is_running_in_hf_space() else no_op_decorator
|
| 240 |
# #duration=120
|
| 241 |
|
| 242 |
+
@spaces.GPU(duration=1)
|
| 243 |
+
def _warmup():
|
| 244 |
print("Warming up...")
|
| 245 |
|
|
|
|
|
|
|
| 246 |
|
| 247 |
# if is_running_in_hf_space():
|
| 248 |
@spaces.GPU(duration=30)
|
|
|
|
| 1422 |
outputs=query_display
|
| 1423 |
)
|
| 1424 |
|
| 1425 |
+
# Run a tiny GPU warmup safely inside a request context
|
| 1426 |
+
demo.load(fn=_warmup, inputs=None, outputs=None, queue=False)
|
| 1427 |
+
|
| 1428 |
|
| 1429 |
# demo.static_dirs = {
|
| 1430 |
# "static": str(static_dir)
|