CSB261 commited on
Commit
9ea4ecb
โ€ข
1 Parent(s): e2a3594

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -48,32 +48,32 @@ def save_image(image):
48
  return None
49
 
50
 
51
- slider1 = ImageSlider(label="birefnet", type="pil")
52
- slider2 = ImageSlider(label="birefnet", type="pil")
53
- image = gr.Image(label="Upload an image")
54
- text = gr.Textbox(label="Paste an image URL")
55
- download_button = gr.Button("Download Image") # ๋‹ค์šด๋กœ๋“œ ๋ฒ„ํŠผ ์ถ”๊ฐ€
56
- output_file = gr.File() # ํŒŒ์ผ ์ถœ๋ ฅ ์ถ”๊ฐ€
57
-
58
- chameleon = load_img("butterfly.jpg", output_type="pil")
59
-
60
- url = "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"
61
- tab1 = gr.Interface(
62
- fn, inputs=image, outputs=[slider1, output_file], examples=[chameleon], api_name="image"
63
- )
64
-
65
- tab2 = gr.Interface(fn, inputs=text, outputs=[slider2, output_file], examples=[url], api_name="text")
66
-
67
-
68
- def process_download(image):
69
- return save_image(image[0])
70
-
71
-
72
- download_button.click(process_download, inputs=slider1, outputs=output_file)
73
-
74
- demo = gr.TabbedInterface(
75
- [tab1, tab2], ["image", "text"], title="birefnet for background removal"
76
- )
77
 
78
  if __name__ == "__main__":
79
  demo.launch()
 
 
48
  return None
49
 
50
 
51
+ with gr.Blocks() as demo:
52
+ image = gr.Image(label="Upload an image")
53
+ text = gr.Textbox(label="Paste an image URL")
54
+ download_button = gr.Button("Download Image")
55
+ output_file = gr.File()
56
+ slider1 = ImageSlider(label="birefnet", type="pil")
57
+ slider2 = ImageSlider(label="birefnet", type="pil")
58
+
59
+ chameleon = load_img("butterfly.jpg", output_type="pil")
60
+ url = "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"
61
+
62
+ with gr.Tab("Image Upload"):
63
+ tab1 = gr.Interface(
64
+ fn, inputs=image, outputs=[slider1, output_file], examples=[chameleon], api_name="image"
65
+ )
66
+
67
+ with gr.Tab("Image URL"):
68
+ tab2 = gr.Interface(
69
+ fn, inputs=text, outputs=[slider2, output_file], examples=[url], api_name="text"
70
+ )
71
+
72
+ def process_download(image):
73
+ return save_image(image[0])
74
+
75
+ download_button.click(process_download, inputs=slider1, outputs=output_file)
 
76
 
77
  if __name__ == "__main__":
78
  demo.launch()
79
+