Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ def generate_qrcode(link):
|
|
| 32 |
qr.make(fit=True)
|
| 33 |
qr_image = qr.make_image(fill_color="black", back_color="white")
|
| 34 |
|
| 35 |
-
small_qr_image = qr_image.resize((
|
| 36 |
|
| 37 |
buffer = BytesIO()
|
| 38 |
small_qr_image.save(buffer, format="PNG")
|
|
@@ -162,12 +162,12 @@ def main():
|
|
| 162 |
["Accueil", "Transformations d'image", "Cropping", "Rotation", "Floutage", "Contours", "Génération de Code-barres et QR Code", "Détection Faciale"],
|
| 163 |
format_func=lambda x: {
|
| 164 |
"Accueil": "🏠 Accueil",
|
| 165 |
-
"Transformations d'image": "🖼️
|
| 166 |
"Cropping": "✂️ Cropping",
|
| 167 |
"Rotation": "🔄 Rotation",
|
| 168 |
"Floutage": "🌫️ Floutage",
|
| 169 |
"Contours": "🔍 Contours",
|
| 170 |
-
"Génération de Code-barres et QR Code": "📇 Codes",
|
| 171 |
"Détection Faciale": "🙂 Détection Faciale"
|
| 172 |
}.get(x, x)
|
| 173 |
)
|
|
@@ -180,8 +180,7 @@ def main():
|
|
| 180 |
"""
|
| 181 |
<div class="stMarkdown">
|
| 182 |
<h2>ADS VISOR est une application innovante pour analyser, transformer et explorer vos images. 🖼️✨</h2>
|
| 183 |
-
<p>
|
| 184 |
-
<p>Que vous soyez un professionnel ou un passionné, découvrez un large éventail de fonctionnalités interactives !</p>
|
| 185 |
<ul>
|
| 186 |
<li><b>Transformations d'image :</b> Couleurs, niveaux de gris, etc.</li>
|
| 187 |
<li><b>Découpage & Rotation :</b> Ajustez vos images à la perfection.</li>
|
|
@@ -213,30 +212,86 @@ def main():
|
|
| 213 |
])
|
| 214 |
|
| 215 |
with tab1:
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
with tab2:
|
| 218 |
red = image_np.copy()
|
| 219 |
red[:, :, 1:] = 0
|
| 220 |
st.image(red, caption="Image Rouge", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
with tab3:
|
| 222 |
green = image_np.copy()
|
| 223 |
green[:, :, [0, 2]] = 0
|
| 224 |
st.image(green, caption="Image Verte", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
with tab4:
|
| 226 |
yellow = image_np.copy()
|
| 227 |
yellow[:, :, 0] = 0
|
| 228 |
st.image(yellow, caption="Image Jaune", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
elif menu_option == "Cropping":
|
| 231 |
st.subheader("Cropping")
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
elif menu_option == "Rotation":
|
| 242 |
st.subheader("Rotation")
|
|
@@ -247,6 +302,14 @@ def main():
|
|
| 247 |
rotation_matrix = cv2.getRotationMatrix2D((cols / 2, rows / 2), angle, 1)
|
| 248 |
rotated = cv2.warpAffine(image_np, rotation_matrix, (cols, rows))
|
| 249 |
st.image(rotated, caption=f"Image Rotée de {angle} degrés", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
elif menu_option == "Floutage":
|
| 252 |
st.subheader("Floutage")
|
|
@@ -254,6 +317,14 @@ def main():
|
|
| 254 |
blur_level = st.slider("Niveau de flou (k)", min_value=1, max_value=51, step=2, value=15)
|
| 255 |
blurred = cv2.GaussianBlur(image_np, (blur_level, blur_level), 0)
|
| 256 |
st.image(blurred, caption=f"Image Floutée (k={blur_level})", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
elif menu_option == "Contours":
|
| 259 |
st.subheader("Contours")
|
|
@@ -261,18 +332,61 @@ def main():
|
|
| 261 |
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
|
| 262 |
edges = cv2.Canny(gray, 100, 200)
|
| 263 |
st.image(edges, caption="Contours de l'Image", use_container_width=True)
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
elif menu_option == "Génération de Code-barres et QR Code":
|
| 266 |
st.subheader("Génération de Code-barres et QR Code")
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
elif menu_option == "Détection Faciale":
|
| 278 |
st.subheader("Détection Faciale")
|
|
|
|
| 32 |
qr.make(fit=True)
|
| 33 |
qr_image = qr.make_image(fill_color="black", back_color="white")
|
| 34 |
|
| 35 |
+
small_qr_image = qr_image.resize((512, 512), Image.Resampling.LANCZOS)
|
| 36 |
|
| 37 |
buffer = BytesIO()
|
| 38 |
small_qr_image.save(buffer, format="PNG")
|
|
|
|
| 162 |
["Accueil", "Transformations d'image", "Cropping", "Rotation", "Floutage", "Contours", "Génération de Code-barres et QR Code", "Détection Faciale"],
|
| 163 |
format_func=lambda x: {
|
| 164 |
"Accueil": "🏠 Accueil",
|
| 165 |
+
"Transformations d'image": "🖼️ Niveaux de couleurs",
|
| 166 |
"Cropping": "✂️ Cropping",
|
| 167 |
"Rotation": "🔄 Rotation",
|
| 168 |
"Floutage": "🌫️ Floutage",
|
| 169 |
"Contours": "🔍 Contours",
|
| 170 |
+
"Génération de Code-barres et QR Code": "📇 Codes numériques",
|
| 171 |
"Détection Faciale": "🙂 Détection Faciale"
|
| 172 |
}.get(x, x)
|
| 173 |
)
|
|
|
|
| 180 |
"""
|
| 181 |
<div class="stMarkdown">
|
| 182 |
<h2>ADS VISOR est une application innovante pour analyser, transformer et explorer vos images. 🖼️✨</h2>
|
| 183 |
+
<p>Que vous soyez un professionnel ou un passionné, découvrez un large éventail de fonctionnalités interactives !</p>
|
|
|
|
| 184 |
<ul>
|
| 185 |
<li><b>Transformations d'image :</b> Couleurs, niveaux de gris, etc.</li>
|
| 186 |
<li><b>Découpage & Rotation :</b> Ajustez vos images à la perfection.</li>
|
|
|
|
| 212 |
])
|
| 213 |
|
| 214 |
with tab1:
|
| 215 |
+
gray_image = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
|
| 216 |
+
st.image(gray_image, caption="Image en Niveaux de Gris", use_container_width=True)
|
| 217 |
+
st.download_button(
|
| 218 |
+
label="Télécharger l'image en gris",
|
| 219 |
+
data=image_to_bytes(gray_image),
|
| 220 |
+
file_name="image_gris.png",
|
| 221 |
+
mime="image/png"
|
| 222 |
+
)
|
| 223 |
with tab2:
|
| 224 |
red = image_np.copy()
|
| 225 |
red[:, :, 1:] = 0
|
| 226 |
st.image(red, caption="Image Rouge", use_container_width=True)
|
| 227 |
+
st.download_button(
|
| 228 |
+
label="Télécharger l'image rouge",
|
| 229 |
+
data=image_to_bytes(red),
|
| 230 |
+
file_name="image_rouge.png",
|
| 231 |
+
mime="image/png"
|
| 232 |
+
)
|
| 233 |
with tab3:
|
| 234 |
green = image_np.copy()
|
| 235 |
green[:, :, [0, 2]] = 0
|
| 236 |
st.image(green, caption="Image Verte", use_container_width=True)
|
| 237 |
+
st.download_button(
|
| 238 |
+
label="Télécharger l'image verte",
|
| 239 |
+
data=image_to_bytes(green),
|
| 240 |
+
file_name="image_verte.png",
|
| 241 |
+
mime="image/png"
|
| 242 |
+
)
|
| 243 |
with tab4:
|
| 244 |
yellow = image_np.copy()
|
| 245 |
yellow[:, :, 0] = 0
|
| 246 |
st.image(yellow, caption="Image Jaune", use_container_width=True)
|
| 247 |
+
st.download_button(
|
| 248 |
+
label="Télécharger l'image jaune",
|
| 249 |
+
data=image_to_bytes(yellow),
|
| 250 |
+
file_name="image_jaune.png",
|
| 251 |
+
mime="image/png"
|
| 252 |
+
)
|
| 253 |
|
| 254 |
elif menu_option == "Cropping":
|
| 255 |
st.subheader("Cropping")
|
| 256 |
|
| 257 |
+
# Explications pour les paramètres
|
| 258 |
+
st.markdown(
|
| 259 |
+
"""
|
| 260 |
+
### Légende : Fonctionnement du recadrage
|
| 261 |
+
- **`x1` (Coordonnée x du coin supérieur gauche)** : Position horizontale du début du rectangle (0 ≤ `x1` < largeur-1).
|
| 262 |
+
- **`y1` (Coordonnée y du coin supérieur gauche)** : Position verticale du début du rectangle (0 ≤ `y1` < hauteur-1).
|
| 263 |
+
- **`x2` (Coordonnée x du coin inférieur droit)** : Position horizontale de la fin du rectangle (1 ≤ `x2` ≤ largeur).
|
| 264 |
+
- **`y2` (Coordonnée y du coin inférieur droit)** : Position verticale de la fin du rectangle (1 ≤ `y2` ≤ hauteur).
|
| 265 |
+
"""
|
| 266 |
+
)
|
| 267 |
|
| 268 |
+
# Entrée des coordonnées
|
| 269 |
+
try:
|
| 270 |
+
x1 = st.number_input("x1 (Coordonnée x du coin supérieur gauche)", 0, image_np.shape[1] - 1, step=1)
|
| 271 |
+
y1 = st.number_input("y1 (Coordonnée y du coin supérieur gauche)", 0, image_np.shape[0] - 1, step=1)
|
| 272 |
+
x2 = st.number_input("x2 (Coordonnée x du coin inférieur droit)", 1, image_np.shape[1], step=1)
|
| 273 |
+
y2 = st.number_input("y2 (Coordonnée y du coin inférieur droit)", 1, image_np.shape[0], step=1)
|
| 274 |
+
|
| 275 |
+
# Validation des coordonnées
|
| 276 |
+
if x1 >= x2:
|
| 277 |
+
st.error("`x2` doit être strictement supérieur à `x1`. Veuillez corriger vos entrées.")
|
| 278 |
+
elif y1 >= y2:
|
| 279 |
+
st.error("`y2` doit être strictement supérieur à `y1`. Veuillez corriger vos entrées.")
|
| 280 |
+
else:
|
| 281 |
+
# Recadrage de l'image
|
| 282 |
+
cropped = image_np[int(y1):int(y2), int(x1):int(x2)]
|
| 283 |
+
st.image(cropped, caption="Image Croppée", use_container_width=True)
|
| 284 |
+
|
| 285 |
+
# Bouton de téléchargement
|
| 286 |
+
st.download_button(
|
| 287 |
+
label="Télécharger l'image croppée",
|
| 288 |
+
data=image_to_bytes(cropped),
|
| 289 |
+
file_name="image_cropped.png",
|
| 290 |
+
mime="image/png"
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
except Exception as e:
|
| 294 |
+
st.error(f"Une erreur est survenue : {e}")
|
| 295 |
|
| 296 |
elif menu_option == "Rotation":
|
| 297 |
st.subheader("Rotation")
|
|
|
|
| 302 |
rotation_matrix = cv2.getRotationMatrix2D((cols / 2, rows / 2), angle, 1)
|
| 303 |
rotated = cv2.warpAffine(image_np, rotation_matrix, (cols, rows))
|
| 304 |
st.image(rotated, caption=f"Image Rotée de {angle} degrés", use_container_width=True)
|
| 305 |
+
|
| 306 |
+
# Bouton de téléchargement
|
| 307 |
+
st.download_button(
|
| 308 |
+
label="Télécharger l'image rotée",
|
| 309 |
+
data=image_to_bytes(rotated),
|
| 310 |
+
file_name=f"image_rotated_{angle}.png",
|
| 311 |
+
mime="image/png"
|
| 312 |
+
)
|
| 313 |
|
| 314 |
elif menu_option == "Floutage":
|
| 315 |
st.subheader("Floutage")
|
|
|
|
| 317 |
blur_level = st.slider("Niveau de flou (k)", min_value=1, max_value=51, step=2, value=15)
|
| 318 |
blurred = cv2.GaussianBlur(image_np, (blur_level, blur_level), 0)
|
| 319 |
st.image(blurred, caption=f"Image Floutée (k={blur_level})", use_container_width=True)
|
| 320 |
+
|
| 321 |
+
# Bouton de téléchargement
|
| 322 |
+
st.download_button(
|
| 323 |
+
label="Télécharger l'image floutée",
|
| 324 |
+
data=image_to_bytes(blurred),
|
| 325 |
+
file_name=f"image_blurred_k{blur_level}.png",
|
| 326 |
+
mime="image/png"
|
| 327 |
+
)
|
| 328 |
|
| 329 |
elif menu_option == "Contours":
|
| 330 |
st.subheader("Contours")
|
|
|
|
| 332 |
gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
|
| 333 |
edges = cv2.Canny(gray, 100, 200)
|
| 334 |
st.image(edges, caption="Contours de l'Image", use_container_width=True)
|
| 335 |
+
# Bouton de téléchargement
|
| 336 |
+
st.download_button(
|
| 337 |
+
label="Télécharger l'image avec contours",
|
| 338 |
+
data=image_to_bytes(edges),
|
| 339 |
+
file_name=f"image_edges.png",
|
| 340 |
+
mime="image/png"
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
|
| 344 |
elif menu_option == "Génération de Code-barres et QR Code":
|
| 345 |
st.subheader("Génération de Code-barres et QR Code")
|
| 346 |
+
|
| 347 |
+
# Entrée utilisateur pour le lien ou le texte
|
| 348 |
+
link = st.text_input("Entre un lien ou un texte pour générer les codes")
|
| 349 |
+
|
| 350 |
+
# Ajout du bouton pour confirmer la génération
|
| 351 |
+
if st.button("Générer"):
|
| 352 |
+
if link:
|
| 353 |
+
try:
|
| 354 |
+
# Génération du code-barres
|
| 355 |
+
barcode_image = generate_barcode(link)
|
| 356 |
+
st.image(barcode_image, caption="Code-barres généré", use_container_width=True)
|
| 357 |
+
|
| 358 |
+
barcode_buffer = BytesIO()
|
| 359 |
+
barcode_image.save(barcode_buffer, format="PNG")
|
| 360 |
+
barcode_buffer.seek(0)
|
| 361 |
+
st.download_button(
|
| 362 |
+
label="Télécharger le Code-barres",
|
| 363 |
+
data=barcode_buffer,
|
| 364 |
+
file_name="barcode.png",
|
| 365 |
+
mime="image/png"
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
# Génération du QR Code
|
| 369 |
+
qrcode_image = generate_qrcode(link)
|
| 370 |
+
st.image(qrcode_image, caption="QR Code généré", use_container_width=True)
|
| 371 |
+
|
| 372 |
+
# Bouton de téléchargement pour le code-barres
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
# Bouton de téléchargement pour le QR code
|
| 376 |
+
qrcode_buffer = BytesIO()
|
| 377 |
+
qrcode_image.save(qrcode_buffer, format="PNG")
|
| 378 |
+
qrcode_buffer.seek(0)
|
| 379 |
+
st.download_button(
|
| 380 |
+
label="Télécharger le QR Code",
|
| 381 |
+
data=qrcode_buffer,
|
| 382 |
+
file_name="qrcode.png",
|
| 383 |
+
mime="image/png"
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
except Exception as e:
|
| 387 |
+
st.error(f"Une erreur est survenue : {e}")
|
| 388 |
+
else:
|
| 389 |
+
st.error("Veuillez entrer un lien ou un texte valide pour générer les codes.")
|
| 390 |
|
| 391 |
elif menu_option == "Détection Faciale":
|
| 392 |
st.subheader("Détection Faciale")
|