Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image, ImageEnhance
|
| 3 |
-
import numpy as np
|
| 4 |
|
| 5 |
-
# Fonction pour modifier les couleurs de l'image
|
| 6 |
def modify_image_color(image):
|
| 7 |
-
# Convertir l'image PIL en format RGB
|
| 8 |
img = image.convert("RGB")
|
| 9 |
-
|
| 10 |
-
# Augmenter la saturation de l'image
|
| 11 |
enhancer = ImageEnhance.Color(img)
|
| 12 |
-
img = enhancer.enhance(2) #
|
| 13 |
-
|
| 14 |
return img
|
| 15 |
|
| 16 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
iface = gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
-
inputs=gr.Image(type="pil", label="Télécharger une image"), #
|
| 20 |
-
outputs=
|
| 21 |
-
title="Modification
|
| 22 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# Lancer l'interface
|
| 26 |
iface.launch()
|
| 27 |
-
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
+
from PIL import Image, ImageEnhance, ImageOps
|
|
|
|
| 4 |
|
| 5 |
+
# Fonction pour modifier les couleurs de l'image (ajouter de la saturation)
|
| 6 |
def modify_image_color(image):
|
|
|
|
| 7 |
img = image.convert("RGB")
|
|
|
|
|
|
|
| 8 |
enhancer = ImageEnhance.Color(img)
|
| 9 |
+
img = enhancer.enhance(2) # Augmente la saturation
|
|
|
|
| 10 |
return img
|
| 11 |
|
| 12 |
+
# Fonction pour convertir l'image en noir et blanc
|
| 13 |
+
def convert_to_black_and_white(image):
|
| 14 |
+
return ImageOps.grayscale(image)
|
| 15 |
+
|
| 16 |
+
# Interface Gradio avec plusieurs fonctionnalités
|
| 17 |
iface = gr.Interface(
|
| 18 |
+
fn=None, # La fonction principale sera None ici
|
| 19 |
+
inputs=gr.Image(type="pil", label="Télécharger une image"), # Télécharger une image
|
| 20 |
+
outputs="image", # Sortie image
|
| 21 |
+
title="Modification d'image",
|
| 22 |
+
description="Choisissez une option ci-dessous pour modifier l'image.",
|
| 23 |
+
live=True, # Permet d'avoir des mises à jour en temps réel
|
| 24 |
+
layout="vertical", # Disposition verticale des composants
|
| 25 |
+
|
| 26 |
+
# Composants supplémentaires pour chaque fonctionnalité
|
| 27 |
+
examples=[["image1.jpg"], ["image2.jpg"]], # Exemples d'images
|
| 28 |
+
allow_flagging="never" # Désactive le flagging (optionnelle)
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Ajout de plusieurs options avec des boutons pour activer chaque fonction
|
| 32 |
+
iface.add_component(
|
| 33 |
+
gr.Button("Augmenter la saturation", elem_id="saturation_button").click(modify_image_color, inputs="image", outputs="image")
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
iface.add_component(
|
| 37 |
+
gr.Button("Convertir en noir et blanc", elem_id="bw_button").click(convert_to_black_and_white, inputs="image", outputs="image")
|
| 38 |
)
|
| 39 |
|
| 40 |
# Lancer l'interface
|
| 41 |
iface.launch()
|
|
|