rishi9440 commited on
Commit
13ba839
·
1 Parent(s): 4cb6a12

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -1,22 +1,32 @@
1
  import gradio as gr
2
  from rembg import remove
3
  from PIL import Image
 
4
 
5
  def remove_background(input_image):
6
  input = Image.open(input_image) # load image
7
  output = remove(input) # remove background
8
  return output
9
 
10
- input_image = gr.inputs.Image(type="filepath", label="Input Image")
11
- output_image = gr.inputs.Image(type="filepath", label="Output Image")
12
- output_image_download = gr.outputs.Download(label="Download Output")
13
 
14
  # Create a Gradio interface
15
  iface = gr.Interface(remove_background,
16
  inputs=input_image,
17
- outputs=[output_image, output_image_download],
18
  title='Image Background Remover',
19
- description='Upload an image and it will remove the background.')
 
 
 
 
 
 
 
20
 
21
  # Launch the interface
22
  iface.launch()
 
 
 
 
1
  import gradio as gr
2
  from rembg import remove
3
  from PIL import Image
4
+ import base64
5
 
6
  def remove_background(input_image):
7
  input = Image.open(input_image) # load image
8
  output = remove(input) # remove background
9
  return output
10
 
11
+ input_image = gr.inputs.Image(type="pil", label="Input Image")
12
+ output_image = gr.outputs.Image(type="pil", label="Output Image")
 
13
 
14
  # Create a Gradio interface
15
  iface = gr.Interface(remove_background,
16
  inputs=input_image,
17
+ outputs=output_image,
18
  title='Image Background Remover',
19
+ description='Upload an image and it will remove.')
20
+
21
+ # Define a function to convert PIL image to base64 string
22
+ def pil_to_base64_string(pil_image):
23
+ buffered = BytesIO()
24
+ pil_image.save(buffered, format="PNG")
25
+ img_str = base64.b64encode(buffered.getvalue()).decode()
26
+ return img_str
27
 
28
  # Launch the interface
29
  iface.launch()
30
+
31
+ # After the interface is launched, you can download the output image as follows:
32
+ output_pil = iface.get_output() # get the output PIL image from the