Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,29 +15,25 @@ def process_uploaded_image(uploaded_file):
|
|
| 15 |
pixel_data = np.array(image)
|
| 16 |
return pixel_data
|
| 17 |
|
| 18 |
-
# Fonction pour générer une image
|
| 19 |
-
def
|
| 20 |
width, height = 300, 300
|
| 21 |
generated_image = np.zeros((height, width, 3), dtype=np.uint8)
|
| 22 |
|
| 23 |
-
# Parcourir les pixels pour générer l'image
|
| 24 |
for i in range(height):
|
| 25 |
for j in range(width):
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
else:
|
| 33 |
-
# Premier pixel arbitraire
|
| 34 |
-
avg_pixel = base_pixels[i, j]
|
| 35 |
|
| 36 |
-
# Éviter les
|
| 37 |
if avoid_data and (i, j) in avoid_data:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
generated_image[i, j] =
|
| 41 |
|
| 42 |
return Image.fromarray(generated_image)
|
| 43 |
|
|
@@ -57,7 +53,7 @@ if uploaded_file:
|
|
| 57 |
# Choisir l'animal et générer une nouvelle image basée sur cette référence
|
| 58 |
animal = st.selectbox("Sélectionnez un animal :", ["chat", "chien", "cheval"])
|
| 59 |
if st.button("Générer une image"):
|
| 60 |
-
generated_image =
|
| 61 |
st.image(generated_image, caption=f"Image générée pour un {animal}", use_column_width=True)
|
| 62 |
|
| 63 |
# Options de validation de l'image générée
|
|
|
|
| 15 |
pixel_data = np.array(image)
|
| 16 |
return pixel_data
|
| 17 |
|
| 18 |
+
# Fonction pour générer une image avec variations basées sur les pixels environnants
|
| 19 |
+
def generate_image_with_variation(base_pixels, label, avoid_data=None):
|
| 20 |
width, height = 300, 300
|
| 21 |
generated_image = np.zeros((height, width, 3), dtype=np.uint8)
|
| 22 |
|
|
|
|
| 23 |
for i in range(height):
|
| 24 |
for j in range(width):
|
| 25 |
+
# Utiliser le pixel de référence et ajouter des variations aléatoires
|
| 26 |
+
base_pixel = base_pixels[i, j]
|
| 27 |
+
|
| 28 |
+
# Ajouter une variation aléatoire aux composants RGB
|
| 29 |
+
variation = np.array([random.randint(-20, 20) for _ in range(3)])
|
| 30 |
+
new_pixel = np.clip(base_pixel + variation, 0, 255)
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Éviter les combinaisons déjà marquées comme erreur
|
| 33 |
if avoid_data and (i, j) in avoid_data:
|
| 34 |
+
new_pixel = (new_pixel + np.array([random.randint(0, 50) for _ in range(3)])) % 255
|
| 35 |
+
|
| 36 |
+
generated_image[i, j] = new_pixel
|
| 37 |
|
| 38 |
return Image.fromarray(generated_image)
|
| 39 |
|
|
|
|
| 53 |
# Choisir l'animal et générer une nouvelle image basée sur cette référence
|
| 54 |
animal = st.selectbox("Sélectionnez un animal :", ["chat", "chien", "cheval"])
|
| 55 |
if st.button("Générer une image"):
|
| 56 |
+
generated_image = generate_image_with_variation(base_pixels, animal, avoid_data=error_data.get(animal))
|
| 57 |
st.image(generated_image, caption=f"Image générée pour un {animal}", use_column_width=True)
|
| 58 |
|
| 59 |
# Options de validation de l'image générée
|