LennyS17 commited on
Commit
e9ef54a
·
1 Parent(s): ddca27a

Add example images

Browse files
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import tensorflow as tf
2
  from keras import models
3
  import numpy as np
@@ -31,8 +33,7 @@ def preprocess_image(img):
31
 
32
  # Function to postprocess the image (denormalize)
33
  def postprocess_image(img):
34
- img = cv2.cvtColor(((img + 1) * 127.5).numpy().astype(np.uint8), cv2.COLOR_LAB2RGB)
35
- return np.uint8(np.clip(img, 0, 255))
36
 
37
 
38
  # Function to adjust brightness
@@ -94,12 +95,17 @@ def colorize_image(input_image):
94
 
95
 
96
  # Function to colorize and store the result for further manipulation
97
- def colorize_and_store(img):
98
  # Colorize the image
99
  colorized_image = colorize_image(img)
100
 
 
 
 
 
 
101
  # Return the colorized image for further manipulation (no model call)
102
- return colorized_image, colorized_image
103
 
104
 
105
  def make_grayscale_256(img):
@@ -133,6 +139,14 @@ p {
133
  }
134
  """
135
 
 
 
 
 
 
 
 
 
136
  # Gradio Interface
137
  with gr.Blocks(css=css) as demo:
138
  demo.title = "Portrait Colorizer"
@@ -151,6 +165,9 @@ with gr.Blocks(css=css) as demo:
151
  width=256,
152
  elem_id="input-image",
153
  )
 
 
 
154
  output_image = gr.Image(
155
  type="numpy",
156
  label="Colorized Image",
@@ -170,7 +187,7 @@ with gr.Blocks(css=css) as demo:
170
  # Button click triggers processing
171
  process_button.click(
172
  fn=colorize_and_store,
173
- inputs=input_image,
174
  outputs=[colorized_image, output_image],
175
  )
176
 
 
1
+ import os
2
+ import random
3
  import tensorflow as tf
4
  from keras import models
5
  import numpy as np
 
33
 
34
  # Function to postprocess the image (denormalize)
35
  def postprocess_image(img):
36
+ return cv2.cvtColor(((img + 1) * 127.5).numpy().astype(np.uint8), cv2.COLOR_LAB2RGB)
 
37
 
38
 
39
  # Function to adjust brightness
 
95
 
96
 
97
  # Function to colorize and store the result for further manipulation
98
+ def colorize_and_store(img, bright_slider, cont_slider, sat_slider, hue_slider):
99
  # Colorize the image
100
  colorized_image = colorize_image(img)
101
 
102
+ output_image = adjust_brightness(colorized_image, bright_slider)
103
+ output_image = adjust_contrast(output_image, cont_slider)
104
+ output_image = adjust_saturation(output_image, sat_slider)
105
+ output_image = adjust_hue(output_image, hue_slider)
106
+
107
  # Return the colorized image for further manipulation (no model call)
108
+ return colorized_image, output_image
109
 
110
 
111
  def make_grayscale_256(img):
 
139
  }
140
  """
141
 
142
+ # Get all image file paths in the folder
143
+ image_files = [
144
+ os.path.join("examples", file)
145
+ for file in os.listdir("examples")
146
+ if file.lower().endswith((".png", ".jpg", ".jpeg", ".webp"))
147
+ ]
148
+ random.shuffle(image_files)
149
+
150
  # Gradio Interface
151
  with gr.Blocks(css=css) as demo:
152
  demo.title = "Portrait Colorizer"
 
165
  width=256,
166
  elem_id="input-image",
167
  )
168
+ examples_gallery = gr.Examples(
169
+ examples=image_files, inputs=[input_image], label="Example Images"
170
+ )
171
  output_image = gr.Image(
172
  type="numpy",
173
  label="Colorized Image",
 
187
  # Button click triggers processing
188
  process_button.click(
189
  fn=colorize_and_store,
190
+ inputs=[input_image, bright_slider, cont_slider, sat_slider, hue_slider],
191
  outputs=[colorized_image, output_image],
192
  )
193
 
examples/ex1.jpg ADDED
examples/ex2.jpg ADDED
examples/ex3.jpg ADDED
examples/ex4.jpg ADDED
examples/ex5.jpg ADDED
examples/ex6.jpg ADDED
examples/ex7.jpg ADDED
examples/ex8.jpg ADDED