m7mdal7aj commited on
Commit
d7b49eb
·
verified ·
1 Parent(s): 330cb8a

Update my_model/utilities/st_utils.py

Browse files
Files changed (1) hide show
  1. my_model/utilities/st_utils.py +20 -2
my_model/utilities/st_utils.py CHANGED
@@ -90,9 +90,10 @@ class StateManager:
90
  if selected_method is not None:
91
  st.session_state['selected_method'] = selected_method
92
 
93
- def check_settings_changed(self, current_detection_model, current_confidence_level):
94
  return (st.session_state['model_settings']['detection_model'] != current_detection_model or
95
- st.session_state['model_settings']['confidence_level'] != current_confidence_level)
 
96
 
97
  def display_model_settings(self):
98
  st.write("### Current Model Settings:")
@@ -104,6 +105,23 @@ class StateManager:
104
  df = pd.DataFrame(data)
105
  st.table(df)
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
 
109
 
 
90
  if selected_method is not None:
91
  st.session_state['selected_method'] = selected_method
92
 
93
+ def check_settings_changed(self, current_selected_method, current_detection_model, current_confidence_level):
94
  return (st.session_state['model_settings']['detection_model'] != current_detection_model or
95
+ st.session_state['model_settings']['confidence_level'] != current_confidence_level
96
+ st.session_state['model_settings']['selected_method'] != current_selected_method)
97
 
98
  def display_model_settings(self):
99
  st.write("### Current Model Settings:")
 
105
  df = pd.DataFrame(data)
106
  st.table(df)
107
 
108
+ def is_model_loaded(self):
109
+ """Check if the model is loaded in the session state."""
110
+ return 'kbvqa' in st.session_state and st.session_state['kbvqa'] is not None
111
+
112
+
113
+ def reload_detection_model(self, detection_model, confidence_level):
114
+ """Reload only the detection model with new settings."""
115
+ try:
116
+ free_gpu_resources()
117
+ if self.is_model_loaded():
118
+ prepare_kbvqa_model(detection_model, only_reload_detection_model=True)
119
+ st.session_state['kbvqa'].detection_confidence = confidence_level
120
+ self.update_model_settings(detection_model, confidence_level)
121
+ free_gpu_resources()
122
+ except Exception as e:
123
+ st.error(f"Error reloading detection model: {e}")
124
+
125
 
126
 
127