Spaces:
Sleeping
Sleeping
Fixed empty image error
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ service_account_json = {
|
|
| 20 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/veytel-pulmoviz-pentool%40veytel-cloud-store.iam.gserviceaccount.com",
|
| 21 |
"universe_domain": "googleapis.com"
|
| 22 |
}
|
| 23 |
-
|
| 24 |
|
| 25 |
def set_min_dense_1(max_dense_0):
|
| 26 |
global scaled_thresh1
|
|
@@ -78,7 +78,8 @@ def upload_csv_to_gcs(csv_content, filename):
|
|
| 78 |
|
| 79 |
def new__cxr(max_dense_0, max_dense_1, max_dense_2):
|
| 80 |
global textured_cxr, lung_noised, max_val, cxr, mask, scaled_thresh1, scaled_thresh2, scaled_thresh3, image_id, index, count
|
| 81 |
-
|
|
|
|
| 82 |
if index > 3:
|
| 83 |
index = 1
|
| 84 |
image_id += 1
|
|
@@ -87,20 +88,19 @@ def new__cxr(max_dense_0, max_dense_1, max_dense_2):
|
|
| 87 |
|
| 88 |
csv_data = read_csv_from_gcs(user)
|
| 89 |
# write count, thresh1, thresh2, thresh3 to csv file
|
| 90 |
-
if count <
|
| 91 |
csv_content = ""
|
| 92 |
for row in csv_data:
|
| 93 |
csv_content += ",".join(row) + "\n"
|
| 94 |
-
|
|
|
|
| 95 |
filename = f"density_{user}.csv"
|
| 96 |
upload_csv_to_gcs(csv_content, filename)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
if (count > 30):
|
| 101 |
empty_image = np.zeros((256, 256), dtype=np.uint8)
|
| 102 |
label1.update(visible=False)
|
| 103 |
-
count = 1
|
| 104 |
image_id = 1
|
| 105 |
index = 1
|
| 106 |
csv_content = ""
|
|
@@ -108,10 +108,10 @@ def new__cxr(max_dense_0, max_dense_1, max_dense_2):
|
|
| 108 |
csv_content += ",".join(row) + "\n"
|
| 109 |
fieldnames = ['count', 'thresh_1', 'thresh_2', 'thresh_3']
|
| 110 |
csv_content += ",".join(fieldnames) + "\n"
|
| 111 |
-
csv_content += f"{count},{max_dense_0},{max_dense_1},{max_dense_2}\n"
|
| 112 |
filename = f"density_{user}.csv"
|
| 113 |
upload_csv_to_gcs(csv_content, filename)
|
| 114 |
-
return empty_image, empty_image, empty_image, empty_image, empty_image, empty_image, empty_image,
|
| 115 |
cxr_file = "cxr" + str(image_id) + "_cxr.png"
|
| 116 |
mask_file = "cxr" + str(image_id) + "_mask.png"
|
| 117 |
textured_cxr_file = "cxr" + str(image_id) + "_textured_" + str(index) + ".png"
|
|
@@ -135,7 +135,7 @@ def new__cxr(max_dense_0, max_dense_1, max_dense_2):
|
|
| 135 |
dense_1 = np.where(((textured_cxr < scaled_thresh2) & (textured_cxr >= scaled_thresh1)), textured_cxr, 0)
|
| 136 |
dense_2 = np.where(((textured_cxr < scaled_thresh3) & (textured_cxr >= scaled_thresh2)), textured_cxr, 0)
|
| 137 |
dense_3 = np.where(((textured_cxr < 255) & (textured_cxr >= scaled_thresh3)), textured_cxr, 0)
|
| 138 |
-
return cxr, textured_cxr, lung_noised, lung_noised, dense_0, dense_1, dense_2, dense_3, count
|
| 139 |
|
| 140 |
|
| 141 |
def create_csv():
|
|
@@ -148,8 +148,7 @@ def create_csv():
|
|
| 148 |
else:
|
| 149 |
for row in csv_data:
|
| 150 |
csv_content += ",".join(row) + "\n"
|
| 151 |
-
csv_content += f"{count},{thresh1},{thresh2},{thresh3}\n"
|
| 152 |
-
|
| 153 |
filename = f"density_{user}.csv"
|
| 154 |
upload_csv_to_gcs(csv_content, filename)
|
| 155 |
|
|
@@ -174,7 +173,6 @@ def change_vis():
|
|
| 174 |
|
| 175 |
|
| 176 |
with gr.Blocks() as demo:
|
| 177 |
-
count = 1
|
| 178 |
image_id = 1
|
| 179 |
index = 1
|
| 180 |
executable_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
| 20 |
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/veytel-pulmoviz-pentool%40veytel-cloud-store.iam.gserviceaccount.com",
|
| 21 |
"universe_domain": "googleapis.com"
|
| 22 |
}
|
| 23 |
+
count = 0
|
| 24 |
|
| 25 |
def set_min_dense_1(max_dense_0):
|
| 26 |
global scaled_thresh1
|
|
|
|
| 78 |
|
| 79 |
def new__cxr(max_dense_0, max_dense_1, max_dense_2):
|
| 80 |
global textured_cxr, lung_noised, max_val, cxr, mask, scaled_thresh1, scaled_thresh2, scaled_thresh3, image_id, index, count
|
| 81 |
+
if count >= 0:
|
| 82 |
+
index += 1
|
| 83 |
if index > 3:
|
| 84 |
index = 1
|
| 85 |
image_id += 1
|
|
|
|
| 88 |
|
| 89 |
csv_data = read_csv_from_gcs(user)
|
| 90 |
# write count, thresh1, thresh2, thresh3 to csv file
|
| 91 |
+
if count < 30:
|
| 92 |
csv_content = ""
|
| 93 |
for row in csv_data:
|
| 94 |
csv_content += ",".join(row) + "\n"
|
| 95 |
+
if count >0:
|
| 96 |
+
csv_content += f"{count},{max_dense_0},{max_dense_1},{max_dense_2}\n"
|
| 97 |
filename = f"density_{user}.csv"
|
| 98 |
upload_csv_to_gcs(csv_content, filename)
|
| 99 |
|
| 100 |
+
if (count >= 30):
|
|
|
|
|
|
|
| 101 |
empty_image = np.zeros((256, 256), dtype=np.uint8)
|
| 102 |
label1.update(visible=False)
|
| 103 |
+
count = -1
|
| 104 |
image_id = 1
|
| 105 |
index = 1
|
| 106 |
csv_content = ""
|
|
|
|
| 108 |
csv_content += ",".join(row) + "\n"
|
| 109 |
fieldnames = ['count', 'thresh_1', 'thresh_2', 'thresh_3']
|
| 110 |
csv_content += ",".join(fieldnames) + "\n"
|
| 111 |
+
#csv_content += f"{count},{max_dense_0},{max_dense_1},{max_dense_2}\n"
|
| 112 |
filename = f"density_{user}.csv"
|
| 113 |
upload_csv_to_gcs(csv_content, filename)
|
| 114 |
+
return empty_image, empty_image, empty_image, empty_image, empty_image, empty_image, empty_image, empty_image, 0
|
| 115 |
cxr_file = "cxr" + str(image_id) + "_cxr.png"
|
| 116 |
mask_file = "cxr" + str(image_id) + "_mask.png"
|
| 117 |
textured_cxr_file = "cxr" + str(image_id) + "_textured_" + str(index) + ".png"
|
|
|
|
| 135 |
dense_1 = np.where(((textured_cxr < scaled_thresh2) & (textured_cxr >= scaled_thresh1)), textured_cxr, 0)
|
| 136 |
dense_2 = np.where(((textured_cxr < scaled_thresh3) & (textured_cxr >= scaled_thresh2)), textured_cxr, 0)
|
| 137 |
dense_3 = np.where(((textured_cxr < 255) & (textured_cxr >= scaled_thresh3)), textured_cxr, 0)
|
| 138 |
+
return cxr, textured_cxr, lung_noised, lung_noised, dense_0, dense_1, dense_2, dense_3, count+1
|
| 139 |
|
| 140 |
|
| 141 |
def create_csv():
|
|
|
|
| 148 |
else:
|
| 149 |
for row in csv_data:
|
| 150 |
csv_content += ",".join(row) + "\n"
|
| 151 |
+
#csv_content += f"{count+1},{thresh1},{thresh2},{thresh3}\n"
|
|
|
|
| 152 |
filename = f"density_{user}.csv"
|
| 153 |
upload_csv_to_gcs(csv_content, filename)
|
| 154 |
|
|
|
|
| 173 |
|
| 174 |
|
| 175 |
with gr.Blocks() as demo:
|
|
|
|
| 176 |
image_id = 1
|
| 177 |
index = 1
|
| 178 |
executable_path = os.path.dirname(os.path.realpath(__file__))
|