Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ transform_image = transforms.Compose(
|
|
24 |
@spaces.GPU
|
25 |
def fn(image):
|
26 |
if image is None or len(image) == 0:
|
27 |
-
return image
|
28 |
im = load_img(image, output_type="pil")
|
29 |
im = im.convert("RGB")
|
30 |
image_size = im.size
|
@@ -38,24 +38,38 @@ def fn(image):
|
|
38 |
pred_pil = transforms.ToPILImage()(pred)
|
39 |
mask = pred_pil.resize(image_size)
|
40 |
image.putalpha(mask)
|
41 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
|
44 |
slider1 = ImageSlider(label="birefnet", type="pil")
|
45 |
slider2 = ImageSlider(label="birefnet", type="pil")
|
46 |
image = gr.Image(label="Upload an image")
|
47 |
text = gr.Textbox(label="Paste an image URL")
|
48 |
-
|
|
|
49 |
|
50 |
chameleon = load_img("butterfly.jpg", output_type="pil")
|
51 |
|
52 |
url = "https://hips.hearstapps.com/hmg-prod/images/gettyimages-1229892983-square.jpg"
|
53 |
tab1 = gr.Interface(
|
54 |
-
fn, inputs=image, outputs=slider1, examples=[chameleon], api_name="image"
|
55 |
)
|
56 |
|
57 |
-
tab2 = gr.Interface(fn, inputs=text, outputs=slider2, examples=[url], api_name="text")
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
59 |
|
60 |
demo = gr.TabbedInterface(
|
61 |
[tab1, tab2], ["image", "text"], title="birefnet for background removal"
|
|
|
24 |
@spaces.GPU
|
25 |
def fn(image):
|
26 |
if image is None or len(image) == 0:
|
27 |
+
return image, None # ์๋ณธ ์ด๋ฏธ์ง๋ ๋ฐํ
|
28 |
im = load_img(image, output_type="pil")
|
29 |
im = im.convert("RGB")
|
30 |
image_size = im.size
|
|
|
38 |
pred_pil = transforms.ToPILImage()(pred)
|
39 |
mask = pred_pil.resize(image_size)
|
40 |
image.putalpha(mask)
|
41 |
+
return image, origin # ๋ณํ๋ ์ด๋ฏธ์ง์ ์๋ณธ ์ด๋ฏธ์ง ๋ฐํ
|
42 |
+
|
43 |
+
|
44 |
+
def save_image(image):
|
45 |
+
if image is not None:
|
46 |
+
image.save("output.png")
|
47 |
+
return "output.png"
|
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"
|