Mingze commited on
Commit
ae93c58
·
1 Parent(s): 7c2ef80

Translate Space interface to English

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -62,7 +62,7 @@ def segment_street_scene(
62
  ):
63
  """Run semantic segmentation and return visual, tabular, and raw outputs."""
64
  if image is None:
65
- raise gr.Error("请先上传一张街景图片。")
66
 
67
  started_at = time.perf_counter()
68
  prepared_image = resize_for_output(image)
@@ -83,7 +83,7 @@ def segment_street_scene(
83
  class_map = class_map_tensor.cpu().numpy().astype(np.uint8)
84
  except Exception as exc:
85
  raise gr.Error(
86
- f"分割模型运行失败:{type(exc).__name__}: {exc}"
87
  ) from exc
88
 
89
  overlay, color_mask = render_segmentation(
@@ -109,8 +109,8 @@ def segment_street_scene(
109
  elapsed = time.perf_counter() - started_at
110
  visible_classes = len(np.unique(class_map))
111
  status = (
112
- f"完成 · {prepared_image.width}×{prepared_image.height} · "
113
- f"{visible_classes} 个街景类别 · {elapsed:.1f}s · "
114
  f"device={device.type}"
115
  )
116
 
@@ -135,8 +135,8 @@ with gr.Blocks(title="Street Scene Segmentation", theme=gr.themes.Soft(), css=CS
135
  gr.Markdown(
136
  """
137
  <div class="hero">
138
- <h1>🚦 街景语义分割</h1>
139
- <p>上传道路或城市街景,自动识别道路、人行道、建筑、植被、车辆、行人等 Cityscapes 类别。</p>
140
  <p class="muted">SegFormer-B0 · 19 street-scene classes · CPU/GPU adaptive</p>
141
  </div>
142
  """
@@ -146,53 +146,54 @@ with gr.Blocks(title="Street Scene Segmentation", theme=gr.themes.Soft(), css=CS
146
  with gr.Column(scale=5):
147
  image_input = gr.Image(
148
  type="pil",
149
- label="上传街景图片",
150
  height=470,
151
  sources=["upload", "clipboard", "webcam"],
152
  )
153
- with gr.Accordion("显示设置", open=False):
154
  opacity_input = gr.Slider(
155
  0.15,
156
  0.85,
157
  value=0.55,
158
  step=0.05,
159
- label="叠加透明度",
160
  )
161
  min_share_input = gr.Slider(
162
  0.0,
163
  5.0,
164
  value=0.1,
165
  step=0.1,
166
- label="类别表最小面积占比 (%)",
167
  )
168
  with gr.Row():
169
- run_button = gr.Button("开始分割", variant="primary", size="lg")
170
- clear_button = gr.ClearButton(value="清空", components=[image_input])
171
  status_output = gr.Markdown()
172
 
173
  with gr.Column(scale=7):
174
  with gr.Tabs():
175
- with gr.Tab("叠加结果"):
176
- overlay_output = gr.Image(label="语义分割叠加图", height=470)
177
- with gr.Tab("彩色掩码"):
178
- mask_output = gr.Image(label="Cityscapes 彩色掩码", height=470)
179
 
180
  table_output = gr.Dataframe(
181
- headers=["Class ID", "类别", "像素数", "面积占比 (%)", "颜色"],
182
  datatype=["number", "str", "number", "number", "str"],
183
- label="检测到的街景类别",
184
  interactive=False,
185
  wrap=True,
186
  )
187
  files_output = gr.File(
188
- label="下载结果(叠加图、彩色掩码、原始 Class ID、CSV",
189
  file_count="multiple",
190
  )
191
 
192
  gr.Markdown(
193
  """
194
- > 首次运行会从 Hugging Face 下载模型,之后复用容器缓存。超大图片会等比例缩放到最长边 2048px,
195
- > 以避免免费 Space 内存不足。该模型面向 Cityscapes 街景,不适合医学、遥感或室内场景。
 
196
  """
197
  )
198
 
 
62
  ):
63
  """Run semantic segmentation and return visual, tabular, and raw outputs."""
64
  if image is None:
65
+ raise gr.Error("Please upload a street-scene image first.")
66
 
67
  started_at = time.perf_counter()
68
  prepared_image = resize_for_output(image)
 
83
  class_map = class_map_tensor.cpu().numpy().astype(np.uint8)
84
  except Exception as exc:
85
  raise gr.Error(
86
+ f"Segmentation failed: {type(exc).__name__}: {exc}"
87
  ) from exc
88
 
89
  overlay, color_mask = render_segmentation(
 
109
  elapsed = time.perf_counter() - started_at
110
  visible_classes = len(np.unique(class_map))
111
  status = (
112
+ f"Done · {prepared_image.width}×{prepared_image.height} · "
113
+ f"{visible_classes} street-scene classes · {elapsed:.1f}s · "
114
  f"device={device.type}"
115
  )
116
 
 
135
  gr.Markdown(
136
  """
137
  <div class="hero">
138
+ <h1>🚦 Street Scene Semantic Segmentation</h1>
139
+ <p>Upload a road or urban street image to identify Cityscapes classes such as roads, sidewalks, buildings, vegetation, vehicles, and people.</p>
140
  <p class="muted">SegFormer-B0 · 19 street-scene classes · CPU/GPU adaptive</p>
141
  </div>
142
  """
 
146
  with gr.Column(scale=5):
147
  image_input = gr.Image(
148
  type="pil",
149
+ label="Upload a street-scene image",
150
  height=470,
151
  sources=["upload", "clipboard", "webcam"],
152
  )
153
+ with gr.Accordion("Display settings", open=False):
154
  opacity_input = gr.Slider(
155
  0.15,
156
  0.85,
157
  value=0.55,
158
  step=0.05,
159
+ label="Overlay opacity",
160
  )
161
  min_share_input = gr.Slider(
162
  0.0,
163
  5.0,
164
  value=0.1,
165
  step=0.1,
166
+ label="Minimum class area shown in table (%)",
167
  )
168
  with gr.Row():
169
+ run_button = gr.Button("Run segmentation", variant="primary", size="lg")
170
+ clear_button = gr.ClearButton(value="Clear", components=[image_input])
171
  status_output = gr.Markdown()
172
 
173
  with gr.Column(scale=7):
174
  with gr.Tabs():
175
+ with gr.Tab("Overlay"):
176
+ overlay_output = gr.Image(label="Segmentation overlay", height=470)
177
+ with gr.Tab("Color mask"):
178
+ mask_output = gr.Image(label="Cityscapes color mask", height=470)
179
 
180
  table_output = gr.Dataframe(
181
+ headers=["Class ID", "Class", "Pixels", "Area share (%)", "Color"],
182
  datatype=["number", "str", "number", "number", "str"],
183
+ label="Detected street-scene classes",
184
  interactive=False,
185
  wrap=True,
186
  )
187
  files_output = gr.File(
188
+ label="Download results (overlay, color mask, class IDs, and CSV)",
189
  file_count="multiple",
190
  )
191
 
192
  gr.Markdown(
193
  """
194
+ > The model is downloaded from Hugging Face on the first run and then reused from the container cache.
195
+ > Images are resized to a maximum side length of 2048 px to prevent memory issues.
196
+ > This Cityscapes model is intended for street scenes, not medical, remote-sensing, or indoor imagery.
197
  """
198
  )
199