Spaces:
Running
Running
| import os | |
| from PIL import Image | |
| from PIL.ExifTags import TAGS | |
| def scan_image_metadata(image_path): | |
| keywords = ['midjourney', 'dall-e', 'stable diffusion', 'generative', 'ai', 'dalle'] | |
| try: | |
| image = Image.open(image_path) | |
| exif_data = image.getexif() | |
| info_dict = image.info | |
| all_text = [] | |
| if exif_data: | |
| for tag_id, value in exif_data.items(): | |
| tag = TAGS.get(tag_id, tag_id) | |
| all_text.append(str(tag).lower()) | |
| all_text.append(str(value).lower()) | |
| if info_dict: | |
| for k, v in info_dict.items(): | |
| all_text.append(str(k).lower()) | |
| if isinstance(v, (str, bytes)): | |
| all_text.append(str(v).lower()) | |
| full_metadata_string = " ".join(all_text) | |
| for keyword in keywords: | |
| # Pour eviter les faux positifs avec 'ai', on pourrait faire une regex de mot entier, | |
| # mais on suit la consigne simple pour l'instant. (ex: 'dall-e' in texte) | |
| # Pour 'ai', on va chercher le mot entouré d'espaces ou ponctuations. | |
| # Mais par sécurité et vitesse, on utilise ' in ' | |
| if keyword in full_metadata_string: | |
| return { | |
| "is_fake": True, | |
| "reason": f"Signature IA trouvée dans les métadonnées (mot-clé: {keyword})" | |
| } | |
| return {"is_fake": False} | |
| except Exception as e: | |
| print(f"Erreur d'analyse forensic : {e}") | |
| return {"is_fake": False} | |