Update my_model/utilities/state_manager.py
Browse files
my_model/utilities/state_manager.py
CHANGED
@@ -12,32 +12,15 @@ class StateManager:
|
|
12 |
def initialize_state(self):
|
13 |
if 'images_data' not in st.session_state:
|
14 |
st.session_state['images_data'] = {}
|
15 |
-
#if 'method' not in st.session_state:
|
16 |
-
# st.session_state['method'] = None
|
17 |
-
# if 'detection_model' not in st.session_state:
|
18 |
-
# st.session_state['detection_model'] = None
|
19 |
if 'kbvqa' not in st.session_state:
|
20 |
st.session_state['kbvqa'] = None
|
21 |
-
# if 'confidence_level' not in st.session_state:
|
22 |
-
# st.session_state['confidence_level'] = None
|
23 |
|
24 |
|
25 |
-
|
26 |
def set_up_widgets(self):
|
27 |
st.selectbox("Choose a method:", ["Fine-Tuned Model", "In-Context Learning (n-shots)"], index=0, key='method')
|
28 |
detection_model = st.selectbox("Choose a model for objects detection:", ["yolov5", "detic"], index=1, key='detection_model')
|
29 |
-
st.write('detection model')
|
30 |
-
st.write(st.session_state.detection_model)
|
31 |
default_confidence = 0.2 if st.session_state.detection_model == "yolov5" else 0.4
|
32 |
-
self.set_slider_value(text="Select minimum detection confidence level",
|
33 |
-
min_value=0.1,
|
34 |
-
max_value=0.9,
|
35 |
-
value=default_confidence,
|
36 |
-
step=0.1,
|
37 |
-
slider_key_name='confidence_level'
|
38 |
-
)
|
39 |
-
st.write("Detection Confidence")
|
40 |
-
st.write(st.session_state.confidence_level)
|
41 |
|
42 |
def set_slider_value(self, text, min_value, max_value, value, step, slider_key_name):
|
43 |
|
@@ -69,9 +52,19 @@ class StateManager:
|
|
69 |
st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
|
70 |
#self.update_model_settings(detection_model, confidence_level)
|
71 |
st.text("Model is ready for inference.")
|
|
|
|
|
|
|
72 |
free_gpu_resources()
|
73 |
except Exception as e:
|
74 |
-
st.error(f"Error loading model: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
def get_model(self):
|
77 |
"""Retrieve the KBVQA model from the session state."""
|
|
|
12 |
def initialize_state(self):
|
13 |
if 'images_data' not in st.session_state:
|
14 |
st.session_state['images_data'] = {}
|
|
|
|
|
|
|
|
|
15 |
if 'kbvqa' not in st.session_state:
|
16 |
st.session_state['kbvqa'] = None
|
|
|
|
|
17 |
|
18 |
|
|
|
19 |
def set_up_widgets(self):
|
20 |
st.selectbox("Choose a method:", ["Fine-Tuned Model", "In-Context Learning (n-shots)"], index=0, key='method')
|
21 |
detection_model = st.selectbox("Choose a model for objects detection:", ["yolov5", "detic"], index=1, key='detection_model')
|
|
|
|
|
22 |
default_confidence = 0.2 if st.session_state.detection_model == "yolov5" else 0.4
|
23 |
+
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def set_slider_value(self, text, min_value, max_value, value, step, slider_key_name):
|
26 |
|
|
|
52 |
st.session_state['kbvqa'].detection_confidence = st.session_state.confidence_level
|
53 |
#self.update_model_settings(detection_model, confidence_level)
|
54 |
st.text("Model is ready for inference.")
|
55 |
+
# Update the previous state with current session state values
|
56 |
+
st.session_state['previous_state'] = {'method': st.session_state.method, 'detection_model': st.session_state.detection_model, 'confidence_level': st.session_state.confidence_level}
|
57 |
+
|
58 |
free_gpu_resources()
|
59 |
except Exception as e:
|
60 |
+
st.error(f"Error loading model: {e}")
|
61 |
+
|
62 |
+
# Function to check if any session state values have changed
|
63 |
+
def has_state_changed(self):
|
64 |
+
for key in st.session_state['previous_state']:
|
65 |
+
if st.session_state[key] != st.session_state['previous_state'][key]:
|
66 |
+
return True # Found a change
|
67 |
+
else: return False # No changes found
|
68 |
|
69 |
def get_model(self):
|
70 |
"""Retrieve the KBVQA model from the session state."""
|