Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
|
6 |
-
# ๋ชจ๋ธ๊ณผ
|
7 |
model_name = "nvidia/mit-b0"
|
8 |
-
|
9 |
model = SegformerForSemanticSegmentation.from_pretrained(model_name)
|
10 |
|
11 |
def remove_background(image):
|
12 |
# ์ด๋ฏธ์ง์์ ํผ์ฒ ์ถ์ถ
|
13 |
-
inputs =
|
14 |
outputs = model(**inputs)
|
15 |
logits = outputs.logits
|
16 |
# ๊ฒฐ๊ณผ์์ ๊ฐ์ฅ ๊ฐ๋ฅ์ฑ ๋์ ํด๋์ค ์ ํ
|
@@ -31,7 +31,7 @@ def remove_background(image):
|
|
31 |
return masked_image
|
32 |
|
33 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
34 |
-
iface = gr.Interface(fn=remove_background, inputs=gr.
|
35 |
|
36 |
# ์ฑ ์คํ
|
37 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
|
6 |
+
# ๋ชจ๋ธ๊ณผ ์ด๋ฏธ์ง ํ๋ก์ธ์ ๋ก๋
|
7 |
model_name = "nvidia/mit-b0"
|
8 |
+
image_processor = SegformerImageProcessor.from_pretrained(model_name)
|
9 |
model = SegformerForSemanticSegmentation.from_pretrained(model_name)
|
10 |
|
11 |
def remove_background(image):
|
12 |
# ์ด๋ฏธ์ง์์ ํผ์ฒ ์ถ์ถ
|
13 |
+
inputs = image_processor(images=image, return_tensors="pt")
|
14 |
outputs = model(**inputs)
|
15 |
logits = outputs.logits
|
16 |
# ๊ฒฐ๊ณผ์์ ๊ฐ์ฅ ๊ฐ๋ฅ์ฑ ๋์ ํด๋์ค ์ ํ
|
|
|
31 |
return masked_image
|
32 |
|
33 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
34 |
+
iface = gr.Interface(fn=remove_background, inputs=gr.Image(type="pil"), outputs="image", title="Background Remover", description="Upload an image to remove the background.")
|
35 |
|
36 |
# ์ฑ ์คํ
|
37 |
iface.launch()
|