Spaces:
Runtime error
Runtime error
| 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) |