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 CHANGED

Git LFS Details

  • SHA256: 2d381592d66dd3da31230896df92b608f40f6c4c31dbc44abe3a57043e36cbee
  • Pointer size: 131 Bytes
  • Size of remote file: 852 kB

Git LFS Details

  • SHA256: d3057fdebb7200ceb7b0b827c41407b8cad06b1d296ad768351ca8704e9a6e65
  • Pointer size: 131 Bytes
  • Size of remote file: 683 kB
control_imgs/lowpoly/5002d28d665fc668.png ADDED

Git LFS Details

  • SHA256: d0f367c2389b9ffe28fa585d4155968d761ebd43be7e4f03c63b0824106bb17b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.65 MB
control_imgs/lowpoly/509dd472891584c0.png ADDED

Git LFS Details

  • SHA256: 4f6a37e097c4b9bb1801424fa4f859f3b6264eaaab17519f394e2bba68c01d51
  • Pointer size: 132 Bytes
  • Size of remote file: 1.66 MB
control_imgs/lowpoly/8882000.png CHANGED

Git LFS Details

  • SHA256: 4892842e52d94610ff25c5920c9000c67b51cc50513178ff08d0784ba97e8442
  • Pointer size: 132 Bytes
  • Size of remote file: 1.25 MB

Git LFS Details

  • SHA256: a9a41f83f98f548a42851c4f42f9ee4ce10b5b73795c4029965418a1d82327fc
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
control_imgs/lowpoly/8882001.png CHANGED

Git LFS Details

  • SHA256: 6c9369d6e2e683d1476f9cf27046168d9a8e776feec10d2201331d3b844cb122
  • Pointer size: 132 Bytes
  • Size of remote file: 1.54 MB

Git LFS Details

  • SHA256: 2f25ddf65164a09c40044395176297b8c1b41ce9a792d647cb8e2e9de1f4ae01
  • Pointer size: 132 Bytes
  • Size of remote file: 1.39 MB
control_imgs/lowpoly/8882002.png CHANGED

Git LFS Details

  • SHA256: 85083948d25785f914410ae1812ea57fef0ac7ee8c03509cf97bb2c7eacf4f50
  • Pointer size: 131 Bytes
  • Size of remote file: 922 kB

Git LFS Details

  • SHA256: ff4da0531476d848555d06bdf284b14374ea0576086b1c19b85d80301b84331e
  • Pointer size: 131 Bytes
  • Size of remote file: 780 kB
control_imgs/lowpoly/8882003.png CHANGED

Git LFS Details

  • SHA256: 82c33a6ce59e8b834dac04d3ad5f7424525433a70e2ec2571075bdf709586be6
  • Pointer size: 131 Bytes
  • Size of remote file: 528 kB

Git LFS Details

  • SHA256: ef34a33588cd9bdbd6c1e2aaf24bff6b3ce67291b20c511bb3aede157fbe4afd
  • Pointer size: 131 Bytes
  • Size of remote file: 441 kB
control_imgs/lowpoly/8883001.png ADDED

Git LFS Details

  • SHA256: c54d5d92899505da62d9df56c5ae224543a62a17c7d5f2e53f8b68a57be23e53
  • Pointer size: 132 Bytes
  • Size of remote file: 1.71 MB
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": "auto"
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=120, poll_interval=5):
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

  • SHA256: 10dd72ef537ac9026deb7d10db77c6f8bda0edb455722f6de5037474c7fc31cc
  • Pointer size: 128 Bytes
  • Size of remote file: 837 Bytes
skins/lowpoly/5002d28d665fc668.png ADDED

Git LFS Details

  • SHA256: b9568c88751d6c765fe09e0e24ec0bf3c313f51e373360625e2555307bb86365
  • Pointer size: 128 Bytes
  • Size of remote file: 725 Bytes
skins/lowpoly/509dd472891584c0.png ADDED

Git LFS Details

  • SHA256: dc2ce6c4b3252fc07d8ef5567dbbfbbbd085cd55e5083761182d8535c3a5a6de
  • Pointer size: 128 Bytes
  • Size of remote file: 871 Bytes
skins/lowpoly/8883001.png ADDED

Git LFS Details

  • SHA256: e73e1445a3f9e9fb02a5d3603c0cd8817fa842f5d61565ccd793ac0bf727d423
  • Pointer size: 129 Bytes
  • Size of remote file: 2.93 kB
skins/lowpoly/975b94368d87cede.png ADDED

Git LFS Details

  • SHA256: 58365e151b4ecf58cf45a01315497f26c10399324d8ebc1fc7859c927b92e784
  • Pointer size: 129 Bytes
  • Size of remote file: 1.09 kB
skins/lowpoly/cba099198414fdf1.png ADDED

Git LFS Details

  • SHA256: d0d3ec063426a2a7e2746efb1e0cfd3b208f7e6cbb83c6502d718082fb0f8f46
  • Pointer size: 129 Bytes
  • Size of remote file: 3.49 kB