Spaces:
Sleeping
Sleeping
Update my_model/tabs/run_inference.py
Browse files
my_model/tabs/run_inference.py
CHANGED
@@ -48,10 +48,10 @@ class InferenceRunner(StateManager):
|
|
48 |
|
49 |
# Display and interact with each uploaded/selected image
|
50 |
for image_key, image_data in self.get_images_data().items():
|
51 |
-
col2.image(image_data['image'], caption=f'Uploaded Image: {image_key[-11:]}', use_column_width=True)
|
52 |
if not image_data['analysis_done']:
|
53 |
self.col2.text("Cool image, please click 'Analyze Image'..")
|
54 |
-
if col2.button('Analyze Image', key=f'analyze_{image_key}'):
|
55 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
|
56 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
57 |
|
@@ -59,8 +59,8 @@ class InferenceRunner(StateManager):
|
|
59 |
qa_history = image_data.get('qa_history', [])
|
60 |
|
61 |
if image_data['analysis_done']:
|
62 |
-
question = col2.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
|
63 |
-
if col2.button('Get Answer', key=f'answer_{image_key}'):
|
64 |
if question not in [q for q, _ in qa_history]:
|
65 |
answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
|
66 |
self.add_to_qa_history(image_key, question, answer)
|
@@ -77,15 +77,15 @@ class InferenceRunner(StateManager):
|
|
77 |
self.set_up_widgets()
|
78 |
st.session_state['settings_changed'] = self.has_state_changed()
|
79 |
if st.session_state['settings_changed']:
|
80 |
-
col1.warning("Model settings have changed, please reload the model, this will take a second .. ")
|
81 |
|
82 |
st.session_state.button_label = "Reload Model" if self.is_model_loaded() and self.settings_changed else "Load Model"
|
83 |
|
84 |
if st.session_state.method == "Fine-Tuned Model":
|
85 |
-
if col1.button(st.session_state.button_label):
|
86 |
if st.session_state.button_label == "Load Model":
|
87 |
if self.is_model_loaded():
|
88 |
-
col1.text("Model already loaded and no settings were changed:)")
|
89 |
else:
|
90 |
self.load_model()
|
91 |
else:
|
@@ -94,4 +94,4 @@ class InferenceRunner(StateManager):
|
|
94 |
if self.is_model_loaded() and st.session_state.kbvqa.all_models_loaded:
|
95 |
self.image_qa_app(self.get_model())
|
96 |
else:
|
97 |
-
col1.warning(f'Model using {st.session_state.method} is not deployed yet, will be ready later.')
|
|
|
48 |
|
49 |
# Display and interact with each uploaded/selected image
|
50 |
for image_key, image_data in self.get_images_data().items():
|
51 |
+
self.col2.image(image_data['image'], caption=f'Uploaded Image: {image_key[-11:]}', use_column_width=True)
|
52 |
if not image_data['analysis_done']:
|
53 |
self.col2.text("Cool image, please click 'Analyze Image'..")
|
54 |
+
if self.col2.button('Analyze Image', key=f'analyze_{image_key}'):
|
55 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
|
56 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
57 |
|
|
|
59 |
qa_history = image_data.get('qa_history', [])
|
60 |
|
61 |
if image_data['analysis_done']:
|
62 |
+
question = self.col2.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
|
63 |
+
if self.col2.button('Get Answer', key=f'answer_{image_key}'):
|
64 |
if question not in [q for q, _ in qa_history]:
|
65 |
answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
|
66 |
self.add_to_qa_history(image_key, question, answer)
|
|
|
77 |
self.set_up_widgets()
|
78 |
st.session_state['settings_changed'] = self.has_state_changed()
|
79 |
if st.session_state['settings_changed']:
|
80 |
+
self.col1.warning("Model settings have changed, please reload the model, this will take a second .. ")
|
81 |
|
82 |
st.session_state.button_label = "Reload Model" if self.is_model_loaded() and self.settings_changed else "Load Model"
|
83 |
|
84 |
if st.session_state.method == "Fine-Tuned Model":
|
85 |
+
if self.col1.button(st.session_state.button_label):
|
86 |
if st.session_state.button_label == "Load Model":
|
87 |
if self.is_model_loaded():
|
88 |
+
self.col1.text("Model already loaded and no settings were changed:)")
|
89 |
else:
|
90 |
self.load_model()
|
91 |
else:
|
|
|
94 |
if self.is_model_loaded() and st.session_state.kbvqa.all_models_loaded:
|
95 |
self.image_qa_app(self.get_model())
|
96 |
else:
|
97 |
+
self.col1.warning(f'Model using {st.session_state.method} is not deployed yet, will be ready later.')
|