Hali5 commited on
Commit
8a7acf8
·
1 Parent(s): b124895

undone convert to unint8

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -22,7 +22,6 @@ LABELS = [
22
  "Colorectal Adenocarcinoma Epithelium",
23
  ]
24
 
25
-
26
  model = Predictor(n_labels=len(LABELS))
27
 
28
  model_file = hf_hub_download(
@@ -61,8 +60,10 @@ number_of_examples = len(labels)
61
  os.makedirs("ui_examples", exist_ok=True)
62
 
63
  for i in range(number_of_examples):
 
64
  img_array = images[i]
65
  val_img_arr = val_images[i]
 
66
  label_index = int(labels[i].item() if hasattr(labels[i], 'item') else labels[i])
67
  val_label_index = int(val_labels[i].item() if hasattr(val_labels[i], 'item') else val_labels[i])
68
 
@@ -72,8 +73,8 @@ for i in range(number_of_examples):
72
  file_path = f"ui_examples/sample_{i}.jpg"
73
  val_file_path = f"ui_examples/val_sample_{i}.jpg"
74
 
75
- Image.fromarray(img_array.astype("uint8"), "RGB").save(file_path)
76
- Image.fromarray(val_img_arr.astype("uint8"), "RGB").save(val_file_path)
77
 
78
  example_rows_test.append([file_path, truth_label_text])
79
  example_rows_val.append([val_file_path, val_truth_label_text])
@@ -123,7 +124,7 @@ with gradio.Blocks(css=custom_css) as demo:
123
  with gradio.Row():
124
  input_img = gradio.Image(height=512, width=512)
125
  with gradio.Column():
126
- output_lbl = gradio.Label(num_top_classes=3)
127
  btn = gradio.Button("Predict")
128
  btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
129
 
@@ -134,7 +135,7 @@ with gradio.Blocks(css=custom_css) as demo:
134
  with gradio.Column():
135
  input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
136
  truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
137
- output_lbl_ex = gradio.Label(num_top_classes=3, label="Model Prediction")
138
 
139
  gradio.Examples(
140
  examples=example_rows_val,
@@ -151,7 +152,7 @@ with gradio.Blocks(css=custom_css) as demo:
151
  with gradio.Column():
152
  input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
153
  truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
154
- output_lbl_ex = gradio.Label(num_top_classes=3, label="Model Prediction")
155
 
156
  gradio.Examples(
157
  examples=example_rows_test,
 
22
  "Colorectal Adenocarcinoma Epithelium",
23
  ]
24
 
 
25
  model = Predictor(n_labels=len(LABELS))
26
 
27
  model_file = hf_hub_download(
 
60
  os.makedirs("ui_examples", exist_ok=True)
61
 
62
  for i in range(number_of_examples):
63
+
64
  img_array = images[i]
65
  val_img_arr = val_images[i]
66
+
67
  label_index = int(labels[i].item() if hasattr(labels[i], 'item') else labels[i])
68
  val_label_index = int(val_labels[i].item() if hasattr(val_labels[i], 'item') else val_labels[i])
69
 
 
73
  file_path = f"ui_examples/sample_{i}.jpg"
74
  val_file_path = f"ui_examples/val_sample_{i}.jpg"
75
 
76
+ Image.fromarray(img_array, "RGB").save(file_path)
77
+ Image.fromarray(val_img_arr, "RGB").save(val_file_path)
78
 
79
  example_rows_test.append([file_path, truth_label_text])
80
  example_rows_val.append([val_file_path, val_truth_label_text])
 
124
  with gradio.Row():
125
  input_img = gradio.Image(height=512, width=512)
126
  with gradio.Column():
127
+ output_lbl = gradio.Label(num_top_classes=5)
128
  btn = gradio.Button("Predict")
129
  btn.click(fn=predict, inputs=input_img, outputs=output_lbl)
130
 
 
135
  with gradio.Column():
136
  input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
137
  truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
138
+ output_lbl_ex = gradio.Label(num_top_classes=5, label="Model Prediction")
139
 
140
  gradio.Examples(
141
  examples=example_rows_val,
 
152
  with gradio.Column():
153
  input_img_ex = gradio.Image(label="Selected Test Image", height=512, width=512)
154
  truth_box = gradio.Textbox(label="Ground Truth Label", interactive=False)
155
+ output_lbl_ex = gradio.Label(num_top_classes=5, label="Model Prediction")
156
 
157
  gradio.Examples(
158
  examples=example_rows_test,