VarunRavichander commited on
Commit
cff6f14
·
verified ·
1 Parent(s): a3a0d26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -54,18 +54,18 @@ def display_image(image_path):
54
  img_data = (img_data - np.min(img_data)) / (np.max(img_data) - np.min(img_data)) * 255
55
  img_data = img_data.astype(np.uint8)
56
 
57
- st.image(img_data, use_column_width=True)
58
  except Exception as rasterio_error:
59
  # Fall back to PIL
60
  try:
61
  img = Image.open(image_path)
62
- st.image(img, use_column_width=True)
63
  except Exception as pil_error:
64
  st.error(f"Failed to load image: {str(pil_error)}")
65
  else:
66
  # Use PIL for other formats
67
  img = Image.open(image_path)
68
- st.image(img, use_column_width=True)
69
  else:
70
  st.info(f"Image file not found: {image_path}")
71
  except Exception as e:
@@ -1560,7 +1560,7 @@ if st.session_state.app_mode == "SAR Colorization":
1560
  # Display legend
1561
  st.markdown("<h4 style='color: #a78bfa; margin-top: 20px;'>Land Cover Classes</h4>", unsafe_allow_html=True)
1562
  legend_img = create_legend()
1563
- st.image(legend_img, use_column_width=True)
1564
 
1565
  st.markdown("</div>", unsafe_allow_html=True)
1566
  else:
@@ -1632,7 +1632,7 @@ if st.session_state.app_mode == "SAR Colorization":
1632
 
1633
  # Display results with metrics
1634
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results with Ground Truth</h4>", unsafe_allow_html=True)
1635
- st.image(result_buf, use_column_width=True)
1636
 
1637
  # Calculate metrics
1638
  pred_class = np.argmax(prediction[0], axis=-1)
@@ -1668,7 +1668,7 @@ if st.session_state.app_mode == "SAR Colorization":
1668
  # Fall back to regular visualization without ground truth
1669
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
1670
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
1671
- st.image(result_img, use_column_width=True)
1672
 
1673
  # Add download button for the result
1674
  btn = st.download_button(
@@ -1682,7 +1682,7 @@ if st.session_state.app_mode == "SAR Colorization":
1682
  # Regular visualization without ground truth
1683
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
1684
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
1685
- st.image(result_img, use_column_width=True)
1686
 
1687
  # Add download button for the result
1688
  btn = st.download_button(
@@ -1927,7 +1927,7 @@ if st.session_state.app_mode == "SAR Colorization":
1927
  if 'accuracy' in img_data:
1928
  st.markdown(f"<p style='color: #a78bfa;'>Pixel Accuracy: {img_data['accuracy']:.2f}%</p>", unsafe_allow_html=True)
1929
 
1930
- st.image(img_data['result'], use_column_width=True)
1931
  st.markdown("<hr style='border-color: rgba(147, 51, 234, 0.3);'>", unsafe_allow_html=True)
1932
  else:
1933
  st.warning("No images were successfully processed.")
@@ -2057,7 +2057,7 @@ if st.session_state.app_mode == "SAR Colorization":
2057
  # Direct mapping if values are already 0-10
2058
  colored_label[label_data == class_idx] = color
2059
 
2060
- st.image(colored_label, use_column_width=True)
2061
  else:
2062
  # For regular image formats
2063
  display_image(label_path)
@@ -2107,7 +2107,7 @@ if st.session_state.app_mode == "SAR Colorization":
2107
 
2108
  # Display results with metrics
2109
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results with Ground Truth</h4>", unsafe_allow_html=True)
2110
- st.image(result_buf, use_column_width=True)
2111
 
2112
  # Calculate metrics
2113
  pred_class = np.argmax(prediction[0], axis=-1)
@@ -2142,7 +2142,7 @@ if st.session_state.app_mode == "SAR Colorization":
2142
  # Regular visualization without ground truth
2143
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
2144
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
2145
- st.image(result_img, use_column_width=True)
2146
 
2147
  # Add download button for the result
2148
  btn = st.download_button(
@@ -2389,30 +2389,30 @@ elif st.session_state.app_mode == "SAR to Optical Translation":
2389
 
2390
  with col1:
2391
  st.subheader("Original SAR Image")
2392
- st.image(sar_rgb, use_column_width=True)
2393
 
2394
  with col2:
2395
  st.subheader("Predicted Segmentation")
2396
- st.image(colored_pred, use_column_width=True)
2397
 
2398
  with col3:
2399
  st.subheader("Colorized SAR")
2400
- st.image(overlay, use_column_width=True)
2401
  else:
2402
  # Regular 3-panel visualization without ground truth
2403
  col1, col2, col3 = st.columns(3)
2404
 
2405
  with col1:
2406
  st.subheader("Original SAR Image")
2407
- st.image(sar_rgb, use_column_width=True)
2408
 
2409
  with col2:
2410
  st.subheader("Predicted Segmentation")
2411
- st.image(colored_pred, use_column_width=True)
2412
 
2413
  with col3:
2414
  st.subheader("Colorized SAR")
2415
- st.image(overlay, use_column_width=True)
2416
 
2417
  # Display colorized image if available
2418
  if colorized_img is not None:
@@ -2864,7 +2864,7 @@ elif st.session_state.app_mode == "SAR to Optical Translation":
2864
  st.markdown("</div>", unsafe_allow_html=True)
2865
 
2866
 
2867
- st.image(result['result'], use_column_width=True)
2868
 
2869
  # Add download button for individual result
2870
  col1, col2 = st.columns(2)
@@ -3084,20 +3084,20 @@ elif st.session_state.app_mode == "SAR to Optical Translation":
3084
 
3085
  with col1:
3086
  st.subheader("Original SAR Image")
3087
- st.image(sar_rgb, use_column_width=True)
3088
 
3089
  with col2:
3090
  st.subheader("Predicted Segmentation")
3091
- st.image(colored_pred, use_column_width=True)
3092
 
3093
  with col3:
3094
  st.subheader("Colorized SAR")
3095
  if colorized_img is not None:
3096
  # Convert from -1,1 to 0,1 range
3097
  colorized_display = (colorized_img * 0.5) + 0.5
3098
- st.image(colorized_display, use_column_width=True)
3099
  else:
3100
- st.image(overlay, use_column_width=True)
3101
 
3102
  # Add download buttons
3103
  col1, col2 = st.columns(2)
 
54
  img_data = (img_data - np.min(img_data)) / (np.max(img_data) - np.min(img_data)) * 255
55
  img_data = img_data.astype(np.uint8)
56
 
57
+ st.image(img_data, use_container_width=True)
58
  except Exception as rasterio_error:
59
  # Fall back to PIL
60
  try:
61
  img = Image.open(image_path)
62
+ st.image(img, use_container_width=True)
63
  except Exception as pil_error:
64
  st.error(f"Failed to load image: {str(pil_error)}")
65
  else:
66
  # Use PIL for other formats
67
  img = Image.open(image_path)
68
+ st.image(img, use_container_width=True)
69
  else:
70
  st.info(f"Image file not found: {image_path}")
71
  except Exception as e:
 
1560
  # Display legend
1561
  st.markdown("<h4 style='color: #a78bfa; margin-top: 20px;'>Land Cover Classes</h4>", unsafe_allow_html=True)
1562
  legend_img = create_legend()
1563
+ st.image(legend_img, use_container_width=True)
1564
 
1565
  st.markdown("</div>", unsafe_allow_html=True)
1566
  else:
 
1632
 
1633
  # Display results with metrics
1634
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results with Ground Truth</h4>", unsafe_allow_html=True)
1635
+ st.image(result_buf, use_container_width=True)
1636
 
1637
  # Calculate metrics
1638
  pred_class = np.argmax(prediction[0], axis=-1)
 
1668
  # Fall back to regular visualization without ground truth
1669
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
1670
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
1671
+ st.image(result_img, use_container_width=True)
1672
 
1673
  # Add download button for the result
1674
  btn = st.download_button(
 
1682
  # Regular visualization without ground truth
1683
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
1684
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
1685
+ st.image(result_img, use_container_width=True)
1686
 
1687
  # Add download button for the result
1688
  btn = st.download_button(
 
1927
  if 'accuracy' in img_data:
1928
  st.markdown(f"<p style='color: #a78bfa;'>Pixel Accuracy: {img_data['accuracy']:.2f}%</p>", unsafe_allow_html=True)
1929
 
1930
+ st.image(img_data['result'], use_container_width=True)
1931
  st.markdown("<hr style='border-color: rgba(147, 51, 234, 0.3);'>", unsafe_allow_html=True)
1932
  else:
1933
  st.warning("No images were successfully processed.")
 
2057
  # Direct mapping if values are already 0-10
2058
  colored_label[label_data == class_idx] = color
2059
 
2060
+ st.image(colored_label, use_container_width=True)
2061
  else:
2062
  # For regular image formats
2063
  display_image(label_path)
 
2107
 
2108
  # Display results with metrics
2109
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results with Ground Truth</h4>", unsafe_allow_html=True)
2110
+ st.image(result_buf, use_container_width=True)
2111
 
2112
  # Calculate metrics
2113
  pred_class = np.argmax(prediction[0], axis=-1)
 
2142
  # Regular visualization without ground truth
2143
  result_img = visualize_prediction(prediction, np.expand_dims(sar_normalized, axis=-1))
2144
  st.markdown("<h4 style='color: #a78bfa;'>Segmentation Results</h4>", unsafe_allow_html=True)
2145
+ st.image(result_img, use_container_width=True)
2146
 
2147
  # Add download button for the result
2148
  btn = st.download_button(
 
2389
 
2390
  with col1:
2391
  st.subheader("Original SAR Image")
2392
+ st.image(sar_rgb, use_container_width=True)
2393
 
2394
  with col2:
2395
  st.subheader("Predicted Segmentation")
2396
+ st.image(colored_pred, use_container_width=True)
2397
 
2398
  with col3:
2399
  st.subheader("Colorized SAR")
2400
+ st.image(overlay, use_container_width=True)
2401
  else:
2402
  # Regular 3-panel visualization without ground truth
2403
  col1, col2, col3 = st.columns(3)
2404
 
2405
  with col1:
2406
  st.subheader("Original SAR Image")
2407
+ st.image(sar_rgb, use_container_width=True)
2408
 
2409
  with col2:
2410
  st.subheader("Predicted Segmentation")
2411
+ st.image(colored_pred, use_container_width=True)
2412
 
2413
  with col3:
2414
  st.subheader("Colorized SAR")
2415
+ st.image(overlay, use_container_width=True)
2416
 
2417
  # Display colorized image if available
2418
  if colorized_img is not None:
 
2864
  st.markdown("</div>", unsafe_allow_html=True)
2865
 
2866
 
2867
+ st.image(result['result'], use_container_width=True)
2868
 
2869
  # Add download button for individual result
2870
  col1, col2 = st.columns(2)
 
3084
 
3085
  with col1:
3086
  st.subheader("Original SAR Image")
3087
+ st.image(sar_rgb, use_container_width=True)
3088
 
3089
  with col2:
3090
  st.subheader("Predicted Segmentation")
3091
+ st.image(colored_pred, use_container_width=True)
3092
 
3093
  with col3:
3094
  st.subheader("Colorized SAR")
3095
  if colorized_img is not None:
3096
  # Convert from -1,1 to 0,1 range
3097
  colorized_display = (colorized_img * 0.5) + 0.5
3098
+ st.image(colorized_display, use_container_width=True)
3099
  else:
3100
+ st.image(overlay, use_container_width=True)
3101
 
3102
  # Add download buttons
3103
  col1, col2 = st.columns(2)