Kvikontent commited on
Commit
27c3c1a
·
verified ·
1 Parent(s): bfd179d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -5,6 +5,7 @@ import io
5
  import torch
6
  import numpy as np
7
  from RealESRGAN import RealESRGAN
 
8
 
9
  # Initialize RealESRGAN model
10
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -13,16 +14,17 @@ model.load_weights('weights/RealESRGAN_x4.pth', download=True)
13
 
14
  def background_remover_and_upscale(input_image):
15
  # Remove background
16
- output_img = remove(input_image)
17
 
18
  # Convert back to PIL Image for upscaling
19
- output_img_pil = Image.fromarray(output_img)
 
20
 
21
  # Upscale image
22
- sr_image = model.predict(output_img_pil)
23
 
24
  # Return the upscaled image directly
25
- return sr_image
26
 
27
  description = """
28
  ✨ This app uses the rembg library to remove the background from uploaded images and then the RealESRGAN model to upscale the image.
@@ -31,12 +33,16 @@ Simply upload your image and let the models do their work. Download the result i
31
 
32
  iface = gr.Interface(
33
  fn=background_remover_and_upscale,
34
- inputs=gr.Image(type='pil', label="Upload Image"),
35
- outputs="image",
36
  examples=["woman.jpg", "groot.jpg"],
37
- title="🖼 Background Remover and Image Upscaler",
38
  description=description,
 
 
 
 
39
  theme="soft"
40
  )
41
 
42
- iface.launch(share=True)
 
5
  import torch
6
  import numpy as np
7
  from RealESRGAN import RealESRGAN
8
+ import cv2
9
 
10
  # Initialize RealESRGAN model
11
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 
14
 
15
  def background_remover_and_upscale(input_image):
16
  # Remove background
17
+ output_img = remove(np.array(input_image))
18
 
19
  # Convert back to PIL Image for upscaling
20
+ output_img_rgb = cv2.cvtColor(output_img, cv2.COLOR_BGR2RGB)
21
+ output_img_pil = Image.fromarray(output_img_rgb)
22
 
23
  # Upscale image
24
+ sr_image = model.predict([output_img])
25
 
26
  # Return the upscaled image directly
27
+ return sr_image[0]
28
 
29
  description = """
30
  ✨ This app uses the rembg library to remove the background from uploaded images and then the RealESRGAN model to upscale the image.
 
33
 
34
  iface = gr.Interface(
35
  fn=background_remover_and_upscale,
36
+ inputs=gr.Image(type='pil'),
37
+ outputs=[gr.File("image")],
38
  examples=["woman.jpg", "groot.jpg"],
39
+ title="Background Remover and Image Upscaler",
40
  description=description,
41
+ article="""This demo was created by KVI Kontent using Gradio.""",
42
+ allow_flagging=False,
43
+ live=True,
44
+ layout="horizontal",
45
  theme="soft"
46
  )
47
 
48
+ iface.launch()