jgitsolutions commited on
Commit
e029145
1 Parent(s): d144847

'replaced np with pandas'

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -9,7 +9,7 @@ from diffusers.models import AutoencoderKL
9
  from diffusers.models.attention_processor import AttnProcessor2_0
10
  from PIL import Image
11
  import cv2
12
- import numpy as np
13
  from RealESRGAN import RealESRGAN
14
  import gradio as gr
15
  from gradio_imageslider import ImageSlider
@@ -146,21 +146,21 @@ def resize_and_upscale(input_image, resolution):
146
  def create_hdr_effect(original_image, hdr):
147
  if hdr == 0:
148
  return original_image
149
- cv_original = cv2.cvtColor(np.array(original_image), cv2.COLOR_RGB2BGR)
150
  factors = [1.0 - 0.9 * hdr, 1.0 - 0.7 * hdr, 1.0 - 0.45 * hdr,
151
  1.0 - 0.25 * hdr, 1.0, 1.0 + 0.2 * hdr,
152
  1.0 + 0.4 * hdr, 1.0 + 0.6 * hdr, 1.0 + 0.8 * hdr]
153
  images = [cv2.convertScaleAbs(cv_original, alpha=factor) for factor in factors]
154
  merge_mertens = cv2.createMergeMertens()
155
  hdr_image = merge_mertens.process(images)
156
- hdr_image_8bit = np.clip(hdr_image * 255, 0, 255).astype('uint8')
157
  return Image.fromarray(cv2.cvtColor(hdr_image_8bit, cv2.COLOR_BGR2RGB))
158
 
159
  def apply_denoising(image, strength):
160
  return cv2.fastNlMeansDenoisingColored(image, None, strength * 10, strength * 10, 7, 21)
161
 
162
  def apply_sharpening(image, intensity):
163
- kernel = np.array([[0, -1, 0], [-1, 5 + intensity * 4, -1], [0, -1, 0]])
164
  return cv2.filter2D(image, -1, kernel)
165
 
166
  def prepare_image(input_image, resolution, hdr):
@@ -187,7 +187,7 @@ def gradio_process_images(input_images, model_choice, custom_prompt, custom_nega
187
  "control_image": condition_image,
188
  }
189
  result = lazy_pipe(**options).images[0]
190
- result = np.array(result)
191
 
192
  if denoising_strength > 0:
193
  result = apply_denoising(result, denoising_strength)
@@ -212,7 +212,7 @@ def update_live_preview(input_image, model_choice, custom_prompt, custom_negativ
212
  "control_image": condition_image,
213
  }
214
  result = lazy_pipe(**options).images[0]
215
- return np.array(result)
216
 
217
  # Gradio Interface
218
  input_images = gr.File(label="Input Images", type="file", multiple=True)
@@ -251,4 +251,4 @@ demo = gr.Interface(
251
  outputs=output_slider
252
  )
253
 
254
- demo.launch()
 
9
  from diffusers.models.attention_processor import AttnProcessor2_0
10
  from PIL import Image
11
  import cv2
12
+ import pandas as pd
13
  from RealESRGAN import RealESRGAN
14
  import gradio as gr
15
  from gradio_imageslider import ImageSlider
 
146
  def create_hdr_effect(original_image, hdr):
147
  if hdr == 0:
148
  return original_image
149
+ cv_original = cv2.cvtColor(pd.DataFrame(original_image).to_numpy(), cv2.COLOR_RGB2BGR)
150
  factors = [1.0 - 0.9 * hdr, 1.0 - 0.7 * hdr, 1.0 - 0.45 * hdr,
151
  1.0 - 0.25 * hdr, 1.0, 1.0 + 0.2 * hdr,
152
  1.0 + 0.4 * hdr, 1.0 + 0.6 * hdr, 1.0 + 0.8 * hdr]
153
  images = [cv2.convertScaleAbs(cv_original, alpha=factor) for factor in factors]
154
  merge_mertens = cv2.createMergeMertens()
155
  hdr_image = merge_mertens.process(images)
156
+ hdr_image_8bit = pd.DataFrame(np.clip(hdr_image * 255, 0, 255).astype('uint8')).to_numpy()
157
  return Image.fromarray(cv2.cvtColor(hdr_image_8bit, cv2.COLOR_BGR2RGB))
158
 
159
  def apply_denoising(image, strength):
160
  return cv2.fastNlMeansDenoisingColored(image, None, strength * 10, strength * 10, 7, 21)
161
 
162
  def apply_sharpening(image, intensity):
163
+ kernel = pd.DataFrame([[0, -1, 0], [-1, 5 + intensity * 4, -1], [0, -1, 0]]).to_numpy()
164
  return cv2.filter2D(image, -1, kernel)
165
 
166
  def prepare_image(input_image, resolution, hdr):
 
187
  "control_image": condition_image,
188
  }
189
  result = lazy_pipe(**options).images[0]
190
+ result = pd.DataFrame(result).to_numpy()
191
 
192
  if denoising_strength > 0:
193
  result = apply_denoising(result, denoising_strength)
 
212
  "control_image": condition_image,
213
  }
214
  result = lazy_pipe(**options).images[0]
215
+ return pd.DataFrame(result).to_numpy()
216
 
217
  # Gradio Interface
218
  input_images = gr.File(label="Input Images", type="file", multiple=True)
 
251
  outputs=output_slider
252
  )
253
 
254
+ demo.launch()