Spaces:
Sleeping
Sleeping
Commit
·
e65263a
1
Parent(s):
6c6688f
Update app.py
Browse files
app.py
CHANGED
@@ -7,30 +7,35 @@ from geti_sdk.utils import show_image_with_annotation_scene
|
|
7 |
deployment = Deployment.from_folder("deployment")
|
8 |
deployment.load_inference_models(device="CPU")
|
9 |
|
10 |
-
|
|
|
11 |
height, width = image.shape[:2]
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
new_width = int(width * (max_dimension / height))
|
17 |
-
else:
|
18 |
-
new_width = max_dimension
|
19 |
-
new_height = int(height * (max_dimension / width))
|
20 |
resized_image = cv2.resize(image, (new_width, new_height))
|
21 |
return resized_image
|
22 |
|
|
|
23 |
def infer(image=None):
|
24 |
if image is None:
|
25 |
-
return None
|
|
|
|
|
|
|
26 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
27 |
prediction = deployment.infer(image)
|
28 |
output = show_image_with_annotation_scene(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), prediction, show_results=False)
|
29 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
30 |
-
|
31 |
-
return output
|
32 |
|
33 |
-
|
|
|
34 |
inputs='image',
|
35 |
-
outputs='image',
|
36 |
-
|
|
|
|
|
|
|
|
|
|
7 |
deployment = Deployment.from_folder("deployment")
|
8 |
deployment.load_inference_models(device="CPU")
|
9 |
|
10 |
+
|
11 |
+
def resize_image(image, target_dimension):
|
12 |
height, width = image.shape[:2]
|
13 |
+
max_dimension = max(height, width)
|
14 |
+
scale_factor = target_dimension / max_dimension
|
15 |
+
new_width = int(width * scale_factor)
|
16 |
+
new_height = int(height * scale_factor)
|
|
|
|
|
|
|
|
|
17 |
resized_image = cv2.resize(image, (new_width, new_height))
|
18 |
return resized_image
|
19 |
|
20 |
+
|
21 |
def infer(image=None):
|
22 |
if image is None:
|
23 |
+
return [None,'no image']
|
24 |
+
|
25 |
+
image = resize_image(image, 1200)
|
26 |
+
|
27 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
28 |
prediction = deployment.infer(image)
|
29 |
output = show_image_with_annotation_scene(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), prediction, show_results=False)
|
30 |
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
|
31 |
+
return [output, prediction.overview]
|
|
|
32 |
|
33 |
+
|
34 |
+
interface = gr.Interface(fn=infer,
|
35 |
inputs='image',
|
36 |
+
outputs=['image','text'],
|
37 |
+
allow_flagging='manual',
|
38 |
+
flagging_dir='flagged',
|
39 |
+
examples=["eggsample1.png", "eggsample2.png"])
|
40 |
+
|
41 |
+
interface.launch()
|