File size: 1,167 Bytes
28f9e35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import gradio as gr
from segmentation import segment_image
import numpy as np
import cv2
# Image de test par défaut
default_image_path = "./image.png"
def segment_and_display(image_path=default_image_path):
# Appeler la fonction de segmentation
original_image, segmented_image = segment_image(image_path)
# Retourner les images pour l'affichage
return original_image, segmented_image
# Charger l'image de test par défaut
default_original_image, default_segmented_image = segment_image(default_image_path)
# Interface Gradio
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 # Permet de voir les changements en temps réel
)
# Afficher l'image de test par défaut lorsque l'interface est ouverte
iface.launch(share=True, inline=True) |