s-egg-mentation / app.py
oliver9523's picture
Update app.py
0d798b8
raw
history blame
1.26 kB
import gradio as gr
import cv2
from geti_sdk.deployment import Deployment
from geti_sdk.utils import show_image_with_annotation_scene
# Step 1: Load the deployment
deployment = Deployment.from_folder("deployment")
deployment.load_inference_models(device="CPU")
def resize_image(image, max_dimension):
height, width = image.shape[:2]
if max(height, width) <= max_dimension:
return image
if height > width:
new_height = max_dimension
new_width = int(width * (max_dimension / height))
else:
new_width = max_dimension
new_height = int(height * (max_dimension / width))
resized_image = cv2.resize(image, (new_width, new_height))
return resized_image
def infer(image=None):
if image is None:
return None
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
prediction = deployment.infer(image)
output = show_image_with_annotation_scene(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), prediction, show_results=False)
output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
# output = cv2.resize(output, (224, 224))
return output
gr.Interface(fn=infer,
inputs='image',
outputs='image',
examples=["eggsample1.png", "eggsample2.png"]).launch()