Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
4 |
import logging
|
|
|
5 |
|
6 |
# ๋ก๊น
์ค์
|
7 |
logging.basicConfig(level=logging.INFO)
|
@@ -17,6 +106,7 @@ def remove_background(input_image):
|
|
17 |
try:
|
18 |
logging.info("Processing image.")
|
19 |
|
|
|
20 |
if isinstance(input_image, str):
|
21 |
input_img = Image.open(input_image)
|
22 |
else:
|
@@ -36,6 +126,17 @@ def clear_images():
|
|
36 |
"""์
๋ ฅ ์ด๋ฏธ์ง์ ์ถ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ ์ด๊ธฐํํ๋ ํจ์"""
|
37 |
return None, None
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
40 |
with gr.Blocks(css="""
|
41 |
#btn-remove {
|
@@ -73,10 +174,7 @@ with gr.Blocks(css="""
|
|
73 |
|
74 |
# ์์ ์ด๋ฏธ์ง
|
75 |
gr.Examples(
|
76 |
-
examples=[
|
77 |
-
["./example1.jpg"],
|
78 |
-
["./example2.jpg"]
|
79 |
-
],
|
80 |
inputs=input_image,
|
81 |
label="์์ ์ด๋ฏธ์ง"
|
82 |
)
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# from rembg import remove
|
3 |
+
# from PIL import Image
|
4 |
+
# import logging
|
5 |
+
|
6 |
+
# # ๋ก๊น
์ค์
|
7 |
+
# logging.basicConfig(level=logging.INFO)
|
8 |
+
|
9 |
+
# def remove_background(input_image):
|
10 |
+
# """
|
11 |
+
# ์
๋ ฅ๋ ์ด๋ฏธ์ง์์ ๋ฐฐ๊ฒฝ์ ์ ๊ฑฐํ๋ ํจ์
|
12 |
+
# Parameters:
|
13 |
+
# input_image (PIL.Image ๋๋ str): ์
๋ก๋๋ ์ด๋ฏธ์ง ํ์ผ์ ๊ฐ์ฒด ๋๋ ํ์ผ ๊ฒฝ๋ก
|
14 |
+
# Returns:
|
15 |
+
# PIL.Image ๋๋ str: ๋ฐฐ๊ฒฝ์ด ์ ๊ฑฐ๋ ์ด๋ฏธ์ง ๋๋ ์๋ฌ ๋ฉ์์ง
|
16 |
+
# """
|
17 |
+
# try:
|
18 |
+
# logging.info("Processing image.")
|
19 |
+
|
20 |
+
# if isinstance(input_image, str):
|
21 |
+
# input_img = Image.open(input_image)
|
22 |
+
# else:
|
23 |
+
# input_img = input_image
|
24 |
+
|
25 |
+
# # ๋ฐฐ๊ฒฝ ์ ๊ฑฐ
|
26 |
+
# output_img = remove(input_img)
|
27 |
+
# logging.info("Background removed successfully.")
|
28 |
+
|
29 |
+
# # ํฌ๋ช
๋๋ฅผ ์ ์งํ๊ธฐ ์ํด PNG ํ์์ผ๋ก ๋ณํ
|
30 |
+
# return output_img.convert("RGBA")
|
31 |
+
# except Exception as e:
|
32 |
+
# logging.error(f"Error removing background: {e}")
|
33 |
+
# return f"์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
34 |
+
|
35 |
+
# def clear_images():
|
36 |
+
# """์
๋ ฅ ์ด๋ฏธ์ง์ ์ถ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ ์ด๊ธฐํํ๋ ํจ์"""
|
37 |
+
# return None, None
|
38 |
+
|
39 |
+
# # Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
40 |
+
# with gr.Blocks(css="""
|
41 |
+
# #btn-remove {
|
42 |
+
# background-color: #4CAF50; /* ์ด๋ก์ */
|
43 |
+
# color: white;
|
44 |
+
# }
|
45 |
+
# #btn-reset {
|
46 |
+
# background-color: #f44336; /* ๋นจ๊ฐ์ */
|
47 |
+
# color: white;
|
48 |
+
# }
|
49 |
+
# """) as demo:
|
50 |
+
# gr.Markdown("# ์ด๋ฏธ์ง ๋ฐฐ๊ฒฝ ์ ๊ฑฐ๊ธฐ")
|
51 |
+
# gr.Markdown("์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ๋ฐฐ๊ฒฝ์ด ์๋์ผ๋ก ์ ๊ฑฐ๋ฉ๋๋ค.")
|
52 |
+
|
53 |
+
# with gr.Row():
|
54 |
+
# input_image = gr.Image(
|
55 |
+
# type="pil",
|
56 |
+
# label="์
๋ ฅ ์ด๋ฏธ์ง",
|
57 |
+
# interactive=True # ์ฌ์ฉ์๊ฐ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ ์ ์๋๋ก ์ค์
|
58 |
+
# )
|
59 |
+
# output_image = gr.Image(
|
60 |
+
# type="pil",
|
61 |
+
# label="๋ฐฐ๊ฒฝ ์ ๊ฑฐ๋ ์ด๋ฏธ์ง",
|
62 |
+
# interactive=False # ์ถ๋ ฅ ์ด๋ฏธ์ง๋ ์ํธ์์ฉ ๋ถ๊ฐ๋ฅ
|
63 |
+
# )
|
64 |
+
|
65 |
+
# # ๋ฐฐ๊ฒฝ ์ ๊ฑฐ ๋ฒํผ
|
66 |
+
# with gr.Row():
|
67 |
+
# btn_remove = gr.Button("๋ฐฐ๊ฒฝ ์ ๊ฑฐ", elem_id="btn-remove") # elem_id๋ก ๋ฒํผ ์คํ์ผ ์ง์
|
68 |
+
# btn_remove.click(fn=remove_background, inputs=input_image, outputs=output_image)
|
69 |
+
|
70 |
+
# # ์ด๊ธฐํ ๋ฒํผ ์ถ๊ฐ
|
71 |
+
# btn_reset = gr.Button("์ด๊ธฐํ", elem_id="btn-reset") # elem_id๋ก ๋ฒํผ ์คํ์ผ ์ง์
|
72 |
+
# btn_reset.click(fn=clear_images, inputs=None, outputs=[input_image, output_image])
|
73 |
+
|
74 |
+
# # ์์ ์ด๋ฏธ์ง
|
75 |
+
# gr.Examples(
|
76 |
+
# examples=[
|
77 |
+
# ["./example1.jpg"],
|
78 |
+
# ["./example2.jpg"]
|
79 |
+
# ],
|
80 |
+
# inputs=input_image,
|
81 |
+
# label="์์ ์ด๋ฏธ์ง"
|
82 |
+
# )
|
83 |
+
|
84 |
+
# if __name__ == "__main__":
|
85 |
+
# demo.launch()
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
import gradio as gr
|
90 |
from rembg import remove
|
91 |
from PIL import Image
|
92 |
import logging
|
93 |
+
import os
|
94 |
|
95 |
# ๋ก๊น
์ค์
|
96 |
logging.basicConfig(level=logging.INFO)
|
|
|
106 |
try:
|
107 |
logging.info("Processing image.")
|
108 |
|
109 |
+
# ์
๋ก๋๋ ์ด๋ฏธ์ง๊ฐ ๊ฒฝ๋ก์ธ์ง ํ์ธ ํ ์ด๋ฏธ์ง ๊ฐ์ฒด๋ก ๋ก๋
|
110 |
if isinstance(input_image, str):
|
111 |
input_img = Image.open(input_image)
|
112 |
else:
|
|
|
126 |
"""์
๋ ฅ ์ด๋ฏธ์ง์ ์ถ๋ ฅ ์ด๋ฏธ์ง๋ฅผ ๋ชจ๋ ์ด๊ธฐํํ๋ ํจ์"""
|
127 |
return None, None
|
128 |
|
129 |
+
# ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก ์ค์
|
130 |
+
example_images = [
|
131 |
+
"./example1.jpg",
|
132 |
+
"./example2.jpg"
|
133 |
+
]
|
134 |
+
|
135 |
+
# ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก๊ฐ ์กด์ฌํ๋์ง ํ์ธ
|
136 |
+
for img_path in example_images:
|
137 |
+
if not os.path.exists(img_path):
|
138 |
+
logging.warning(f"Example image {img_path} does not exist. Please provide valid paths.")
|
139 |
+
|
140 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
141 |
with gr.Blocks(css="""
|
142 |
#btn-remove {
|
|
|
174 |
|
175 |
# ์์ ์ด๋ฏธ์ง
|
176 |
gr.Examples(
|
177 |
+
examples=[[img] for img in example_images], # ๋ฆฌ์คํธ ํ์์ผ๋ก ๊ฒฝ๋ก ์ ๋ฌ
|
|
|
|
|
|
|
178 |
inputs=input_image,
|
179 |
label="์์ ์ด๋ฏธ์ง"
|
180 |
)
|