Spaces:
Running
Running
Commit
·
fb2817b
1
Parent(s):
b7ff10f
lazy load model
Browse files
app.py
CHANGED
|
@@ -50,16 +50,15 @@ h1 {
|
|
| 50 |
|
| 51 |
rng = np.random.default_rng(0xDEADBEEF)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
def load_ahoy() -> AHOY:
|
| 55 |
-
"""Load and warmup the model."""
|
| 56 |
-
model = load_model("ahoy-RGB-b2")
|
| 57 |
-
return model
|
| 58 |
-
|
| 59 |
|
| 60 |
@spaces.GPU
|
| 61 |
-
def inference(
|
| 62 |
"""Run inference on image and return annotated image."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
results = model(image)
|
| 64 |
return results.draw(image, diameter=4)
|
| 65 |
|
|
@@ -110,7 +109,7 @@ with gr.Blocks(theme=theme, css=css, title="SEA.AI Vision Demo") as demo:
|
|
| 110 |
# event listeners
|
| 111 |
img_url.change(load_image_from_url, [img_url], img_input)
|
| 112 |
submit.click(check_image, [img_input], None, show_api=False).success(
|
| 113 |
-
|
| 114 |
[img_input],
|
| 115 |
img_output,
|
| 116 |
api_name="inference",
|
|
|
|
| 50 |
|
| 51 |
rng = np.random.default_rng(0xDEADBEEF)
|
| 52 |
|
| 53 |
+
model: AHOY = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
@spaces.GPU
|
| 56 |
+
def inference(image):
|
| 57 |
"""Run inference on image and return annotated image."""
|
| 58 |
+
global model
|
| 59 |
+
if model is None:
|
| 60 |
+
# lazy load model
|
| 61 |
+
model = load_model("ahoy-RGB-b2")
|
| 62 |
results = model(image)
|
| 63 |
return results.draw(image, diameter=4)
|
| 64 |
|
|
|
|
| 109 |
# event listeners
|
| 110 |
img_url.change(load_image_from_url, [img_url], img_input)
|
| 111 |
submit.click(check_image, [img_input], None, show_api=False).success(
|
| 112 |
+
inference,
|
| 113 |
[img_input],
|
| 114 |
img_output,
|
| 115 |
api_name="inference",
|