Jen-Hung Wang commited on
Commit
50f5a57
·
1 Parent(s): 8a0447f

Add Tabview widget

Browse files
Files changed (1) hide show
  1. web_app.py +19 -6
web_app.py CHANGED
@@ -48,6 +48,7 @@ def predict_image(name, model, img, conf_threshold, iou_threshold):
48
  )
49
 
50
  cno_count = []
 
51
  cno_image = []
52
  file_name = []
53
 
@@ -74,6 +75,7 @@ def predict_image(name, model, img, conf_threshold, iou_threshold):
74
  cno_coor[j] = [x, y]
75
  cv2.rectangle(result.orig_img, (x1, y1), (x2, y2), (0, 255, 0), 1)
76
  im_array = result.orig_img
 
77
  cno_image.append([Image.fromarray(im_array[..., ::-1]), file_label])
78
  cno_count.append(cno)
79
  file_name.append(file_label)
@@ -115,11 +117,13 @@ def predict_image(name, model, img, conf_threshold, iou_threshold):
115
  # load data into a DataFrame object:
116
  cno_df = pd.DataFrame(data)
117
 
118
- return cno_df, cno_image
 
119
 
120
  def highlight_max(s, props=''):
121
  return np.where(s == np.nanmax(s.values), props, '')
122
 
 
123
  def highlight_df(df, data: gr.SelectData):
124
 
125
  styler = df.style.apply(lambda x: ['background: lightgreen'
@@ -140,10 +144,12 @@ def reset():
140
  conf_slider = 0.2
141
  iou_slider = 0.5
142
  analysis_results = []
 
143
  cno_gallery = []
144
  test_label = ""
145
 
146
- return name_textbox, gender_radio, age_slider, fitzpatrick, history, model_radio, input_files, conf_slider, iou_slider, analysis_results, cno_gallery, test_label
 
147
 
148
 
149
  with gr.Blocks(title="AFM AI Analysis", theme="default") as app:
@@ -171,19 +177,26 @@ with gr.Blocks(title="AFM AI Analysis", theme="default") as app:
171
  with gr.Column():
172
  analysis_results = gr.Dataframe(headers=["Files", "CNO Count"], interactive=False)
173
  # cno_label = gr.Label(label="Analysis Results")
174
- cno_gallery = gr.Gallery(label="Result", show_label=True, columns=3, object_fit="contain")
 
 
 
 
 
175
  test_label = gr.Label(label="Analysis Results")
176
  # cno_img = gr.Image(type="pil", label="Result")
177
 
178
  analyze_btn.click(
179
  fn=predict_image,
180
  inputs=[name_textbox, model_radio, input_files, conf_slider, iou_slider],
181
- outputs=[analysis_results, cno_gallery]
182
  )
183
 
184
  clear_btn.click(reset, outputs=[name_textbox, gender_radio, age_slider, fitzpatrick, history, model_radio,
185
- input_files, conf_slider, iou_slider, analysis_results, cno_gallery, test_label])
 
186
 
 
187
  cno_gallery.select(highlight_df, inputs=analysis_results, outputs=[test_label, analysis_results])
188
 
189
 
@@ -207,4 +220,4 @@ iface = gr.Interface(
207
 
208
  if __name__ == '__main__':
209
  # iface.launch()
210
- app.launch(share=True, auth=('user', 'admin'), auth_message="Enter your username and password")
 
48
  )
49
 
50
  cno_count = []
51
+ afm_image = []
52
  cno_image = []
53
  file_name = []
54
 
 
75
  cno_coor[j] = [x, y]
76
  cv2.rectangle(result.orig_img, (x1, y1), (x2, y2), (0, 255, 0), 1)
77
  im_array = result.orig_img
78
+ afm_image.append([img[idx], file_label])
79
  cno_image.append([Image.fromarray(im_array[..., ::-1]), file_label])
80
  cno_count.append(cno)
81
  file_name.append(file_label)
 
117
  # load data into a DataFrame object:
118
  cno_df = pd.DataFrame(data)
119
 
120
+ return cno_df, afm_image, cno_image
121
+
122
 
123
  def highlight_max(s, props=''):
124
  return np.where(s == np.nanmax(s.values), props, '')
125
 
126
+
127
  def highlight_df(df, data: gr.SelectData):
128
 
129
  styler = df.style.apply(lambda x: ['background: lightgreen'
 
144
  conf_slider = 0.2
145
  iou_slider = 0.5
146
  analysis_results = []
147
+ afm_gallery = []
148
  cno_gallery = []
149
  test_label = ""
150
 
151
+ return name_textbox, gender_radio, age_slider, fitzpatrick, history, model_radio, input_files, conf_slider, \
152
+ iou_slider, analysis_results, afm_gallery, cno_gallery, test_label
153
 
154
 
155
  with gr.Blocks(title="AFM AI Analysis", theme="default") as app:
 
177
  with gr.Column():
178
  analysis_results = gr.Dataframe(headers=["Files", "CNO Count"], interactive=False)
179
  # cno_label = gr.Label(label="Analysis Results")
180
+ with gr.Tab("AFM"):
181
+ afm_gallery = gr.Gallery(label="Result", show_label=True, columns=3, object_fit="contain")
182
+ with gr.Tab("CNO"):
183
+ cno_gallery = gr.Gallery(label="Result", show_label=True, columns=3, object_fit="contain")
184
+ # with gr.Tab("KDE"):
185
+ # kde_gallery = gr.Gallery(label="Result", show_label=True, columns=3, object_fit="contain")
186
  test_label = gr.Label(label="Analysis Results")
187
  # cno_img = gr.Image(type="pil", label="Result")
188
 
189
  analyze_btn.click(
190
  fn=predict_image,
191
  inputs=[name_textbox, model_radio, input_files, conf_slider, iou_slider],
192
+ outputs=[analysis_results, afm_gallery, cno_gallery]
193
  )
194
 
195
  clear_btn.click(reset, outputs=[name_textbox, gender_radio, age_slider, fitzpatrick, history, model_radio,
196
+ input_files, conf_slider, iou_slider, analysis_results, afm_gallery, cno_gallery,
197
+ test_label])
198
 
199
+ afm_gallery.select(highlight_df, inputs=analysis_results, outputs=[test_label, analysis_results])
200
  cno_gallery.select(highlight_df, inputs=analysis_results, outputs=[test_label, analysis_results])
201
 
202
 
 
220
 
221
  if __name__ == '__main__':
222
  # iface.launch()
223
+ app.launch(share=True, auth=[('jenhw', 'admin'), ('user', 'admin')], auth_message="Enter your username and password")