Update my_model/tabs/run_inference.py
Browse files
my_model/tabs/run_inference.py
CHANGED
@@ -76,12 +76,14 @@ class InferenceRunner(StateManager):
|
|
76 |
if not image_data['analysis_done'] or self.settings_changed or self.confidance_change:
|
77 |
nested_col22.text("Please click 'Analyze Image'..")
|
78 |
analyze_button_key = f'analyze_{image_key}_{st.session_state.detection_model}_{st.session_state.confidence_level}'
|
79 |
-
if
|
80 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'])
|
81 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
82 |
st.session_state['loading_in_progress'] = False
|
83 |
|
84 |
def handle_question_answering(self, image_key, image_data, nested_col22):
|
|
|
|
|
85 |
if image_data['analysis_done']:
|
86 |
self.display_question_answering_interface(image_key, image_data, nested_col22)
|
87 |
|
@@ -93,8 +95,13 @@ class InferenceRunner(StateManager):
|
|
93 |
question = custom_question if selected_question == "Custom question..." else selected_question
|
94 |
self.process_question(image_key, question, image_data, nested_col22)
|
95 |
|
96 |
-
def process_question(self, image_key, question, image_data, nested_col22):
|
97 |
qa_history = image_data.get('qa_history', [])
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
if question and (question not in [q for q, _, _ in qa_history] or self.settings_changed or self.confidance_change):
|
99 |
if nested_col22.button('Get Answer', key=f'answer_{image_key}', disabled=self.is_widget_disabled):
|
100 |
answer, prompt_length = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question)
|
@@ -109,8 +116,6 @@ class InferenceRunner(StateManager):
|
|
109 |
for image_key, image_data in self.get_images_data().items():
|
110 |
with st.container():
|
111 |
nested_col21, nested_col22 = st.columns([0.65, 0.35])
|
112 |
-
image_for_display = self.resize_image(image_data['image'], 600)
|
113 |
-
nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
|
114 |
self.display_image_and_analysis(image_key, image_data, nested_col21, nested_col22)
|
115 |
self.handle_question_answering(image_key, image_data, nested_col22)
|
116 |
|
|
|
76 |
if not image_data['analysis_done'] or self.settings_changed or self.confidance_change:
|
77 |
nested_col22.text("Please click 'Analyze Image'..")
|
78 |
analyze_button_key = f'analyze_{image_key}_{st.session_state.detection_model}_{st.session_state.confidence_level}'
|
79 |
+
if nested_col22.button('Analyze Image', key=analyze_button_key, on_click=self.disable_widgets, disabled=self.is_widget_disabled):
|
80 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'])
|
81 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
82 |
st.session_state['loading_in_progress'] = False
|
83 |
|
84 |
def handle_question_answering(self, image_key, image_data, nested_col22):
|
85 |
+
# Initialize qa_history for each image
|
86 |
+
#qa_history = image_data.get('qa_history', [])
|
87 |
if image_data['analysis_done']:
|
88 |
self.display_question_answering_interface(image_key, image_data, nested_col22)
|
89 |
|
|
|
95 |
question = custom_question if selected_question == "Custom question..." else selected_question
|
96 |
self.process_question(image_key, question, image_data, nested_col22)
|
97 |
|
|
|
98 |
qa_history = image_data.get('qa_history', [])
|
99 |
+
for num, (q, a, p) in enumerate(qa_history):
|
100 |
+
nested_col22.text(f"Q{num+1}: {q}\nA{num+1}: {a}\nPrompt Length: {p}\n")
|
101 |
+
|
102 |
+
|
103 |
+
def process_question(self, image_key, question, image_data, nested_col22):
|
104 |
+
#qa_history = image_data.get('qa_history', [])
|
105 |
if question and (question not in [q for q, _, _ in qa_history] or self.settings_changed or self.confidance_change):
|
106 |
if nested_col22.button('Get Answer', key=f'answer_{image_key}', disabled=self.is_widget_disabled):
|
107 |
answer, prompt_length = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question)
|
|
|
116 |
for image_key, image_data in self.get_images_data().items():
|
117 |
with st.container():
|
118 |
nested_col21, nested_col22 = st.columns([0.65, 0.35])
|
|
|
|
|
119 |
self.display_image_and_analysis(image_key, image_data, nested_col21, nested_col22)
|
120 |
self.handle_question_answering(image_key, image_data, nested_col22)
|
121 |
|