Spaces:
Runtime error
Runtime error
polejowska
commited on
Commit
•
f5a0872
1
Parent(s):
4b92437
Update app.py
Browse files
app.py
CHANGED
@@ -26,11 +26,9 @@ def make_prediction(img, feature_extractor, model):
|
|
26 |
)
|
27 |
|
28 |
|
29 |
-
def detect_objects(model_name, image_input, threshold, display_mask=False):
|
30 |
feature_extractor = AutoFeatureExtractor.from_pretrained(MODELS_REPO[model_name])
|
31 |
|
32 |
-
print(image_input.value)
|
33 |
-
|
34 |
if "DETR" in model_name:
|
35 |
model = DetrForObjectDetection.from_pretrained(MODELS_REPO[model_name])
|
36 |
model_details = "DETR details"
|
@@ -44,8 +42,6 @@ def detect_objects(model_name, image_input, threshold, display_mask=False):
|
|
44 |
|
45 |
mask_pil_image = None
|
46 |
if display_mask:
|
47 |
-
# get image path
|
48 |
-
image_path = pathlib.Path(image_input.value)
|
49 |
mask_path = image_path.parent / (
|
50 |
image_path.stem.replace("_HE", "_mask") + image_path.suffix
|
51 |
)
|
@@ -71,11 +67,9 @@ def detect_objects(model_name, image_input, threshold, display_mask=False):
|
|
71 |
)
|
72 |
|
73 |
|
74 |
-
def set_example_image(example: list)
|
75 |
-
|
76 |
-
|
77 |
-
print(gr.Image.update(value=example[0]))
|
78 |
-
return gr.Image.update(value=example[0])
|
79 |
|
80 |
|
81 |
with gr.Blocks(css=css) as app:
|
@@ -136,7 +130,7 @@ with gr.Blocks(css=css) as app:
|
|
136 |
|
137 |
detect_button.click(
|
138 |
detect_objects,
|
139 |
-
inputs=[options, img_input, slider_input, display_mask],
|
140 |
outputs=[
|
141 |
img_output_from_upload,
|
142 |
decoder_att_map_output,
|
@@ -147,8 +141,7 @@ with gr.Blocks(css=css) as app:
|
|
147 |
queue=True,
|
148 |
)
|
149 |
example_images.click(
|
150 |
-
fn=set_example_image, inputs=[example_images], outputs=[img_input]
|
151 |
)
|
152 |
|
153 |
app.launch(enable_queue=True)
|
154 |
-
|
|
|
26 |
)
|
27 |
|
28 |
|
29 |
+
def detect_objects(model_name, image_input, image_path, threshold, display_mask=False):
|
30 |
feature_extractor = AutoFeatureExtractor.from_pretrained(MODELS_REPO[model_name])
|
31 |
|
|
|
|
|
32 |
if "DETR" in model_name:
|
33 |
model = DetrForObjectDetection.from_pretrained(MODELS_REPO[model_name])
|
34 |
model_details = "DETR details"
|
|
|
42 |
|
43 |
mask_pil_image = None
|
44 |
if display_mask:
|
|
|
|
|
45 |
mask_path = image_path.parent / (
|
46 |
image_path.stem.replace("_HE", "_mask") + image_path.suffix
|
47 |
)
|
|
|
67 |
)
|
68 |
|
69 |
|
70 |
+
def set_example_image(example: list):
|
71 |
+
img_path = example[0]
|
72 |
+
return gr.Image.update(value=example[0]), img_path
|
|
|
|
|
73 |
|
74 |
|
75 |
with gr.Blocks(css=css) as app:
|
|
|
130 |
|
131 |
detect_button.click(
|
132 |
detect_objects,
|
133 |
+
inputs=[options, img_input, img_path, slider_input, display_mask],
|
134 |
outputs=[
|
135 |
img_output_from_upload,
|
136 |
decoder_att_map_output,
|
|
|
141 |
queue=True,
|
142 |
)
|
143 |
example_images.click(
|
144 |
+
fn=set_example_image, inputs=[example_images], outputs=[img_input, img_path]
|
145 |
)
|
146 |
|
147 |
app.launch(enable_queue=True)
|
|