Spaces:
Sleeping
Sleeping
Commit
·
6bd0d8c
1
Parent(s):
7b7636a
Add development mode for mocking model initialization and prediction functions
Browse files
main.py
CHANGED
@@ -24,6 +24,8 @@ from utilities.arguments import load_opt_from_config_files
|
|
24 |
from utilities.constants import BIOMED_CLASSES
|
25 |
from inference_utils.inference import interactive_infer_image
|
26 |
|
|
|
|
|
27 |
|
28 |
gr.set_static_paths(["assets"])
|
29 |
|
@@ -76,7 +78,7 @@ def run():
|
|
76 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
77 |
|
78 |
|
79 |
-
def
|
80 |
# Download model
|
81 |
model_file = hf_hub_download(
|
82 |
repo_id="microsoft/BiomedParse",
|
@@ -98,7 +100,11 @@ def init_model():
|
|
98 |
return model
|
99 |
|
100 |
|
101 |
-
def
|
|
|
|
|
|
|
|
|
102 |
if not prompts:
|
103 |
return None
|
104 |
|
@@ -121,6 +127,17 @@ def predict(image, prompts):
|
|
121 |
return pred_overlay
|
122 |
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
description = """Upload a biomedical image and enter prompts (separated by commas) to detect specific features.
|
125 |
|
126 |
The model understands these prompts:
|
|
|
24 |
from utilities.constants import BIOMED_CLASSES
|
25 |
from inference_utils.inference import interactive_infer_image
|
26 |
|
27 |
+
# If True, then mock init_model() and predict() functions will be used.
|
28 |
+
DEV_MODE = True
|
29 |
|
30 |
gr.set_static_paths(["assets"])
|
31 |
|
|
|
78 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
79 |
|
80 |
|
81 |
+
def init_model_prod():
|
82 |
# Download model
|
83 |
model_file = hf_hub_download(
|
84 |
repo_id="microsoft/BiomedParse",
|
|
|
100 |
return model
|
101 |
|
102 |
|
103 |
+
def init_model_dev():
|
104 |
+
return None
|
105 |
+
|
106 |
+
|
107 |
+
def predict_prod(image: gr.Image, prompts: str):
|
108 |
if not prompts:
|
109 |
return None
|
110 |
|
|
|
127 |
return pred_overlay
|
128 |
|
129 |
|
130 |
+
def predict_dev(image: gr.Image, prompts: str):
|
131 |
+
return image
|
132 |
+
|
133 |
+
|
134 |
+
if DEV_MODE:
|
135 |
+
init_model = init_model_dev
|
136 |
+
predict = predict_dev
|
137 |
+
else:
|
138 |
+
init_model = init_model_prod
|
139 |
+
predict = predict_prod
|
140 |
+
|
141 |
description = """Upload a biomedical image and enter prompts (separated by commas) to detect specific features.
|
142 |
|
143 |
The model understands these prompts:
|