| | import gradio as gr |
| | from segmentation import segment_image |
| | import numpy as np |
| | import cv2 |
| |
|
| | |
| | default_image_path = "./image.png" |
| |
|
| | def segment_and_display(image_path=default_image_path): |
| | |
| | original_image, segmented_image = segment_image(image_path) |
| | |
| | |
| | return original_image, segmented_image |
| |
|
| | |
| | default_original_image, default_segmented_image = segment_image(default_image_path) |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=segment_and_display, |
| | inputs=gr.Image(type="filepath", label="Upload Image"), |
| | outputs=[ |
| | gr.Image(type="numpy", label="Original Image"), |
| | gr.Image(type="numpy", label="Segmented Image") |
| | ], |
| | title="Image Segmentation with K-means (k=2)", |
| | description="Upload an image or use the default test image to see the segmentation result.", |
| | examples=[ |
| | [default_image_path] |
| | ], |
| | live=True |
| | ) |
| |
|
| | |
| | iface.launch(share=True, inline=True) |