Spaces:
Build error

pratyyush commited on
Commit
ff1cfd3
·
verified ·
1 Parent(s): 0fec2b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -26,12 +26,12 @@ device.set(device=DeviceId.GPU0) # If GPU available
26
  # Load model
27
  _colorizer = get_image_colorizer(root_folder=Path(snapshot_folder), artistic=True)
28
 
29
- def colorizer_fn(input_img):
30
- """Colorize grayscale images with fixed render factor 40."""
31
  if input_img:
32
  output_img = _colorizer.get_transformed_image(
33
  path=input_img,
34
- render_factor=40, # Fixed render factor
35
  watermarked=False,
36
  post_process=True,
37
  )
@@ -39,27 +39,35 @@ def colorizer_fn(input_img):
39
  else:
40
  return None
41
 
42
- # ✅ Custom CSS to Hide the Share Button
 
 
 
43
  custom_css = """
44
  body, .gradio-container { background-color: black !important; color: white !important; }
45
  .gr-box { width: 100% !important; }
46
  img { max-width: 100vw !important; max-height: 90vh !important; object-fit: contain; }
47
  footer {display: none !important;} /* Hide footer */
48
  button[title="Share"] { display: none !important; } /* Hides the Share button */
 
49
  """
50
 
51
- # Gradio Interface (Button to select image, shows only output)
52
  with gr.Blocks(css=custom_css) as demo:
53
- gr.Markdown("# AI Image Colorizer")
54
 
55
  # File uploader
56
  image_input = gr.File(label="Select Image", file_types=[".png", ".jpg", ".jpeg"])
57
 
 
 
 
58
  # Output display
59
- output = gr.Image(label="Colorized Image")
60
 
61
- # Process image when uploaded
62
- image_input.change(colorizer_fn, inputs=image_input, outputs=output)
 
63
 
64
  # Launch the app
65
  if __name__ == "__main__":
 
26
  # Load model
27
  _colorizer = get_image_colorizer(root_folder=Path(snapshot_folder), artistic=True)
28
 
29
+ def colorizer_fn(input_img, render_factor):
30
+ """Colorize grayscale images with adjustable render factor."""
31
  if input_img:
32
  output_img = _colorizer.get_transformed_image(
33
  path=input_img,
34
+ render_factor=int(render_factor), # Use slider value
35
  watermarked=False,
36
  post_process=True,
37
  )
 
39
  else:
40
  return None
41
 
42
+ # ✅ Custom CSS to:
43
+ # - Hide share button
44
+ # - Fix image in place (disable dragging)
45
+ # - Make the output image full-screen
46
  custom_css = """
47
  body, .gradio-container { background-color: black !important; color: white !important; }
48
  .gr-box { width: 100% !important; }
49
  img { max-width: 100vw !important; max-height: 90vh !important; object-fit: contain; }
50
  footer {display: none !important;} /* Hide footer */
51
  button[title="Share"] { display: none !important; } /* Hides the Share button */
52
+ img { pointer-events: none !important; } /* Prevents image dragging */
53
  """
54
 
55
+ # Gradio Interface with Slider and Fixed Output Image
56
  with gr.Blocks(css=custom_css) as demo:
57
+ gr.Markdown("# AI Image Colorizer with Render Factor Slider")
58
 
59
  # File uploader
60
  image_input = gr.File(label="Select Image", file_types=[".png", ".jpg", ".jpeg"])
61
 
62
+ # Slider for render factor
63
+ slider = gr.Slider(label="Render Factor", minimum=10, maximum=50, value=40, step=1)
64
+
65
  # Output display
66
+ output = gr.Image(label="Colorized Image", interactive=False) # Make image non-interactive
67
 
68
+ # Process image when uploaded or slider changed
69
+ image_input.change(colorizer_fn, inputs=[image_input, slider], outputs=output)
70
+ slider.change(colorizer_fn, inputs=[image_input, slider], outputs=output)
71
 
72
  # Launch the app
73
  if __name__ == "__main__":