Spaces:
Running on Zero
Running on Zero
Update mvsepless/gradio_helper.py
Browse files- mvsepless/gradio_helper.py +12 -7
mvsepless/gradio_helper.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import zipfile
|
| 4 |
from datetime import timezone, timedelta
|
| 5 |
import platform
|
|
|
|
| 6 |
try:
|
| 7 |
import spaces
|
| 8 |
except:
|
|
@@ -250,14 +251,18 @@ else:
|
|
| 250 |
if zerogpu_is:
|
| 251 |
zerogpu_available = True
|
| 252 |
def hf_spaces_gpu(*args, device="cpu", **kwargs):
|
| 253 |
-
# Поддержка разных вариантов вызова
|
| 254 |
device = "cuda:0"
|
| 255 |
-
|
| 256 |
-
#
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
else:
|
| 262 |
def hf_spaces_gpu(*args, **kwargs):
|
| 263 |
if len(args) == 1 and callable(args[0]):
|
|
|
|
| 3 |
import zipfile
|
| 4 |
from datetime import timezone, timedelta
|
| 5 |
import platform
|
| 6 |
+
from functools import wraps
|
| 7 |
try:
|
| 8 |
import spaces
|
| 9 |
except:
|
|
|
|
| 251 |
if zerogpu_is:
|
| 252 |
zerogpu_available = True
|
| 253 |
def hf_spaces_gpu(*args, device="cpu", **kwargs):
|
|
|
|
| 254 |
device = "cuda:0"
|
| 255 |
+
def decorator(func):
|
| 256 |
+
# Для методов класса используем обертку
|
| 257 |
+
@wraps(func)
|
| 258 |
+
def wrapper(*args, **kwargs):
|
| 259 |
+
# Создаем временную функцию для spaces.GPU
|
| 260 |
+
@spaces.GPU(duration=kwargs.get('duration', 180))
|
| 261 |
+
def gpu_wrapper():
|
| 262 |
+
return func(*args, **kwargs)
|
| 263 |
+
return gpu_wrapper()
|
| 264 |
+
return wrapper
|
| 265 |
+
return decorator(*args, **kwargs) if args and callable(args[0]) else decorator
|
| 266 |
else:
|
| 267 |
def hf_spaces_gpu(*args, **kwargs):
|
| 268 |
if len(args) == 1 and callable(args[0]):
|