Datasets:
File size: 2,959 Bytes
2c3f34a ccfa6b3 2c3f34a ccfa6b3 2c3f34a ac4ade7 2c3f34a ac4ade7 2c3f34a ac4ade7 2c3f34a ac4ade7 2c3f34a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import os
import sys
import subprocess
from PIL import Image
# Import skin conversion logic
from convert_skin import convert_skin_64x32_to_64x64
def main():
skins_dir = "skins"
control_imgs_dir = "control_imgs"
if not os.path.exists(skins_dir):
print(f"Error: Skins directory '{skins_dir}' does not exist.")
sys.exit(1)
os.makedirs(control_imgs_dir, exist_ok=True)
# List all PNG files in skins
skin_files = [f for f in os.listdir(skins_dir) if f.lower().endswith(".png")]
skin_files.sort()
print(f"[*] Found {len(skin_files)} skin files in {skins_dir}.")
# 1. Pre-repair pass: check and convert all legacy 64x32 skins in the candidate directory
print("[*] Running pre-repair check on all skin files...")
for skin_file in skin_files:
skin_path = os.path.join(skins_dir, skin_file)
try:
with Image.open(skin_path) as img:
width, height = img.size
if (width, height) == (64, 32):
print(f"[*] Pre-repair: Detected legacy 64x32 skin format for {skin_file}. Auto-converting to 64x64...")
convert_skin_64x32_to_64x64(skin_path, skin_path)
except Exception as e:
print(f"[!] Pre-repair: Error checking skin size for {skin_file}: {e}")
skipped = 0
processed = 0
for skin_file in skin_files:
skin_path = os.path.join(skins_dir, skin_file)
output_path = os.path.join(control_imgs_dir, skin_file)
# Check if the output control image already exists
if os.path.exists(output_path):
skipped += 1
continue
print("="*60)
print(f"[*] Processing: {skin_file}")
# Verify skin size (should be 64x64 after pre-repair)
try:
with Image.open(skin_path) as img:
if img.size != (64, 64):
print(f"[!] Warning: Skin '{skin_file}' has unexpected dimensions {img.size}. Skipping.")
continue
except Exception as e:
print(f"[!] Error verifying skin size: {e}")
continue
# Invoke gpt_skin2real.py using subprocess
cmd = [sys.executable, "gpt_skin2real.py", skin_path, "-o", output_path]
print(f"[*] Running command: {' '.join(cmd)}")
try:
# We run the command and check for success. If it fails, we output the error but continue to other skins.
subprocess.run(cmd, check=True)
print(f"[+] Completed: {skin_file} -> {output_path}")
processed += 1
except subprocess.CalledProcessError as e:
print(f"[!] Command failed for {skin_file}: {e}")
except Exception as e:
print(f"[!] Error running pipeline for {skin_file}: {e}")
print("="*60)
print(f"[*] Batch run completed. Processed: {processed}, Skipped (Already existed): {skipped}.")
if __name__ == "__main__":
main()
|