Spaces:
Build error
Build error
| import gradio as gr | |
| from PIL import Image | |
| import numpy as np | |
| import cv2 | |
| # Fonction pour charger et afficher l'image | |
| def load_image(image): | |
| return image | |
| # Fonction pour appliquer un négatif | |
| def apply_negative(image): | |
| img_np = np.array(image) | |
| negative = 255 - img_np | |
| return Image.fromarray(negative) | |
| # Fonction pour binariser une image | |
| def binarize_image(image, threshold): | |
| img_np = np.array(image.convert('L')) # Convertir en niveaux de gris | |
| _, binary = cv2.threshold(img_np, threshold, 255, cv2.THRESH_BINARY) | |
| return Image.fromarray(binary) | |
| # Interface Gradio | |
| def image_processing(image, operation, threshold=128): | |
| if operation == "Négatif": | |
| return apply_negative(image) | |
| elif operation == "Binarisation": | |
| return binarize_image(image, threshold) | |
| return image | |
| # Interface Gradio | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Projet de Traitement d'Image") | |
| with gr.Row(): | |
| image_input = gr.Image(type="pil", label="Charger Image") | |
| operation = gr.Radio(["Négatif", "Binarisation"], label="Opération à effectuer", value="Négatif") | |
| threshold = gr.Slider(0, 255, 128, label="Seuil de binarisation", visible=False) | |
| image_output = gr.Image(label="Image Modifiée") | |
| def update_threshold(operation): | |
| if operation == "Binarisation": | |
| return gr.update(visible=True) | |
| return gr.update(visible=False) | |
| operation.change(update_threshold, inputs=operation, outputs=threshold) | |
| submit_button = gr.Button("Appliquer") | |
| submit_button.click(image_processing, inputs=[image_input, operation, threshold], outputs=image_output) | |
| # Lancer l'application Gradio | |
| demo.launch() | |