Spaces:
Running
Running
Update my_model/state_manager.py
Browse files- my_model/state_manager.py +20 -1
my_model/state_manager.py
CHANGED
@@ -29,6 +29,10 @@ class StateManager:
|
|
29 |
st.session_state['model_loaded'] = False
|
30 |
if 'loading_in_progress' not in st.session_state:
|
31 |
st.session_state['loading_in_progress'] = False
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
|
@@ -132,6 +136,8 @@ class StateManager:
|
|
132 |
|
133 |
def force_reload_model(self):
|
134 |
try:
|
|
|
|
|
135 |
free_gpu_resources()
|
136 |
st.session_state['kbvqa'] = prepare_kbvqa_model(force_reload=True)
|
137 |
st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
|
@@ -140,9 +146,22 @@ class StateManager:
|
|
140 |
st.session_state['model_loaded'] = True
|
141 |
free_gpu_resources()
|
142 |
except Exception as e:
|
143 |
-
st.error(f"Error
|
144 |
free_gpu_resources()
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
# Function to check if any session state values have changed
|
148 |
def has_state_changed(self):
|
|
|
29 |
st.session_state['model_loaded'] = False
|
30 |
if 'loading_in_progress' not in st.session_state:
|
31 |
st.session_state['loading_in_progress'] = False
|
32 |
+
if 'load_button_clicked' not in st.session_state:
|
33 |
+
st.session_state['load_button_clicked'] = False
|
34 |
+
if 'force_reload_button_clicked' not in st.session_state:
|
35 |
+
st.session_state['force_reload_button_clicked'] = False
|
36 |
|
37 |
|
38 |
|
|
|
136 |
|
137 |
def force_reload_model(self):
|
138 |
try:
|
139 |
+
self.delete_model()
|
140 |
+
self.initialize_state()
|
141 |
free_gpu_resources()
|
142 |
st.session_state['kbvqa'] = prepare_kbvqa_model(force_reload=True)
|
143 |
st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
|
|
|
146 |
st.session_state['model_loaded'] = True
|
147 |
free_gpu_resources()
|
148 |
except Exception as e:
|
149 |
+
st.error(f"Error reloading model: {e}")
|
150 |
free_gpu_resources()
|
151 |
|
152 |
+
def delete_model(self):
|
153 |
+
"""
|
154 |
+
Forces a reload of all models, freeing up GPU resources. This method deletes the current models and calls `free_gpu_resources`.
|
155 |
+
"""
|
156 |
+
|
157 |
+
free_gpu_resources()
|
158 |
+
|
159 |
+
if st.session_state['kbvqa'] is not None:
|
160 |
+
del st.session_state['kbvqa']
|
161 |
+
st.write('Model deleted')
|
162 |
+
free_gpu_resources()
|
163 |
+
free_gpu_resources()
|
164 |
+
|
165 |
|
166 |
# Function to check if any session state values have changed
|
167 |
def has_state_changed(self):
|