zxcvb6958 commited on
Commit
edc21f8
·
1 Parent(s): 6321e70

update UI

Browse files
Files changed (1) hide show
  1. app.py +80 -83
app.py CHANGED
@@ -3,6 +3,7 @@ from PIL import Image
3
  import os
4
  import random
5
 
 
6
  ENHANCE_INPUT_DIR = "sr_input"
7
  ENHANCE_OUTPUT_DIR = "sr_output"
8
  ENHANCE_IMG_NAMES = [f"img_{i}.jpg" for i in range(1, 30)]
@@ -120,27 +121,47 @@ def diagnose_demo(img_name):
120
  return result_table, result_text, suggestion
121
 
122
  css = """
123
- .project-title {
124
- font-size: 38px; font-weight:bold; text-align:center; margin-bottom:40px;
125
- letter-spacing:2px;
 
 
 
 
 
126
  }
 
 
 
 
 
 
 
 
 
 
 
127
  .big-group {
128
  background: #F5F6F7 !important;
129
- border: 2px dashed #123A7A !important;
130
  border-radius: 18px !important;
131
  padding: 28px 18px 24px 18px !important;
132
- margin-top: 28px !important;
133
- margin-bottom: 18px !important;
134
- box-shadow: 0 3px 12px 2px rgba(60,64,67,.10);
135
  }
 
 
136
  .big-title {
137
  font-size: 25px;
138
  font-weight: bold;
139
  margin-bottom: 18px;
140
- color: #123A7A;
141
- text-align:center;
142
  letter-spacing: 1px;
 
143
  }
 
 
144
  .orange-btn {
145
  background: #FF7F1F !important;
146
  color: white !important;
@@ -164,31 +185,13 @@ css = """
164
  .button-row {
165
  margin-top: 8px;
166
  }
167
- .image-label-wrap {
168
- width: 300px;
169
- margin: 0 auto;
170
- display: flex;
171
- flex-direction: column;
172
- align-items: center;
173
- }
174
- .custom-image-label {
175
- background: #2bb7da;
176
- color: #fff;
177
- font-size: 16px;
178
- width: 100%;
179
- text-align: center;
180
- border-radius: 0 0 9px 9px;
181
- padding: 6px 0 4px 0;
182
- margin-top: 0;
183
- margin-bottom: 0;
184
- font-weight: 500;
185
- letter-spacing: 1px;
186
- }
187
  .gr-image, .gr-image-preview {
188
  border-radius: 10px !important;
189
  background: #fff !important;
190
  box-shadow: 0 2px 12px 0 rgba(60,64,67,.08);
191
  }
 
192
  .gr-box .gr-block.gr-group {
193
  box-shadow: none;
194
  border: none;
@@ -206,70 +209,64 @@ def reset_diag():
206
 
207
  with gr.Blocks(title="消化道疾病智能分析系统") as demo:
208
  gr.HTML(f"<style>{css}</style>")
209
- gr.HTML('<div class="project-title">消化道疾病智能分析系统</div>')
210
 
211
- # 第一行:增强&分割(包裹
212
  with gr.Row():
213
  # 图像增强
214
  with gr.Column():
215
- with gr.Group(elem_classes="big-group"):
216
- gr.HTML(f"<div class='big-title'>图像增强模块</div>")
217
- enhance_select = gr.Dropdown(choices=ENHANCE_CHOICES, value="请选择样例图片或者上传", label="选择样例", filterable=True)
218
- with gr.Row():
219
- with gr.Column():
220
- enhance_input_img = gr.Image(interactive=False, width=300, height=300, show_label=False)
221
- gr.HTML('<div class="custom-image-label">原始图片</div>', elem_id=None, elem_classes="image-label-wrap")
222
- with gr.Column():
223
- enhance_output_img = gr.Image(interactive=False, width=300, height=300, show_label=False)
224
- gr.HTML('<div class="custom-image-label">增强结果图片</div>', elem_id=None, elem_classes="image-label-wrap")
225
- with gr.Row(elem_classes="button-row"):
226
- enhance_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
227
- enhance_btn = gr.Button("点击执行图片增强", elem_classes="orange-btn")
228
- enhance_select.change(fn=show_enhance_input, inputs=enhance_select, outputs=enhance_input_img)
229
- enhance_btn.click(fn=enhance_demo, inputs=enhance_select, outputs=enhance_output_img)
230
- enhance_reset_btn.click(fn=reset_enhance, inputs=None, outputs=[enhance_select, enhance_input_img, enhance_output_img])
231
 
232
  # 图像分割
233
  with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  with gr.Group(elem_classes="big-group"):
235
- gr.HTML(f"<div class='big-title'>图像模块</div>")
236
- seg_select = gr.Dropdown(choices=SEG_CHOICES, value="请选择样例图片或者上传", label="选择样例图片", filterable=True)
237
  with gr.Row():
 
238
  with gr.Column():
239
- seg_input_img = gr.Image(interactive=False, width=300, height=300, show_label=False)
240
- gr.HTML('<div class="custom-image-label">输入图片</div>', elem_id=None, elem_classes="image-label-wrap")
 
 
 
 
 
241
  with gr.Column():
242
- seg_output_img = gr.Image(interactive=False, width=300, height=300, show_label=False)
243
- gr.HTML('<div class="custom-image-label">分割结果图片</div>', elem_id=None, elem_classes="image-label-wrap")
244
- with gr.Row(elem_classes="button-row"):
245
- seg_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
246
- seg_btn = gr.Button("点击执行分割", elem_classes="orange-btn")
247
- seg_select.change(fn=show_seg_input, inputs=seg_select, outputs=seg_input_img)
248
- seg_btn.click(fn=segment_demo, inputs=seg_select, outputs=seg_output_img)
249
- seg_reset_btn.click(fn=reset_seg, inputs=None, outputs=[seg_select, seg_input_img, seg_output_img])
250
-
251
- # 第二行:疾病诊断(大框包裹)
252
- with gr.Row():
253
- with gr.Group(elem_classes="big-group"):
254
- gr.HTML(f"<div class='big-title'>疾病分类模块</div>")
255
- with gr.Row():
256
- # 1. 输入图片+按钮
257
- with gr.Column():
258
- diag_select = gr.Dropdown(choices=DIAG_CHOICES, value="请选择样例图片或者上传", label="选择样例图片", filterable=True)
259
- diag_input_img = gr.Image(interactive=False, width=300, height=300, show_label=False)
260
- gr.HTML('<div class="custom-image-label">输入图片</div>', elem_id=None, elem_classes="image-label-wrap")
261
- with gr.Row(elem_classes="button-row"):
262
- diag_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
263
- diag_btn = gr.Button("点击执行诊断", elem_classes="orange-btn")
264
- diag_select.change(fn=show_diag_input, inputs=diag_select, outputs=diag_input_img)
265
- # 2. 结果表格
266
- with gr.Column():
267
- diag_table = gr.Dataframe(headers=["类别", "概率"])
268
- # 3. 预测与建议
269
- with gr.Column():
270
- diag_result = gr.Textbox(label="诊断结果")
271
- diag_suggestion = gr.Textbox(label="建议的治疗方案")
272
- diag_btn.click(fn=diagnose_demo, inputs=diag_select, outputs=[diag_table, diag_result, diag_suggestion])
273
- diag_reset_btn.click(fn=reset_diag, inputs=None, outputs=[diag_select, diag_input_img, diag_table, diag_result, diag_suggestion])
274
 
275
  demo.launch()
 
3
  import os
4
  import random
5
 
6
+ # ========== 配置图片路径 ==========
7
  ENHANCE_INPUT_DIR = "sr_input"
8
  ENHANCE_OUTPUT_DIR = "sr_output"
9
  ENHANCE_IMG_NAMES = [f"img_{i}.jpg" for i in range(1, 30)]
 
121
  return result_table, result_text, suggestion
122
 
123
  css = """
124
+ /* 主标题居中 */
125
+ #main-title {
126
+ text-align: center;
127
+ font-size: 34px;
128
+ font-weight: bold;
129
+ margin-bottom: 18px;
130
+ margin-top: 18px;
131
+ letter-spacing: 2px;
132
  }
133
+
134
+ /* 模块外层深蓝虚线圆角 */
135
+ .blue-dash-border {
136
+ border: 2.5px dashed #164fa0 !important;
137
+ border-radius: 22px !important;
138
+ padding: 0 !important;
139
+ margin-bottom: 32px !important;
140
+ box-sizing: border-box;
141
+ }
142
+
143
+ /* 模块内卡片背景、阴影、圆角等 */
144
  .big-group {
145
  background: #F5F6F7 !important;
146
+ border: 2px solid #e0e2e5 !important;
147
  border-radius: 18px !important;
148
  padding: 28px 18px 24px 18px !important;
149
+ margin: 16px !important;
150
+ box-shadow: 0 3px 12px 2px rgba(60,64,67,.14);
 
151
  }
152
+
153
+ /* 模块标题居中 */
154
  .big-title {
155
  font-size: 25px;
156
  font-weight: bold;
157
  margin-bottom: 18px;
158
+ margin-left: 0;
159
+ color: #343434;
160
  letter-spacing: 1px;
161
+ text-align: center;
162
  }
163
+
164
+ /* 按钮样式(宽度更小, 橙色无边框, 灰色有黑色边框) */
165
  .orange-btn {
166
  background: #FF7F1F !important;
167
  color: white !important;
 
185
  .button-row {
186
  margin-top: 8px;
187
  }
188
+ /* 图片圆角阴影 */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  .gr-image, .gr-image-preview {
190
  border-radius: 10px !important;
191
  background: #fff !important;
192
  box-shadow: 0 2px 12px 0 rgba(60,64,67,.08);
193
  }
194
+ /* 禁止卡片内嵌套group的边框和阴影 */
195
  .gr-box .gr-block.gr-group {
196
  box-shadow: none;
197
  border: none;
 
209
 
210
  with gr.Blocks(title="消化道疾病智能分析系统") as demo:
211
  gr.HTML(f"<style>{css}</style>")
212
+ gr.HTML("<div id='main-title'>消化道疾病智能分析系统</div>")
213
 
214
+ # 第一行:增强&分割(每个模块外再加蓝色虚线边框)
215
  with gr.Row():
216
  # 图像增强
217
  with gr.Column():
218
+ with gr.Group(elem_classes="blue-dash-border"):
219
+ with gr.Group(elem_classes="big-group"):
220
+ gr.HTML(f"<div class='big-title'>像增强模块</div>")
221
+ enhance_select = gr.Dropdown(choices=ENHANCE_CHOICES, value="请选择样例图片或者上传", label="选择样例图片", filterable=True)
222
+ with gr.Row():
223
+ enhance_input_img = gr.Image(label="原始图片", interactive=False, width=300, height=300)
224
+ enhance_output_img = gr.Image(label="增强结果图片", interactive=False, width=300, height=300)
225
+ with gr.Row(elem_classes="button-row"):
226
+ enhance_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
227
+ enhance_btn = gr.Button("点击执行图片增强", elem_classes="orange-btn")
228
+ enhance_select.change(fn=show_enhance_input, inputs=enhance_select, outputs=enhance_input_img)
229
+ enhance_btn.click(fn=enhance_demo, inputs=enhance_select, outputs=enhance_output_img)
230
+ enhance_reset_btn.click(fn=reset_enhance, inputs=None, outputs=[enhance_select, enhance_input_img, enhance_output_img])
 
 
 
231
 
232
  # 图像分割
233
  with gr.Column():
234
+ with gr.Group(elem_classes="blue-dash-border"):
235
+ with gr.Group(elem_classes="big-group"):
236
+ gr.HTML(f"<div class='big-title'>图像分割模块</div>")
237
+ seg_select = gr.Dropdown(choices=SEG_CHOICES, value="请选择样例图片或者上传", label="选择样例图片", filterable=True)
238
+ with gr.Row():
239
+ seg_input_img = gr.Image(label="输入图片", interactive=False, width=300, height=300)
240
+ seg_output_img = gr.Image(label="分割结果图片", interactive=False, width=300, height=300)
241
+ with gr.Row(elem_classes="button-row"):
242
+ seg_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
243
+ seg_btn = gr.Button("点击执行分割", elem_classes="orange-btn")
244
+ seg_select.change(fn=show_seg_input, inputs=seg_select, outputs=seg_input_img)
245
+ seg_btn.click(fn=segment_demo, inputs=seg_select, outputs=seg_output_img)
246
+ seg_reset_btn.click(fn=reset_seg, inputs=None, outputs=[seg_select, seg_input_img, seg_output_img])
247
+
248
+ # 第二行:疾病诊断(外层蓝色虚线,内层卡片)
249
+ with gr.Row():
250
+ with gr.Group(elem_classes="blue-dash-border"):
251
  with gr.Group(elem_classes="big-group"):
252
+ gr.HTML(f"<div class='big-title'>疾病模块</div>")
 
253
  with gr.Row():
254
+ # 1. 输入图片+按钮
255
  with gr.Column():
256
+ diag_select = gr.Dropdown(choices=DIAG_CHOICES, value="请选择样例图片或者上传", label="选择样例图片", filterable=True)
257
+ diag_input_img = gr.Image(label="输入图片", interactive=False, width=300, height=300)
258
+ with gr.Row(elem_classes="button-row"):
259
+ diag_reset_btn = gr.Button("Reset", elem_classes="gray-btn")
260
+ diag_btn = gr.Button("点击执行诊断", elem_classes="orange-btn")
261
+ diag_select.change(fn=show_diag_input, inputs=diag_select, outputs=diag_input_img)
262
+ # 2. 结果表格
263
  with gr.Column():
264
+ diag_table = gr.Dataframe(headers=["类别", "概率"])
265
+ # 3. 预测与建议
266
+ with gr.Column():
267
+ diag_result = gr.Textbox(label="诊断结果")
268
+ diag_suggestion = gr.Textbox(label="建议的治疗方案")
269
+ diag_btn.click(fn=diagnose_demo, inputs=diag_select, outputs=[diag_table, diag_result, diag_suggestion])
270
+ diag_reset_btn.click(fn=reset_diag, inputs=None, outputs=[diag_select, diag_input_img, diag_table, diag_result, diag_suggestion])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
  demo.launch()