Spaces:
fantos
/
Runtime error

arxivgpt kim commited on
Commit
d508478
ยท
verified ยท
1 Parent(s): 768a2fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -96,16 +96,29 @@ def merge_images(background_image, foreground_image):
96
  title = "Background Removal"
97
  description = "This is a demo for BRIA RMBG 1.4 using the BRIA RMBG-1.4 image matting model as backbone."
98
 
99
- demo = gr.Interface(
100
- fn=process,
101
- inputs=[
102
- gr.Image(type="numpy", label="Image to remove background"),
103
- gr.Image(type="pil", label="Optional: Background Image") # 'optional=True'๋Š” Gradio ๋ฒ„์ „์— ๋”ฐ๋ผ ํ•„์š” ์—†์„ ์ˆ˜ ์žˆ์Œ
104
- ],
105
- outputs="image",
106
- title=title,
107
- description=description
108
- )
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  if __name__ == "__main__":
111
- demo.launch()
 
96
  title = "Background Removal"
97
  description = "This is a demo for BRIA RMBG 1.4 using the BRIA RMBG-1.4 image matting model as backbone."
98
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ def add_blue_background(image):
101
+ # ๋ฐฐ๊ฒฝ ์ œ๊ฑฐ๋œ ์ด๋ฏธ์ง€์— ํ‘ธ๋ฅธ์ƒ‰ ๋ฐฐ๊ฒฝ์„ ์ถ”๊ฐ€ํ•˜๋Š” ํ•จ์ˆ˜
102
+ blue_background = Image.new("RGBA", image.size, "blue")
103
+ final_image = Image.alpha_composite(blue_background, image.convert("RGBA"))
104
+ return final_image
105
+
106
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์ด๋ฏธ์ง€ ์ž…๋ ฅ๊ณผ ๋‘ ๊ฐœ์˜ ์ถœ๋ ฅ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
107
+ inputs = gr.inputs.Image(type="pil")
108
+ outputs = [gr.outputs.Image(type="pil", label="Background Removed"),
109
+ gr.outputs.Image(type="pil", label="Blue Background Added")]
110
+
111
+ def update_interface(image):
112
+ transparent_image = process(image)
113
+ blue_background_image = add_blue_background(transparent_image)
114
+ return transparent_image, blue_background_image
115
+
116
+ demo = gr.Interface(fn=update_interface,
117
+ inputs=inputs,
118
+ outputs=outputs,
119
+ title="Background Removal and Add Blue Background",
120
+ description="This adds a blue background to the transparent image.")
121
+
122
+ # 'add' ๋ฒ„ํŠผ์„ ์ œ๊ฑฐํ–ˆ์œผ๋‚˜, ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ถ”๊ฐ€๋Š” ์ž๋™์œผ๋กœ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.
123
  if __name__ == "__main__":
124
+ demo.launch()