m7mdal7aj commited on
Commit
2b3b1de
1 Parent(s): c70ac46

Update my_model/state_manager.py

Browse files
Files changed (1) hide show
  1. my_model/state_manager.py +8 -5
my_model/state_manager.py CHANGED
@@ -41,11 +41,11 @@ class StateManager:
41
  """
42
  Sets up user interface widgets for selecting models, settings, and displaying model settings conditionally.
43
  """
44
-
45
- self.col1.selectbox("Choose a method:", ["Fine-Tuned Model", "In-Context Learning (n-shots)"], index=0, key='method')
46
- detection_model = self.col1.selectbox("Choose a model for objects detection:", ["yolov5", "detic"], index=1, key='detection_model')
47
  default_confidence = 0.2 if st.session_state.detection_model == "yolov5" else 0.4
48
- self.set_slider_value(text="Select minimum detection confidence level", min_value=0.1, max_value=0.9, value=default_confidence, step=0.1, slider_key_name='confidence_level', col=self.col1)
49
 
50
  # Conditional display of model settings
51
 
@@ -56,7 +56,7 @@ class StateManager:
56
 
57
 
58
 
59
- def set_slider_value(self, text, min_value, max_value, value, step, slider_key_name, col=None):
60
  """
61
  Creates a slider widget with the specified parameters, optionally placing it in a specific column.
62
 
@@ -123,14 +123,17 @@ class StateManager:
123
  """
124
 
125
  try:
 
126
  free_gpu_resources()
127
  st.session_state['kbvqa'] = prepare_kbvqa_model()
128
  st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
129
  # Update the previous state with current session state values
130
  st.session_state['previous_state'] = {'method': st.session_state.method, 'detection_model': st.session_state.detection_model, 'confidence_level': st.session_state.confidence_level}
131
  st.session_state['model_loaded'] = True
 
132
  st.session_state['button_label'] = "Reload Model"
133
  free_gpu_resources()
 
134
  except Exception as e:
135
  st.error(f"Error loading model: {e}")
136
 
 
41
  """
42
  Sets up user interface widgets for selecting models, settings, and displaying model settings conditionally.
43
  """
44
+ disabled=st.session_state['loading_in_progress']
45
+ self.col1.selectbox("Choose a method:", ["Fine-Tuned Model", "In-Context Learning (n-shots)"], index=0, key='method', disabled=disabled)
46
+ detection_model = self.col1.selectbox("Choose a model for objects detection:", ["yolov5", "detic"], index=1, key='detection_model', disabled=disabled)
47
  default_confidence = 0.2 if st.session_state.detection_model == "yolov5" else 0.4
48
+ self.set_slider_value(text="Select minimum detection confidence level", min_value=0.1, max_value=0.9, value=default_confidence, step=0.1, slider_key_name='confidence_level', col=self.col1, disabled=disabled)
49
 
50
  # Conditional display of model settings
51
 
 
56
 
57
 
58
 
59
+ def set_slider_value(self, text, min_value, max_value, value, step, slider_key_name, col=None, disabled=False):
60
  """
61
  Creates a slider widget with the specified parameters, optionally placing it in a specific column.
62
 
 
123
  """
124
 
125
  try:
126
+ st.session_state['loading_in_progress'] = True
127
  free_gpu_resources()
128
  st.session_state['kbvqa'] = prepare_kbvqa_model()
129
  st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
130
  # Update the previous state with current session state values
131
  st.session_state['previous_state'] = {'method': st.session_state.method, 'detection_model': st.session_state.detection_model, 'confidence_level': st.session_state.confidence_level}
132
  st.session_state['model_loaded'] = True
133
+ st.session_state['loading_in_progress'] = False
134
  st.session_state['button_label'] = "Reload Model"
135
  free_gpu_resources()
136
+
137
  except Exception as e:
138
  st.error(f"Error loading model: {e}")
139