Spaces:
Running
Running
Update my_model/tabs/run_inference.py
Browse files
my_model/tabs/run_inference.py
CHANGED
@@ -58,7 +58,6 @@ class InferenceRunner(StateManager):
|
|
58 |
with self.col2:
|
59 |
for image_key, image_data in self.get_images_data().items():
|
60 |
with st.container():
|
61 |
-
self.display_session_state()
|
62 |
nested_col21, nested_col22 = st.columns([0.65, 0.35])
|
63 |
image_for_display = self.resize_image(image_data['image'], 600)
|
64 |
nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
|
@@ -95,9 +94,33 @@ class InferenceRunner(StateManager):
|
|
95 |
def display_message(self, message, warning=False, write=False, text=False):
|
96 |
pass
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
def run_inference(self):
|
|
|
|
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
self.set_up_widgets()
|
102 |
load_fine_tuned_model = False
|
103 |
fine_tuned_model_already_loaded = False
|
@@ -137,7 +160,7 @@ class InferenceRunner(StateManager):
|
|
137 |
t1=time.time()
|
138 |
free_gpu_resources()
|
139 |
self.load_model()
|
140 |
-
st.session_state['time_taken_to_load_model'] = time.time()-t1
|
141 |
st.session_state['loading_in_progress'] = False
|
142 |
|
143 |
elif fine_tuned_model_already_loaded:
|
@@ -154,7 +177,7 @@ class InferenceRunner(StateManager):
|
|
154 |
free_gpu_resources()
|
155 |
t1=time.time()
|
156 |
self.force_reload_model()
|
157 |
-
st.session_state['time_taken_to_load_model'] = time.time()-t1
|
158 |
st.session_state['loading_in_progress'] = False
|
159 |
st.session_state['model_loaded'] = True
|
160 |
|
|
|
58 |
with self.col2:
|
59 |
for image_key, image_data in self.get_images_data().items():
|
60 |
with st.container():
|
|
|
61 |
nested_col21, nested_col22 = st.columns([0.65, 0.35])
|
62 |
image_for_display = self.resize_image(image_data['image'], 600)
|
63 |
nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
|
|
|
94 |
def display_message(self, message, warning=False, write=False, text=False):
|
95 |
pass
|
96 |
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
@st.experimental_memo(show_spinner=False)
|
102 |
+
def trigger_rerun(self):
|
103 |
+
pass # No need for any specific code here
|
104 |
+
|
105 |
+
|
106 |
+
|
107 |
+
|
108 |
|
109 |
def run_inference(self):
|
110 |
+
|
111 |
+
|
112 |
|
113 |
+
if st.button("Re-run App"):
|
114 |
+
self.trigger_rerun(None) # Force a re-run
|
115 |
+
else:
|
116 |
+
# Trigger re-run every 5 seconds (example)
|
117 |
+
if time.time() - st.session_state.get("last_rerun", 0) > 5:
|
118 |
+
self.trigger_rerun(None)
|
119 |
+
st.session_state["last_rerun"] = time.time()
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
self.set_up_widgets()
|
125 |
load_fine_tuned_model = False
|
126 |
fine_tuned_model_already_loaded = False
|
|
|
160 |
t1=time.time()
|
161 |
free_gpu_resources()
|
162 |
self.load_model()
|
163 |
+
st.session_state['time_taken_to_load_model'] = int(time.time()-t1)
|
164 |
st.session_state['loading_in_progress'] = False
|
165 |
|
166 |
elif fine_tuned_model_already_loaded:
|
|
|
177 |
free_gpu_resources()
|
178 |
t1=time.time()
|
179 |
self.force_reload_model()
|
180 |
+
st.session_state['time_taken_to_load_model'] = int(time.time()-t1)
|
181 |
st.session_state['loading_in_progress'] = False
|
182 |
st.session_state['model_loaded'] = True
|
183 |
|