Alovestocode commited on
Commit
abe3cd7
·
verified ·
1 Parent(s): e551bf6

Use spaces.GPU decorator

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-313.pyc +0 -0
  2. app.py +5 -10
__pycache__/app.cpython-313.pyc CHANGED
Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ
 
app.py CHANGED
@@ -70,16 +70,16 @@ class GenerateResponse(BaseModel):
70
 
71
  _MODEL = None
72
 
73
-
74
- def _spaces_gpu(*args, **kwargs):
75
- if spaces is None:
76
  def identity(fn):
77
  return fn
78
  return identity
79
- return spaces.GPU(*args, **kwargs)
 
80
 
81
 
82
- @_spaces_gpu(duration=120)
83
  def get_model() -> AutoModelForCausalLM:
84
  global _MODEL
85
  if _MODEL is None:
@@ -136,11 +136,6 @@ def _generate(
136
  fastapi_app = FastAPI(title="Router Model API", version="1.0.0")
137
 
138
 
139
- @fastapi_app.get("/")
140
- def healthcheck() -> dict[str, str]:
141
- return {"status": "ok", "model": MODEL_ID}
142
-
143
-
144
  @fastapi_app.get("/")
145
  def healthcheck() -> dict[str, str]:
146
  return {"status": "ok", "model": MODEL_ID}
 
70
 
71
  _MODEL = None
72
 
73
+ if spaces is None: # pragma: no cover - local testing path
74
+ def gpu_decorator(*args, **kwargs): # type: ignore
 
75
  def identity(fn):
76
  return fn
77
  return identity
78
+ else:
79
+ gpu_decorator = spaces.GPU
80
 
81
 
82
+ @gpu_decorator(duration=120)
83
  def get_model() -> AutoModelForCausalLM:
84
  global _MODEL
85
  if _MODEL is None:
 
136
  fastapi_app = FastAPI(title="Router Model API", version="1.0.0")
137
 
138
 
 
 
 
 
 
139
  @fastapi_app.get("/")
140
  def healthcheck() -> dict[str, str]:
141
  return {"status": "ok", "model": MODEL_ID}