Datasets:
EntropyDrop commited on
Commit ·
2c3f34a
1
Parent(s): 745b560
feat: implement gpt_image module, skin rendering pipelines, legacy converter, and auto batch generator
Browse files- control_imgs/lowpoly/438299.png +2 -2
- control_imgs/lowpoly/5002d28d665fc668.png +3 -0
- control_imgs/lowpoly/509dd472891584c0.png +3 -0
- control_imgs/lowpoly/8882000.png +2 -2
- control_imgs/lowpoly/8882001.png +2 -2
- control_imgs/lowpoly/8882002.png +2 -2
- control_imgs/lowpoly/8882003.png +2 -2
- control_imgs/lowpoly/8883001.png +3 -0
- convert_skin.py +88 -0
- force_resize_control_imgs.py +2 -2
- gpt_image.py +2 -2
- gpt_skin2real.py +1 -1
- gpt_skin2real_auto.py +71 -0
- skins/lowpoly/16ebce196c6e5038.png +3 -0
- skins/lowpoly/5002d28d665fc668.png +3 -0
- skins/lowpoly/509dd472891584c0.png +3 -0
- skins/lowpoly/8883001.png +3 -0
- skins/lowpoly/975b94368d87cede.png +3 -0
- skins/lowpoly/cba099198414fdf1.png +3 -0
control_imgs/lowpoly/438299.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
control_imgs/lowpoly/5002d28d665fc668.png
ADDED
|
Git LFS Details
|
control_imgs/lowpoly/509dd472891584c0.png
ADDED
|
Git LFS Details
|
control_imgs/lowpoly/8882000.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
control_imgs/lowpoly/8882001.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
control_imgs/lowpoly/8882002.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
control_imgs/lowpoly/8882003.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
control_imgs/lowpoly/8883001.png
ADDED
|
Git LFS Details
|
convert_skin.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import argparse
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def copy_mirrored_limb(img, new_img, src_x, src_y, dst_x, dst_y):
|
| 7 |
+
"""
|
| 8 |
+
Mirror a 16x16 limb block from source (src_x, src_y) to destination (dst_x, dst_y).
|
| 9 |
+
"""
|
| 10 |
+
# Top face
|
| 11 |
+
top = img.crop((src_x + 4, src_y, src_x + 8, src_y + 4))
|
| 12 |
+
new_img.paste(top.transpose(Image.FLIP_LEFT_RIGHT), (dst_x + 4, dst_y))
|
| 13 |
+
|
| 14 |
+
# Bottom face
|
| 15 |
+
bottom = img.crop((src_x + 8, src_y, src_x + 12, src_y + 4))
|
| 16 |
+
new_img.paste(bottom.transpose(Image.FLIP_LEFT_RIGHT), (dst_x + 8, dst_y))
|
| 17 |
+
|
| 18 |
+
# Front face
|
| 19 |
+
front = img.crop((src_x + 4, src_y + 4, src_x + 8, src_y + 16))
|
| 20 |
+
new_img.paste(front.transpose(Image.FLIP_LEFT_RIGHT), (dst_x + 4, dst_y + 4))
|
| 21 |
+
|
| 22 |
+
# Back face
|
| 23 |
+
back = img.crop((src_x + 12, src_y + 4, src_x + 16, src_y + 16))
|
| 24 |
+
new_img.paste(back.transpose(Image.FLIP_LEFT_RIGHT), (dst_x + 12, dst_y + 4))
|
| 25 |
+
|
| 26 |
+
# Right (Outer) face -> Left (Outer) face
|
| 27 |
+
right_face = img.crop((src_x, src_y + 4, src_x + 4, src_y + 16))
|
| 28 |
+
new_img.paste(right_face.transpose(Image.FLIP_LEFT_RIGHT), (dst_x + 8, dst_y + 4))
|
| 29 |
+
|
| 30 |
+
# Left (Inner) face -> Right (Inner) face
|
| 31 |
+
left_face = img.crop((src_x + 8, src_y + 4, src_x + 12, src_y + 16))
|
| 32 |
+
new_img.paste(left_face.transpose(Image.FLIP_LEFT_RIGHT), (dst_x, dst_y + 4))
|
| 33 |
+
|
| 34 |
+
def convert_skin_64x32_to_64x64(input_path, output_path):
|
| 35 |
+
print(f"[*] Loading skin: {input_path}")
|
| 36 |
+
img = Image.open(input_path).convert("RGBA")
|
| 37 |
+
|
| 38 |
+
# Verify dimensions
|
| 39 |
+
if img.size == (64, 64):
|
| 40 |
+
print(f"[*] Skin '{input_path}' is already 64x64. No conversion needed.")
|
| 41 |
+
if input_path != output_path:
|
| 42 |
+
img.save(output_path)
|
| 43 |
+
print(f"[+] Saved copy to: {output_path}")
|
| 44 |
+
return
|
| 45 |
+
|
| 46 |
+
if img.size != (64, 32):
|
| 47 |
+
raise ValueError(f"Unsupported skin dimensions: {img.size}. Expected 64x32 legacy skin.")
|
| 48 |
+
|
| 49 |
+
print("[*] Converting legacy 64x32 skin to modern 64x64 format...")
|
| 50 |
+
# Create empty 64x64 transparent canvas
|
| 51 |
+
new_img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
| 52 |
+
|
| 53 |
+
# Paste old skin onto the top 32 pixels of the new canvas
|
| 54 |
+
new_img.paste(img, (0, 0))
|
| 55 |
+
|
| 56 |
+
# Mirror Right Leg (0, 16) to Left Leg (16, 48)
|
| 57 |
+
copy_mirrored_limb(img, new_img, src_x=0, src_y=16, dst_x=16, dst_y=48)
|
| 58 |
+
|
| 59 |
+
# Mirror Right Arm (40, 16) to Left Arm (32, 48)
|
| 60 |
+
copy_mirrored_limb(img, new_img, src_x=40, src_y=16, dst_x=32, dst_y=48)
|
| 61 |
+
|
| 62 |
+
# Save the output image
|
| 63 |
+
new_img.save(output_path)
|
| 64 |
+
print(f"[+] Converted successfully. Modern 64x64 skin saved to: {output_path}")
|
| 65 |
+
|
| 66 |
+
def main():
|
| 67 |
+
parser = argparse.ArgumentParser(description="Convert legacy 64x32 Minecraft skins to modern 64x64 format.")
|
| 68 |
+
parser.add_argument("input_skin", help="Path to the legacy 64x32 Minecraft skin image.")
|
| 69 |
+
parser.add_argument("-o", "--output", help="Output path for the converted skin. Defaults to input_name_64x64.png.")
|
| 70 |
+
args = parser.parse_args()
|
| 71 |
+
|
| 72 |
+
if not os.path.exists(args.input_skin):
|
| 73 |
+
print(f"Error: Input file '{args.input_skin}' does not exist.")
|
| 74 |
+
sys.exit(1)
|
| 75 |
+
|
| 76 |
+
output_path = args.output
|
| 77 |
+
if not output_path:
|
| 78 |
+
base, ext = os.path.splitext(args.input_skin)
|
| 79 |
+
output_path = f"{base}_64x64{ext or '.png'}"
|
| 80 |
+
|
| 81 |
+
try:
|
| 82 |
+
convert_skin_64x32_to_64x64(args.input_skin, output_path)
|
| 83 |
+
except Exception as e:
|
| 84 |
+
print(f"[!] Error: {e}")
|
| 85 |
+
sys.exit(1)
|
| 86 |
+
|
| 87 |
+
if __name__ == '__main__':
|
| 88 |
+
main()
|
force_resize_control_imgs.py
CHANGED
|
@@ -9,9 +9,9 @@ import uvicorn
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
|
| 12 |
-
for i in os.listdir('control_imgs'):
|
| 13 |
if i.endswith('.png'):
|
| 14 |
-
img_path = f'control_imgs/{i}'
|
| 15 |
img = Image.open(img_path)
|
| 16 |
w, h = img.width, img.height
|
| 17 |
if w != 1024 or h != 1024:
|
|
|
|
| 9 |
|
| 10 |
import os
|
| 11 |
|
| 12 |
+
for i in os.listdir('control_imgs/lowpoly'):
|
| 13 |
if i.endswith('.png'):
|
| 14 |
+
img_path = f'control_imgs/lowpoly/{i}'
|
| 15 |
img = Image.open(img_path)
|
| 16 |
w, h = img.width, img.height
|
| 17 |
if w != 1024 or h != 1024:
|
gpt_image.py
CHANGED
|
@@ -61,7 +61,7 @@ def generate_image(s3_urls, prompt):
|
|
| 61 |
"quality": "auto",
|
| 62 |
"resolution": "1K",
|
| 63 |
"response_format": "url",
|
| 64 |
-
"size": "
|
| 65 |
},
|
| 66 |
"prompt": prompt
|
| 67 |
}
|
|
@@ -85,7 +85,7 @@ def generate_image(s3_urls, prompt):
|
|
| 85 |
print(f"[+] Task created successfully. Task ID: {task_id}")
|
| 86 |
return task_id
|
| 87 |
|
| 88 |
-
def poll_task_status(task_id, timeout_seconds=
|
| 89 |
"""
|
| 90 |
Polls the task status with a timeout.
|
| 91 |
"""
|
|
|
|
| 61 |
"quality": "auto",
|
| 62 |
"resolution": "1K",
|
| 63 |
"response_format": "url",
|
| 64 |
+
"size": "1024x1024"
|
| 65 |
},
|
| 66 |
"prompt": prompt
|
| 67 |
}
|
|
|
|
| 85 |
print(f"[+] Task created successfully. Task ID: {task_id}")
|
| 86 |
return task_id
|
| 87 |
|
| 88 |
+
def poll_task_status(task_id, timeout_seconds=220, poll_interval=10):
|
| 89 |
"""
|
| 90 |
Polls the task status with a timeout.
|
| 91 |
"""
|
gpt_skin2real.py
CHANGED
|
@@ -16,7 +16,7 @@ def main():
|
|
| 16 |
parser = argparse.ArgumentParser(description="Render Minecraft skin to 3D views, upload to S3, and call img2img model.")
|
| 17 |
parser.add_argument("skin", help="Path to local Minecraft skin image file.")
|
| 18 |
parser.add_argument("-o", "--output", help="Output path for the generated image. Defaults to 'result_<timestamp>.png'.")
|
| 19 |
-
parser.add_argument("-p", "--prompt", default="生成ta的真人照片,再生成ta的背面放在图片右边", help="Prompt for the img2img model.")
|
| 20 |
parser.add_argument("-r", "--render-only", action="store_true", help="Only render the 3D front and back views locally, without calling the S3/img2img pipeline.")
|
| 21 |
args = parser.parse_args()
|
| 22 |
|
|
|
|
| 16 |
parser = argparse.ArgumentParser(description="Render Minecraft skin to 3D views, upload to S3, and call img2img model.")
|
| 17 |
parser.add_argument("skin", help="Path to local Minecraft skin image file.")
|
| 18 |
parser.add_argument("-o", "--output", help="Output path for the generated image. Defaults to 'result_<timestamp>.png'.")
|
| 19 |
+
parser.add_argument("-p", "--prompt", default="生成ta的全身真人照片,再生成ta的背面放在图片右边", help="Prompt for the img2img model.")
|
| 20 |
parser.add_argument("-r", "--render-only", action="store_true", help="Only render the 3D front and back views locally, without calling the S3/img2img pipeline.")
|
| 21 |
args = parser.parse_args()
|
| 22 |
|
gpt_skin2real_auto.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Import skin conversion logic
|
| 7 |
+
from convert_skin import convert_skin_64x32_to_64x64
|
| 8 |
+
|
| 9 |
+
def main():
|
| 10 |
+
skins_dir = "skins/lowpoly"
|
| 11 |
+
control_imgs_dir = "control_imgs/lowpoly"
|
| 12 |
+
|
| 13 |
+
if not os.path.exists(skins_dir):
|
| 14 |
+
print(f"Error: Skins directory '{skins_dir}' does not exist.")
|
| 15 |
+
sys.exit(1)
|
| 16 |
+
|
| 17 |
+
os.makedirs(control_imgs_dir, exist_ok=True)
|
| 18 |
+
|
| 19 |
+
# List all PNG files in skins/lowpoly
|
| 20 |
+
skin_files = [f for f in os.listdir(skins_dir) if f.lower().endswith(".png")]
|
| 21 |
+
skin_files.sort()
|
| 22 |
+
|
| 23 |
+
print(f"[*] Found {len(skin_files)} skin files in {skins_dir}.")
|
| 24 |
+
|
| 25 |
+
skipped = 0
|
| 26 |
+
processed = 0
|
| 27 |
+
|
| 28 |
+
for skin_file in skin_files:
|
| 29 |
+
skin_path = os.path.join(skins_dir, skin_file)
|
| 30 |
+
output_path = os.path.join(control_imgs_dir, skin_file)
|
| 31 |
+
|
| 32 |
+
# Check if the output control image already exists
|
| 33 |
+
if os.path.exists(output_path):
|
| 34 |
+
skipped += 1
|
| 35 |
+
continue
|
| 36 |
+
|
| 37 |
+
print("="*60)
|
| 38 |
+
print(f"[*] Processing: {skin_file}")
|
| 39 |
+
|
| 40 |
+
# Check skin size and auto-convert to 64x64 in-place if legacy format
|
| 41 |
+
try:
|
| 42 |
+
with Image.open(skin_path) as img:
|
| 43 |
+
width, height = img.size
|
| 44 |
+
if (width, height) == (64, 32):
|
| 45 |
+
print(f"[*] Detected legacy 64x32 skin format for {skin_file}. Auto-converting to 64x64...")
|
| 46 |
+
convert_skin_64x32_to_64x64(skin_path, skin_path)
|
| 47 |
+
elif (width, height) != (64, 64):
|
| 48 |
+
print(f"[!] Warning: Skin '{skin_file}' has unexpected dimensions {img.size}. Skipping.")
|
| 49 |
+
continue
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f"[!] Error checking skin size: {e}")
|
| 52 |
+
continue
|
| 53 |
+
|
| 54 |
+
# Invoke gpt_skin2real.py using subprocess
|
| 55 |
+
cmd = [sys.executable, "gpt_skin2real.py", skin_path, "-o", output_path]
|
| 56 |
+
print(f"[*] Running command: {' '.join(cmd)}")
|
| 57 |
+
try:
|
| 58 |
+
# We run the command and check for success. If it fails, we output the error but continue to other skins.
|
| 59 |
+
subprocess.run(cmd, check=True)
|
| 60 |
+
print(f"[+] Completed: {skin_file} -> {output_path}")
|
| 61 |
+
processed += 1
|
| 62 |
+
except subprocess.CalledProcessError as e:
|
| 63 |
+
print(f"[!] Command failed for {skin_file}: {e}")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"[!] Error running pipeline for {skin_file}: {e}")
|
| 66 |
+
|
| 67 |
+
print("="*60)
|
| 68 |
+
print(f"[*] Batch run completed. Processed: {processed}, Skipped (Already existed): {skipped}.")
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|
skins/lowpoly/16ebce196c6e5038.png
ADDED
|
Git LFS Details
|
skins/lowpoly/5002d28d665fc668.png
ADDED
|
Git LFS Details
|
skins/lowpoly/509dd472891584c0.png
ADDED
|
Git LFS Details
|
skins/lowpoly/8883001.png
ADDED
|
Git LFS Details
|
skins/lowpoly/975b94368d87cede.png
ADDED
|
Git LFS Details
|
skins/lowpoly/cba099198414fdf1.png
ADDED
|
Git LFS Details
|