Rezuwan commited on
Commit
c085c3d
·
verified ·
1 Parent(s): 3444052

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -16,11 +16,11 @@ def remove_background(image):
16
  output_path = "output.png"
17
  output_img.save(output_path, format="PNG")
18
 
19
- return output_path, "Background removed successfully!", output_path
20
 
21
- # Example images (replace with your actual image paths in the 'examples' folder)
22
  example_images = [
23
- "examples/1.jpg",
24
  "examples/2.jpg",
25
  "examples/3.jpg",
26
  "examples/4.jpg",
@@ -31,19 +31,22 @@ example_images = [
31
  with gr.Blocks(title="Background Remover") as demo:
32
  gr.Markdown("# Background Remover")
33
  gr.Markdown("""
34
- Upload an image or use an example to remove its background.
35
  PS: Not the best image background remover out there but good enough for a free tool.
36
  """)
37
 
38
  with gr.Row():
39
  with gr.Column():
40
- image_input = gr.Image(type="pil", label="Input Image") # FIXED: removed tool="editor"
41
  submit_btn = gr.Button("Submit")
42
  clear_btn = gr.Button("Clear")
43
  with gr.Column():
44
  output_image = gr.Image(label="Output", type="filepath")
45
  output_text = gr.Textbox(label="Status", lines=1)
46
- download_output = gr.File(label="Download Output")
 
 
 
47
 
48
  with gr.Row():
49
  gr.Markdown("### Example Images")
@@ -54,8 +57,12 @@ with gr.Blocks(title="Background Remover") as demo:
54
  label="Click to try an example",
55
  )
56
 
57
- # Logic binding
58
- submit_btn.click(fn=remove_background, inputs=image_input, outputs=[output_image, output_text, download_output])
59
- clear_btn.click(fn=lambda: (None, "", None), outputs=[image_input, output_text, download_output])
 
 
 
 
60
 
61
  demo.launch()
 
16
  output_path = "output.png"
17
  output_img.save(output_path, format="PNG")
18
 
19
+ return output_path, "Background removed successfully!"
20
 
21
+ # Example images
22
  example_images = [
23
+ "examples/1.jpeg",
24
  "examples/2.jpg",
25
  "examples/3.jpg",
26
  "examples/4.jpg",
 
31
  with gr.Blocks(title="Background Remover") as demo:
32
  gr.Markdown("# Background Remover")
33
  gr.Markdown("""
34
+ Upload an image or use an example to remove its background.
35
  PS: Not the best image background remover out there but good enough for a free tool.
36
  """)
37
 
38
  with gr.Row():
39
  with gr.Column():
40
+ image_input = gr.Image(type="pil", label="Input Image")
41
  submit_btn = gr.Button("Submit")
42
  clear_btn = gr.Button("Clear")
43
  with gr.Column():
44
  output_image = gr.Image(label="Output", type="filepath")
45
  output_text = gr.Textbox(label="Status", lines=1)
46
+ download_area = gr.Column(visible=False)
47
+ with download_area:
48
+ gr.Markdown("### Download Output")
49
+ download_output = gr.File(label="", file_types=[".png"])
50
 
51
  with gr.Row():
52
  gr.Markdown("### Example Images")
 
57
  label="Click to try an example",
58
  )
59
 
60
+ # Button logic
61
+ def process(img):
62
+ output_path, msg = remove_background(img)
63
+ return output_path, msg, gr.update(visible=True), output_path
64
+
65
+ submit_btn.click(fn=process, inputs=image_input, outputs=[output_image, output_text, download_area, download_output])
66
+ clear_btn.click(fn=lambda: (None, "", gr.update(visible=False), None), outputs=[image_input, output_text, download_area, download_output])
67
 
68
  demo.launch()