Spaces:
Sleeping
Sleeping
Update my_model/tabs/run_inference.py
Browse files
my_model/tabs/run_inference.py
CHANGED
@@ -86,17 +86,20 @@ class InferenceRunner(StateManager):
|
|
86 |
nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
|
87 |
if not image_data['analysis_done'] or self.settings_changed: # if not done analysis before or even done but settings changed, then we need to analyze again
|
88 |
nested_col22.text("Please click 'Analyze Image'..")
|
|
|
89 |
with nested_col22:
|
90 |
if st.button('Analyze Image', key=f'analyze_{image_key}', on_click=self.disable_widgets, disabled=self.is_widget_disabled):
|
91 |
|
92 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'])
|
93 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
94 |
st.session_state['loading_in_progress'] = False
|
|
|
95 |
|
96 |
# Initialize qa_history for each image
|
97 |
qa_history = image_data.get('qa_history', [])
|
98 |
|
99 |
if image_data['analysis_done']:
|
|
|
100 |
st.session_state['loading_in_progress'] = False
|
101 |
sample_questions = config.SAMPLE_QUESTIONS.get(image_key, [])
|
102 |
selected_question = nested_col22.selectbox(
|
@@ -118,7 +121,7 @@ class InferenceRunner(StateManager):
|
|
118 |
nested_col22.warning("This question has already been answered.")
|
119 |
else:
|
120 |
if nested_col22.button('Get Answer', key=f'answer_{image_key}', disabled=self.is_widget_disabled):
|
121 |
-
|
122 |
answer, prompt_length = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question)
|
123 |
st.session_state['loading_in_progress'] = False
|
124 |
self.add_to_qa_history(image_key, question, answer, prompt_length)
|
@@ -126,6 +129,7 @@ class InferenceRunner(StateManager):
|
|
126 |
# Display Q&A history and prompts lengths for each image
|
127 |
for num, (q, a, p) in enumerate(qa_history):
|
128 |
nested_col22.text(f"Q{num+1}: {q}\nA{num+1}: {a}\nPrompt Length: {p}\n")
|
|
|
129 |
|
130 |
|
131 |
def run_inference(self):
|
|
|
86 |
nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
|
87 |
if not image_data['analysis_done'] or self.settings_changed: # if not done analysis before or even done but settings changed, then we need to analyze again
|
88 |
nested_col22.text("Please click 'Analyze Image'..")
|
89 |
+
free_gpu_resources()
|
90 |
with nested_col22:
|
91 |
if st.button('Analyze Image', key=f'analyze_{image_key}', on_click=self.disable_widgets, disabled=self.is_widget_disabled):
|
92 |
|
93 |
caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'])
|
94 |
self.update_image_data(image_key, caption, detected_objects_str, True)
|
95 |
st.session_state['loading_in_progress'] = False
|
96 |
+
free_gpu_resources()
|
97 |
|
98 |
# Initialize qa_history for each image
|
99 |
qa_history = image_data.get('qa_history', [])
|
100 |
|
101 |
if image_data['analysis_done']:
|
102 |
+
free_gpu_resources()
|
103 |
st.session_state['loading_in_progress'] = False
|
104 |
sample_questions = config.SAMPLE_QUESTIONS.get(image_key, [])
|
105 |
selected_question = nested_col22.selectbox(
|
|
|
121 |
nested_col22.warning("This question has already been answered.")
|
122 |
else:
|
123 |
if nested_col22.button('Get Answer', key=f'answer_{image_key}', disabled=self.is_widget_disabled):
|
124 |
+
free_gpu_resources()
|
125 |
answer, prompt_length = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question)
|
126 |
st.session_state['loading_in_progress'] = False
|
127 |
self.add_to_qa_history(image_key, question, answer, prompt_length)
|
|
|
129 |
# Display Q&A history and prompts lengths for each image
|
130 |
for num, (q, a, p) in enumerate(qa_history):
|
131 |
nested_col22.text(f"Q{num+1}: {q}\nA{num+1}: {a}\nPrompt Length: {p}\n")
|
132 |
+
free_gpu_resources()
|
133 |
|
134 |
|
135 |
def run_inference(self):
|