Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import cv2 | |
| from geti_sdk.deployment import Deployment | |
| from geti_sdk.utils import show_image_with_annotation_scene | |
| #Load models | |
| deployment = Deployment.from_folder("deployments") | |
| deployment.load_inference_models(device="CPU") | |
| def resize_image(image, target_dimension): | |
| height, width = image.shape[:2] | |
| max_dimension = max(height, width) | |
| scale_factor = target_dimension / max_dimension | |
| new_width = int(width * scale_factor) | |
| new_height = int(height * scale_factor) | |
| resized_image = cv2.resize(image, (new_width, new_height)) | |
| return resized_image | |
| def infer(image): | |
| if image is None: | |
| return None, 'Error: No image provided' | |
| image = resize_image(image, 1200) | |
| image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
| prediction = deployment.infer(image_rgb) | |
| output = show_image_with_annotation_scene(image, prediction, show_results=False) | |
| output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB) | |
| return output, prediction.overview | |
| demo = gr.Interface( | |
| fn=infer, | |
| inputs="image", | |
| outputs=["image", "text"], | |
| allow_flagging='manual', | |
| flagging_dir='flagged', | |
| examples=[["eggsample1.jpg"], ["eggsample2.jpg"]] | |
| ) | |
| demo.launch() |