remove opencv and torch imports

#1
by edgarriba - opened
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -1,21 +1,16 @@
1
  import gradio as gr
2
- import cv2
3
 
4
- import torch
5
  import kornia as K
 
6
 
7
- def load_torch_image(fname):
8
- img = K.image_to_tensor(fname, False).float() / 255.
9
- img = K.color.bgr_to_rgb(img)
10
- return img
11
 
 
 
 
 
12
 
13
- def enhance(file, brightness, contrast, saturation, gamma, hue):
14
- fname = file.name
15
- im = cv2.imread(fname)
16
- img = load_torch_image(im)
17
-
18
- x_out: torch.Tensor = K.enhance.adjust_brightness(img, float(brightness))
19
  x_out = K.enhance.adjust_contrast(x_out, float(contrast))
20
  x_out = K.enhance.adjust_saturation(x_out, float(saturation))
21
  x_out = K.enhance.adjust_gamma(x_out, float(gamma))
 
1
  import gradio as gr
 
2
 
 
3
  import kornia as K
4
+ from kornia.core import Tensor
5
 
 
 
 
 
6
 
7
+ def enhance(file, brightness, contrast, saturation, gamma, hue):
8
+ # load the image using the rust backend
9
+ img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
10
+ img = img[None] / 255.
11
 
12
+ # apply tensor image enhancement
13
+ x_out: Tensor = K.enhance.adjust_brightness(img, float(brightness))
 
 
 
 
14
  x_out = K.enhance.adjust_contrast(x_out, float(contrast))
15
  x_out = K.enhance.adjust_saturation(x_out, float(saturation))
16
  x_out = K.enhance.adjust_gamma(x_out, float(gamma))