alicelouis commited on
Commit
565d9ed
·
1 Parent(s): 55d7045

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -256,11 +256,11 @@ elif tabs == 'Upload': #and count_system () != 1:
256
  gray_scale = Image.fromarray(scaled_image)
257
  final_image = gray_scale.convert('RGB')
258
  final_image.resize((200,200))
259
- final_image.save(r'.\dcm_png\{}.png'.format(name_of_files[i]))
260
  feature_extractor = FeatureExtractor(model_name_or_path)
261
  model = LoadModel(model_name_or_path)
262
  if name_of_files[i].endswith('.dcm'):
263
- img = Image.open(r'.\dcm_png\{}.png'.format(name_of_files[i]))
264
  else:
265
  img = Image.open(uploaded_file[i])
266
  img_out = img.resize((224,224))
@@ -317,8 +317,8 @@ elif tabs == 'Upload': #and count_system () != 1:
317
  reshape_transform=reshape_transform_vit_huggingface,
318
  n_components=4,
319
  top_k=4))
320
- # dff_image.save(r".\save_images\dff_image.png")
321
- # gradcam_image.save(r".\save_images\gradcam_image.png")
322
  topK = print_top_categories(model, tensor_resized)
323
  df = pd.DataFrame.from_dict(topK, orient='index')
324
  list_to_be_sorted= []
@@ -353,7 +353,7 @@ elif tabs == 'Upload': #and count_system () != 1:
353
  new_width = 2 * width // 3
354
  cropped_image = image.crop((0, 0, new_width, height))
355
  cropped_image.save(r"./Normal/{}".format(image_path))
356
- #dff_image.save(r".\Normal\{}".format(name_of_files_new[i]))
357
  elif list_to_be_sorted[0]['name'] == "squamous.cell":
358
  dff_image.save(r"./Squamous cell carcinoma/{}".format(name_of_files_new[i]))
359
  image_path = name_of_files_new[i]
@@ -378,7 +378,7 @@ elif tabs == 'Upload': #and count_system () != 1:
378
  with col1:
379
  st.markdown("<h2 style='text-align: center; border: 2px solid #5370c6; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Adenocarcinoma </h2>".format(centered_style), unsafe_allow_html=True)
380
  # Add the second subheader to the second column
381
- folder_path = r".\Adenocarcinoma"
382
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
383
  # Display the images in a loop
384
  for i in range(0, len(image_files), 2):
@@ -397,7 +397,7 @@ elif tabs == 'Upload': #and count_system () != 1:
397
  count_classes.append("Adeno")
398
  with col2:
399
  st.markdown("<h2 style='text-align: center; border: 2px solid green; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Normal </h2>".format(centered_style), unsafe_allow_html=True)
400
- folder_path = r".\Normal"
401
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
402
  # Display the images in a loop
403
  for i in range(0, len(image_files), 2):
@@ -421,7 +421,7 @@ elif tabs == 'Upload': #and count_system () != 1:
421
 
422
  with col5:
423
  st.markdown("<h2 style='text-align: center; border: 2px solid orange; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Large cell carcinoma </h2>".format(centered_style), unsafe_allow_html=True)
424
- folder_path = r".\Large cell carcinoma"
425
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
426
  # Display the images in a loop
427
  for i in range(0, len(image_files), 2):
@@ -440,7 +440,7 @@ elif tabs == 'Upload': #and count_system () != 1:
440
  count_classes.append("Large")
441
  with col6:
442
  st.markdown("<h2 style='text-align: center; border: 2px solid #f16565; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Squamous cell carcinoma </h2>".format(centered_style), unsafe_allow_html=True)
443
- folder_path = r".\Squamous cell carcinoma"
444
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
445
  # Display the images in a loop
446
  for i in range(0, len(image_files), 2):
 
256
  gray_scale = Image.fromarray(scaled_image)
257
  final_image = gray_scale.convert('RGB')
258
  final_image.resize((200,200))
259
+ final_image.save(r'./dcm_png/{}.png'.format(name_of_files[i]))
260
  feature_extractor = FeatureExtractor(model_name_or_path)
261
  model = LoadModel(model_name_or_path)
262
  if name_of_files[i].endswith('.dcm'):
263
+ img = Image.open(r'./dcm_png/{}.png'.format(name_of_files[i]))
264
  else:
265
  img = Image.open(uploaded_file[i])
266
  img_out = img.resize((224,224))
 
317
  reshape_transform=reshape_transform_vit_huggingface,
318
  n_components=4,
319
  top_k=4))
320
+ # dff_image.save(r"./save_images/dff_image.png")
321
+ # gradcam_image.save(r"./save_images/gradcam_image.png")
322
  topK = print_top_categories(model, tensor_resized)
323
  df = pd.DataFrame.from_dict(topK, orient='index')
324
  list_to_be_sorted= []
 
353
  new_width = 2 * width // 3
354
  cropped_image = image.crop((0, 0, new_width, height))
355
  cropped_image.save(r"./Normal/{}".format(image_path))
356
+ #dff_image.save(r"./Normal/{}".format(name_of_files_new[i]))
357
  elif list_to_be_sorted[0]['name'] == "squamous.cell":
358
  dff_image.save(r"./Squamous cell carcinoma/{}".format(name_of_files_new[i]))
359
  image_path = name_of_files_new[i]
 
378
  with col1:
379
  st.markdown("<h2 style='text-align: center; border: 2px solid #5370c6; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Adenocarcinoma </h2>".format(centered_style), unsafe_allow_html=True)
380
  # Add the second subheader to the second column
381
+ folder_path = r"./Adenocarcinoma"
382
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
383
  # Display the images in a loop
384
  for i in range(0, len(image_files), 2):
 
397
  count_classes.append("Adeno")
398
  with col2:
399
  st.markdown("<h2 style='text-align: center; border: 2px solid green; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Normal </h2>".format(centered_style), unsafe_allow_html=True)
400
+ folder_path = r"./Normal"
401
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
402
  # Display the images in a loop
403
  for i in range(0, len(image_files), 2):
 
421
 
422
  with col5:
423
  st.markdown("<h2 style='text-align: center; border: 2px solid orange; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Large cell carcinoma </h2>".format(centered_style), unsafe_allow_html=True)
424
+ folder_path = r"./Large cell carcinoma"
425
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
426
  # Display the images in a loop
427
  for i in range(0, len(image_files), 2):
 
440
  count_classes.append("Large")
441
  with col6:
442
  st.markdown("<h2 style='text-align: center; border: 2px solid #f16565; border-radius: 5px; padding: 15px; background-color: white; color: black;' > Squamous cell carcinoma </h2>".format(centered_style), unsafe_allow_html=True)
443
+ folder_path = r"./Squamous cell carcinoma"
444
  image_files = [f for f in os.listdir(folder_path) if f.endswith('.png') or f.endswith('.jpg')]
445
  # Display the images in a loop
446
  for i in range(0, len(image_files), 2):