Upload readme.py with huggingface_hub
Browse files
readme.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
IMAGE_DIR = "." # change if needed
|
| 7 |
+
README_PATH = "README.md"
|
| 8 |
+
|
| 9 |
+
def extract_metadata(image_path):
|
| 10 |
+
try:
|
| 11 |
+
img = Image.open(image_path)
|
| 12 |
+
return img.text # This contains all tEXt chunks
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"❌ Error reading {image_path}: {e}") # <-- Removed '---'
|
| 15 |
+
|
| 16 |
+
# Get all PNGs in directory
|
| 17 |
+
image_files = [f for f in os.listdir(IMAGE_DIR) if f.lower().endswith(".png")]
|
| 18 |
+
|
| 19 |
+
# Write README.md
|
| 20 |
+
with open(README_PATH, "w") as readme:
|
| 21 |
+
readme.write("# 🖼️ AI Generated Images\n\n")
|
| 22 |
+
|
| 23 |
+
for image_file in image_files:
|
| 24 |
+
image_path = os.path.join(IMAGE_DIR, image_file)
|
| 25 |
+
|
| 26 |
+
print(f"Processing {image_file}...")
|
| 27 |
+
metadata = extract_metadata(image_path)
|
| 28 |
+
|
| 29 |
+
readme.write(f"## Image: {image_file}\n")
|
| 30 |
+
readme.write(f"**Prompt:** {metadata.get('Prompt', 'N/A')}\n\n")
|
| 31 |
+
readme.write(f"**Negative Prompt:** {metadata.get('NegativePrompt', 'N/A')}\n\n")
|
| 32 |
+
readme.write(f"**Model:** {metadata.get('Model', 'N/A')}\n")
|
| 33 |
+
readme.write(f"**Seed:** {metadata.get('Seed', 'N/A')}\n")
|
| 34 |
+
readme.write(f"**Date:** {metadata.get('Date', 'N/A')}\n\n")
|
| 35 |
+
|
| 36 |
+
# Add clickable image
|
| 37 |
+
readme.write(f"[]({image_file})\n\n")
|
| 38 |
+
readme.write("---\n\n")
|
| 39 |
+
|
| 40 |
+
print(f"✅ README.md created at {README_PATH}")
|