GoBoKyung commited on
Commit
074b669
โ€ข
1 Parent(s): abbed59
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -15,7 +15,7 @@ model = TFSegformerForSemanticSegmentation.from_pretrained(
15
  )
16
 
17
  def ade_palette():
18
- """ADE20K palette that maps each class to RGB values."""
19
  return [
20
  [204, 87, 92],
21
  [112, 185, 212],
@@ -48,10 +48,10 @@ colormap = np.asarray(ade_palette())
48
 
49
  def label_to_color_image(label):
50
  if label.ndim != 2:
51
- raise ValueError("Expect 2-D input label")
52
 
53
  if np.max(label) >= len(colormap):
54
- raise ValueError("label value too large.")
55
  return colormap[label]
56
 
57
  def draw_plot(pred_img, seg):
@@ -76,11 +76,11 @@ def draw_plot(pred_img, seg):
76
  return fig
77
 
78
  def sepia(input_text):
79
- # Check if the input text is a valid file path
80
  if not os.path.isfile(input_text):
81
- return "Invalid file path. Please enter a valid image file path."
82
 
83
- # Load the image using the input text (assumed to be a path to an image)
84
  input_img = Image.open(input_text)
85
 
86
  inputs = feature_extractor(images=input_img, return_tensors="tf")
@@ -102,13 +102,13 @@ def sepia(input_text):
102
  pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
103
  pred_img = pred_img.astype(np.uint8)
104
 
105
- # Convert the image array to a format suitable for Gradio
106
  pred_img = Image.fromarray(pred_img)
107
 
108
  return pred_img
109
 
110
- # Define the Gradio interface
111
  iface = gr.Interface(fn=sepia, inputs="image", outputs="image")
112
 
113
- # Launch the Gradio app
114
- iface.launch()
 
15
  )
16
 
17
  def ade_palette():
18
+ """ADE20K ํŒ”๋ ˆํŠธ - ๊ฐ ํด๋ž˜์Šค๋ฅผ RGB ๊ฐ’์— ๋งคํ•‘ํ•ฉ๋‹ˆ๋‹ค."""
19
  return [
20
  [204, 87, 92],
21
  [112, 185, 212],
 
48
 
49
  def label_to_color_image(label):
50
  if label.ndim != 2:
51
+ raise ValueError("2-D ์ž…๋ ฅ ๋ผ๋ฒจ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.")
52
 
53
  if np.max(label) >= len(colormap):
54
+ raise ValueError("๋ผ๋ฒจ ๊ฐ’์ด ๋„ˆ๋ฌด ํฝ๋‹ˆ๋‹ค.")
55
  return colormap[label]
56
 
57
  def draw_plot(pred_img, seg):
 
76
  return fig
77
 
78
  def sepia(input_text):
79
+ # ์ž…๋ ฅ ํ…์ŠคํŠธ๊ฐ€ ์œ ํšจํ•œ ํŒŒ์ผ ๊ฒฝ๋กœ์ธ์ง€ ํ™•์ธ
80
  if not os.path.isfile(input_text):
81
+ return "์œ ํšจํ•˜์ง€ ์•Š์€ ํŒŒ์ผ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค. ์œ ํšจํ•œ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
82
 
83
+ # ์ž…๋ ฅ ํ…์ŠคํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œ (์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ๊ฐ€์ •)
84
  input_img = Image.open(input_text)
85
 
86
  inputs = feature_extractor(images=input_img, return_tensors="tf")
 
102
  pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
103
  pred_img = pred_img.astype(np.uint8)
104
 
105
+ # Gradio์— ์ ํ•ฉํ•œ ํ˜•์‹์œผ๋กœ ์ด๋ฏธ์ง€ ๋ฐฐ์—ด ๋ณ€ํ™˜
106
  pred_img = Image.fromarray(pred_img)
107
 
108
  return pred_img
109
 
110
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
111
  iface = gr.Interface(fn=sepia, inputs="image", outputs="image")
112
 
113
+ # Gradio ์•ฑ ์‹œ์ž‘
114
+ iface.launch()