DreamerHC commited on
Commit
2f6c328
ยท
verified ยท
1 Parent(s): 3c7b030

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
- from transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation
3
  from PIL import Image
4
  import torch
5
 
6
- # ๋ชจ๋ธ๊ณผ ํ”ผ์ฒ˜ ์ถ”์ถœ๊ธฐ ๋กœ๋“œ
7
  model_name = "nvidia/mit-b0"
8
- feature_extractor = SegformerFeatureExtractor.from_pretrained(model_name)
9
  model = SegformerForSemanticSegmentation.from_pretrained(model_name)
10
 
11
  def remove_background(image):
12
  # ์ด๋ฏธ์ง€์—์„œ ํ”ผ์ฒ˜ ์ถ”์ถœ
13
- inputs = feature_extractor(images=image, return_tensors="pt")
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.inputs.Image(type="pil"), outputs="image", title="Background Remover", description="Upload an image to remove the background.")
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()