Update my_model/state_manager.py
Browse files
my_model/state_manager.py
CHANGED
@@ -3,7 +3,7 @@ import copy
|
|
3 |
from PIL import Image
|
4 |
import streamlit as st
|
5 |
from my_model.utilities.gen_utilities import free_gpu_resources
|
6 |
-
from my_model.KBVQA import KBVQA, prepare_kbvqa_model
|
7 |
|
8 |
|
9 |
|
@@ -130,16 +130,18 @@ class StateManager:
|
|
130 |
except Exception as e:
|
131 |
st.error(f"Error loading model: {e}")
|
132 |
|
133 |
-
def
|
134 |
try:
|
135 |
free_gpu_resources()
|
136 |
-
st.session_state['kbvqa'] =
|
137 |
st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
|
138 |
# Update the previous state with current session state values
|
139 |
st.session_state['previous_state'] = {'method': st.session_state.method, 'detection_model': st.session_state.detection_model, 'confidence_level': st.session_state.confidence_level}
|
140 |
st.session_state['model_loaded'] = True
|
|
|
141 |
except Exception as e:
|
142 |
st.error(f"Error loading model: {e}")
|
|
|
143 |
|
144 |
|
145 |
# Function to check if any session state values have changed
|
|
|
3 |
from PIL import Image
|
4 |
import streamlit as st
|
5 |
from my_model.utilities.gen_utilities import free_gpu_resources
|
6 |
+
from my_model.KBVQA import KBVQA, prepare_kbvqa_model
|
7 |
|
8 |
|
9 |
|
|
|
130 |
except Exception as e:
|
131 |
st.error(f"Error loading model: {e}")
|
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
|
138 |
# Update the previous state with current session state values
|
139 |
st.session_state['previous_state'] = {'method': st.session_state.method, 'detection_model': st.session_state.detection_model, 'confidence_level': st.session_state.confidence_level}
|
140 |
st.session_state['model_loaded'] = True
|
141 |
+
free_gpu_resources()
|
142 |
except Exception as e:
|
143 |
st.error(f"Error loading model: {e}")
|
144 |
+
free_gpu_resources()
|
145 |
|
146 |
|
147 |
# Function to check if any session state values have changed
|