jarondon82 commited on
Commit
81714ce
·
1 Parent(s): 86c9064

Simplificado el comportamiento de botones y reducido mensajes de confirmación para una experiencia más coherente

Browse files
Files changed (1) hide show
  1. utils/preprocessing_ui.py +35 -54
utils/preprocessing_ui.py CHANGED
@@ -41,31 +41,16 @@ def show_preprocessing_ui(image_service, img: np.ndarray) -> Dict[str, Any]:
41
  # Set default selection to improved image if not already set
42
  if "selected_image_mode" not in st.session_state:
43
  st.session_state["selected_image_mode"] = "improved"
 
44
 
45
  # Create an expander for the suggested improvements
46
  with st.expander("Suggested improvements available", expanded=True):
47
  # Create a two-column layout for original and improved images
48
  col1, col2 = st.columns(2)
49
 
50
- with col1:
51
- st.markdown("**Original Image**")
52
- st.image(img, use_column_width=True)
53
-
54
- # Determine button style based on current selection
55
- original_button_type = "secondary"
56
- if st.session_state["selected_image_mode"] == "original":
57
- original_button_type = "primary"
58
-
59
- # Botón "Continue with Original" debajo de la imagen original
60
- continue_original = st.button("Continue with Original",
61
- key="continue_original_btn",
62
- type=original_button_type,
63
- use_container_width=True)
64
-
65
- # Apply basic enhancements and display the improved version
66
  try:
67
- # Enhance the image - in a real application, this would use AI-based enhancements
68
- # For demonstration, we'll reduce brightness and contrast
69
  brightness_factor = 0.7 # reduce brightness by 30%
70
  contrast_factor = 0.7 # reduce contrast by 30%
71
 
@@ -81,43 +66,39 @@ def show_preprocessing_ui(image_service, img: np.ndarray) -> Dict[str, Any]:
81
  # Convert back to RGB for display
82
  improved_rgb = cv2.cvtColor(improved_bgr, cv2.COLOR_BGR2RGB)
83
 
 
 
 
 
 
84
  with col2:
85
  st.markdown("**Improved Image**")
86
  st.image(improved_rgb, use_column_width=True)
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  # Determine button style based on current selection
89
- improved_button_type = "secondary"
90
- if st.session_state["selected_image_mode"] == "improved":
91
- improved_button_type = "primary"
92
-
93
- # Botón "Use Improved Image" debajo de la imagen mejorada
94
- use_improved = st.button("Use Improved Image",
95
- key="use_improved_btn",
96
- type=improved_button_type,
97
- use_container_width=True)
98
 
99
- # Store the user's choice for later use
100
- if use_improved:
101
- st.session_state["use_improved_image"] = True
102
- st.session_state["selected_image_mode"] = "improved"
103
- # We'll use this modified image for facial detection
104
- st.session_state.current_image = improved_rgb
105
-
106
- # Display a success message with the selected image
107
- st.success("Using improved image for analysis.")
108
- elif continue_original:
109
- st.session_state["use_improved_image"] = False
110
- st.session_state["selected_image_mode"] = "original"
111
- st.session_state.current_image = img
112
-
113
- # Display a success message with the selected image
114
- st.info("Using original image for analysis.")
115
-
116
- # Show a message about the currently selected image
117
- if st.session_state["selected_image_mode"] == "improved":
118
- st.markdown("<div style='background-color: #1E3A8A; padding: 10px; border-radius: 5px; color: white;'><center>Using improved image for analysis.</center></div>", unsafe_allow_html=True)
119
- else:
120
- st.markdown("<div style='background-color: #1E3A8A; padding: 10px; border-radius: 5px; color: white;'><center>Using original image for analysis.</center></div>", unsafe_allow_html=True)
121
 
122
  # List the improvements made
123
  st.markdown("**Improvements applied:**")
@@ -144,8 +125,8 @@ def show_preprocessing_ui(image_service, img: np.ndarray) -> Dict[str, Any]:
144
  error_trace = traceback.format_exc()
145
  logger.error(f"Error in preprocessing UI: {str(e)}\n{error_trace}")
146
 
147
- # Show error to user
148
- st.error(f"Error during image enhancement: {str(e)}")
149
  result["success"] = False
150
  result["message"] = f"Error: {str(e)}"
151
 
@@ -156,8 +137,8 @@ def show_preprocessing_ui(image_service, img: np.ndarray) -> Dict[str, Any]:
156
  error_trace = traceback.format_exc()
157
  logger.error(f"Error in preprocessing UI: {str(e)}\n{error_trace}")
158
 
159
- # Show error to user
160
- st.error(f"Error preparing image preprocessing: {str(e)}")
161
 
162
  # Return error information
163
  return {
 
41
  # Set default selection to improved image if not already set
42
  if "selected_image_mode" not in st.session_state:
43
  st.session_state["selected_image_mode"] = "improved"
44
+ st.session_state["use_improved_image"] = True
45
 
46
  # Create an expander for the suggested improvements
47
  with st.expander("Suggested improvements available", expanded=True):
48
  # Create a two-column layout for original and improved images
49
  col1, col2 = st.columns(2)
50
 
51
+ # Apply basic enhancements and prepare the improved version
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  try:
53
+ # Standard enhancement parameters
 
54
  brightness_factor = 0.7 # reduce brightness by 30%
55
  contrast_factor = 0.7 # reduce contrast by 30%
56
 
 
66
  # Convert back to RGB for display
67
  improved_rgb = cv2.cvtColor(improved_bgr, cv2.COLOR_BGR2RGB)
68
 
69
+ # Display images
70
+ with col1:
71
+ st.markdown("**Original Image**")
72
+ st.image(img, use_column_width=True)
73
+
74
  with col2:
75
  st.markdown("**Improved Image**")
76
  st.image(improved_rgb, use_column_width=True)
77
+
78
+ # Use a single row for buttons with current selection visually indicated
79
+ col1, col2 = st.columns(2)
80
+
81
+ with col1:
82
+ # Determine button style based on current selection
83
+ original_type = "primary" if st.session_state["selected_image_mode"] == "original" else "secondary"
84
+ if st.button("Continue with Original", key="continue_original_btn", type=original_type, use_container_width=True):
85
+ st.session_state["selected_image_mode"] = "original"
86
+ st.session_state["use_improved_image"] = False
87
+ st.session_state.current_image = img
88
+ st.experimental_rerun()
89
+
90
+ with col2:
91
  # Determine button style based on current selection
92
+ improved_type = "primary" if st.session_state["selected_image_mode"] == "improved" else "secondary"
93
+ if st.button("Use Improved Image", key="use_improved_btn", type=improved_type, use_container_width=True):
94
+ st.session_state["selected_image_mode"] = "improved"
95
+ st.session_state["use_improved_image"] = True
96
+ st.session_state.current_image = improved_rgb
97
+ st.experimental_rerun()
 
 
 
98
 
99
+ # Single status message showing the current selection
100
+ message = f"Using {'improved' if st.session_state['selected_image_mode'] == 'improved' else 'original'} image for analysis."
101
+ st.info(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  # List the improvements made
104
  st.markdown("**Improvements applied:**")
 
125
  error_trace = traceback.format_exc()
126
  logger.error(f"Error in preprocessing UI: {str(e)}\n{error_trace}")
127
 
128
+ # Show error to user - simple message
129
+ st.error(f"Error processing image: {str(e)}")
130
  result["success"] = False
131
  result["message"] = f"Error: {str(e)}"
132
 
 
137
  error_trace = traceback.format_exc()
138
  logger.error(f"Error in preprocessing UI: {str(e)}\n{error_trace}")
139
 
140
+ # Show error to user - simple message
141
+ st.error(f"Error processing image")
142
 
143
  # Return error information
144
  return {