Spaces:
Running
Running
Update my_model/utilities/st_utils.py
Browse files- my_model/utilities/st_utils.py +42 -54
my_model/utilities/st_utils.py
CHANGED
@@ -1,6 +1,8 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from my_model.tabs.run_inference import run_inference
|
3 |
|
|
|
4 |
class UIManager:
|
5 |
def __init__(self):
|
6 |
self.tabs = {
|
@@ -40,7 +42,6 @@ class UIManager:
|
|
40 |
st.write("This is a Place Holder until the contents are uploaded.")
|
41 |
|
42 |
def display_run_inference(self):
|
43 |
-
|
44 |
run_inference()
|
45 |
|
46 |
def display_dissertation_report(self):
|
@@ -67,61 +68,48 @@ class UIManager:
|
|
67 |
|
68 |
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
-
class StateManager:
|
75 |
-
def __init__(self):
|
76 |
-
self.reset_state()
|
77 |
-
|
78 |
-
def reset_state(self):
|
79 |
-
"""Resets the state to its initial values."""
|
80 |
-
self.current_image = None
|
81 |
-
self.qa_history = []
|
82 |
-
self.analysis_done = False
|
83 |
-
self.answer_in_progress = False
|
84 |
-
self.caption = ""
|
85 |
-
self.detected_objects_str = ""
|
86 |
-
|
87 |
-
def set_current_image(self, image):
|
88 |
-
"""Sets the current image and resets relevant state variables."""
|
89 |
-
try:
|
90 |
-
self.current_image = image
|
91 |
-
self.qa_history = []
|
92 |
-
self.analysis_done = False
|
93 |
-
self.answer_in_progress = False
|
94 |
-
self.caption = ""
|
95 |
-
self.detected_objects_str = ""
|
96 |
-
except Exception as e:
|
97 |
-
print(f"Error setting current image: {e}")
|
98 |
-
|
99 |
-
def add_to_qa_history(self, question, answer):
|
100 |
-
"""Adds a question-answer pair to the history."""
|
101 |
-
if question and answer:
|
102 |
-
self.qa_history.append((question, answer))
|
103 |
-
else:
|
104 |
-
print("Invalid question or answer. Cannot add to history.")
|
105 |
-
|
106 |
-
def set_analysis_done(self, status=True):
|
107 |
-
"""Sets the analysis status."""
|
108 |
-
self.analysis_done = status
|
109 |
-
|
110 |
-
def set_answer_in_progress(self, status=True):
|
111 |
-
"""Sets the answer in progress status."""
|
112 |
-
self.answer_in_progress = status
|
113 |
-
|
114 |
-
def set_caption(self, caption):
|
115 |
-
"""Sets the image caption."""
|
116 |
-
if caption:
|
117 |
-
self.caption = caption
|
118 |
-
else:
|
119 |
-
print("Invalid caption. Cannot set caption.")
|
120 |
-
|
121 |
-
def set_detected_objects_str(self, detected_objects_str):
|
122 |
-
"""Sets the detected objects string."""
|
123 |
-
if detected_objects_str:
|
124 |
-
self.detected_objects_str = detected_objects_str
|
125 |
-
else:
|
126 |
-
print("Invalid detected objects string. Cannot set detected objects.")
|
127 |
|
|
|
1 |
+
import pandas as pd
|
2 |
import streamlit as st
|
3 |
from my_model.tabs.run_inference import run_inference
|
4 |
|
5 |
+
|
6 |
class UIManager:
|
7 |
def __init__(self):
|
8 |
self.tabs = {
|
|
|
42 |
st.write("This is a Place Holder until the contents are uploaded.")
|
43 |
|
44 |
def display_run_inference(self):
|
|
|
45 |
run_inference()
|
46 |
|
47 |
def display_dissertation_report(self):
|
|
|
68 |
|
69 |
|
70 |
|
71 |
+
class StateManager:
|
72 |
+
def __init__(self):
|
73 |
+
self.initialize_state()
|
74 |
+
|
75 |
+
def initialize_state(self):
|
76 |
+
if 'images_data' not in st.session_state:
|
77 |
+
st.session_state['images_data'] = {}
|
78 |
+
if 'model_settings' not in st.session_state:
|
79 |
+
st.session_state['model_settings'] = {'detection_model': None, 'confidence_level': None}
|
80 |
+
if 'kbvqa' not in st.session_state:
|
81 |
+
st.session_state['kbvqa'] = None
|
82 |
+
if 'selected_method' not in st.session_state:
|
83 |
+
st.session_state['selected_method'] = None
|
84 |
+
|
85 |
+
def update_model_settings(self, detection_model=None, confidence_level=None, selected_method=None):
|
86 |
+
if detection_model is not None:
|
87 |
+
st.session_state['model_settings']['detection_model'] = detection_model
|
88 |
+
if confidence_level is not None:
|
89 |
+
st.session_state['model_settings']['confidence_level'] = confidence_level
|
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:")
|
99 |
+
st.table(pd.DataFrame(st.session_state['model_settings'], index=[0]))
|
100 |
+
|
101 |
+
def display_session_state(self):
|
102 |
+
st.write("### Current Session State:")
|
103 |
+
data = [{'Key': key, 'Value': str(value)} for key, value in st.session_state.items()]
|
104 |
+
df = pd.DataFrame(data)
|
105 |
+
st.table(df)
|
106 |
+
|
107 |
+
|
108 |
+
|
109 |
+
|
110 |
+
|
111 |
|
112 |
|
113 |
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|