jpjp9292 commited on
Commit
e5b694d
ยท
verified ยท
1 Parent(s): 4a0121c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -4
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
  )