MynooMuz commited on
Commit
025aeb3
·
1 Parent(s): 13a7fb4

feat: add color palette limit selection

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -14,10 +14,15 @@ import spaces
14
  import tempfile
15
 
16
  @spaces.GPU
17
- def process_image(input_image_path):
18
  if input_image_path is None:
19
  return None, None, "Please upload an image."
20
 
 
 
 
 
 
21
  # Get original filename
22
  original_name = os.path.basename(input_image_path)
23
  base, _ = os.path.splitext(original_name)
@@ -47,7 +52,7 @@ def process_image(input_image_path):
47
 
48
  # Generate and save extraction with accurate colors
49
  from pixelfixer.reconstruct import two_stage_pack
50
- low = two_stage_pack(rgba, int(r["cols"]), int(r["rows"]))
51
  extract_img = Image.fromarray(low)
52
 
53
  # Upscale using nearest neighbor to prevent blurriness
@@ -61,6 +66,8 @@ def process_image(input_image_path):
61
  # Create info string
62
  info = f"Grid detected: {r['cols']}x{r['rows']}\n"
63
  info += f"Step size: {r['step_x']}x{r['step_y']}\n"
 
 
64
  info += f"Processing time: {dt}s"
65
 
66
  return overlay_path, extract_path, info
@@ -72,16 +79,17 @@ with gr.Blocks(title="Pixel Art Fixer") as app:
72
  with gr.Row():
73
  with gr.Column():
74
  input_image = gr.Image(type="filepath", label="Input Image")
 
75
  process_btn = gr.Button("Process Image", variant="primary")
76
 
77
  with gr.Column():
78
- info_text = gr.Textbox(label="Detection Info", lines=3)
79
  overlay_image = gr.Image(type="filepath", label="Grid Overlay")
80
  extract_image = gr.Image(type="filepath", label="Extracted Pixel Art")
81
 
82
  process_btn.click(
83
  fn=process_image,
84
- inputs=[input_image],
85
  outputs=[overlay_image, extract_image, info_text]
86
  )
87
 
 
14
  import tempfile
15
 
16
  @spaces.GPU
17
+ def process_image(input_image_path, color_limit):
18
  if input_image_path is None:
19
  return None, None, "Please upload an image."
20
 
21
+ # Parse color limit
22
+ k_colors = 0
23
+ if color_limit != "Unlimited":
24
+ k_colors = int(color_limit)
25
+
26
  # Get original filename
27
  original_name = os.path.basename(input_image_path)
28
  base, _ = os.path.splitext(original_name)
 
52
 
53
  # Generate and save extraction with accurate colors
54
  from pixelfixer.reconstruct import two_stage_pack
55
+ low = two_stage_pack(rgba, int(r["cols"]), int(r["rows"]), k_colors=k_colors)
56
  extract_img = Image.fromarray(low)
57
 
58
  # Upscale using nearest neighbor to prevent blurriness
 
66
  # Create info string
67
  info = f"Grid detected: {r['cols']}x{r['rows']}\n"
68
  info += f"Step size: {r['step_x']}x{r['step_y']}\n"
69
+ if k_colors > 0:
70
+ info += f"Colors: {k_colors}\n"
71
  info += f"Processing time: {dt}s"
72
 
73
  return overlay_path, extract_path, info
 
79
  with gr.Row():
80
  with gr.Column():
81
  input_image = gr.Image(type="filepath", label="Input Image")
82
+ color_limit = gr.Radio(choices=["Unlimited", "8", "12", "16", "32"], value="Unlimited", label="Color Palette Limit")
83
  process_btn = gr.Button("Process Image", variant="primary")
84
 
85
  with gr.Column():
86
+ info_text = gr.Textbox(label="Detection Info", lines=4)
87
  overlay_image = gr.Image(type="filepath", label="Grid Overlay")
88
  extract_image = gr.Image(type="filepath", label="Extracted Pixel Art")
89
 
90
  process_btn.click(
91
  fn=process_image,
92
+ inputs=[input_image, color_limit],
93
  outputs=[overlay_image, extract_image, info_text]
94
  )
95