Darius Morawiec commited on
Commit
ab7fdea
·
1 Parent(s): 0bbf47d

Enhance GPU decorator to accept duration parameter for better control

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -23,11 +23,16 @@ else:
23
 
24
  class spaces:
25
  @staticmethod
26
- def GPU(func):
27
- def wrapper(*args, **kwargs):
28
- return func(*args, **kwargs)
 
29
 
30
- return wrapper
 
 
 
 
31
 
32
 
33
  # Define constants
@@ -252,7 +257,7 @@ with gr.Blocks() as demo:
252
 
253
  return current_model, current_processor
254
 
255
- @spaces.GPU
256
  def generate(
257
  model,
258
  processor,
 
23
 
24
  class spaces:
25
  @staticmethod
26
+ def GPU(func=None, duration=300):
27
+ def decorator(f):
28
+ def wrapper(*args, **kwargs):
29
+ return f(*args, **kwargs)
30
 
31
+ return wrapper
32
+
33
+ if func is None:
34
+ return decorator
35
+ return decorator(func)
36
 
37
 
38
  # Define constants
 
257
 
258
  return current_model, current_processor
259
 
260
+ @spaces.GPU(duration=300)
261
  def generate(
262
  model,
263
  processor,