Spaces:
Paused
Paused
Detect ZeroGPU from Spaces environment
Browse files- src/api/main.py +8 -1
- tests/test_zero_gpu_contract.py +2 -0
src/api/main.py
CHANGED
|
@@ -70,7 +70,14 @@ if _is_test_mode():
|
|
| 70 |
|
| 71 |
|
| 72 |
def _is_zero_gpu_space() -> bool:
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def _effective_inference_backend():
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
def _is_zero_gpu_space() -> bool:
|
| 73 |
+
hardware = os.environ.get("SPACE_HARDWARE", "").strip().lower()
|
| 74 |
+
zero_gpu_flag = os.environ.get("SPACES_ZERO_GPU", "").strip().lower()
|
| 75 |
+
space_id = os.environ.get("SPACE_ID", "").strip().lower()
|
| 76 |
+
return (
|
| 77 |
+
"zero-gpu" in hardware
|
| 78 |
+
or zero_gpu_flag in {"1", "true", "yes", "on"}
|
| 79 |
+
or space_id.startswith("akagtag/")
|
| 80 |
+
)
|
| 81 |
|
| 82 |
|
| 83 |
def _effective_inference_backend():
|
tests/test_zero_gpu_contract.py
CHANGED
|
@@ -61,6 +61,8 @@ def test_api_gradio_compat_redirect_exists():
|
|
| 61 |
|
| 62 |
assert "RedirectResponse" in source
|
| 63 |
assert 'url="/"' in source
|
|
|
|
|
|
|
| 64 |
assert any(
|
| 65 |
isinstance(node, ast.AsyncFunctionDef) and node.name == "gradio_compat_redirect"
|
| 66 |
for node in tree.body
|
|
|
|
| 61 |
|
| 62 |
assert "RedirectResponse" in source
|
| 63 |
assert 'url="/"' in source
|
| 64 |
+
assert "SPACE_HARDWARE" in source
|
| 65 |
+
assert "SPACES_ZERO_GPU" in source
|
| 66 |
assert any(
|
| 67 |
isinstance(node, ast.AsyncFunctionDef) and node.name == "gradio_compat_redirect"
|
| 68 |
for node in tree.body
|