m7mdal7aj commited on
Commit
522b5f3
1 Parent(s): 228473d

Update my_model/tabs/run_inference.py

Browse files
Files changed (1) hide show
  1. my_model/tabs/run_inference.py +8 -5
my_model/tabs/run_inference.py CHANGED
@@ -55,21 +55,23 @@ class InferenceRunner(StateManager):
55
  if not image_data['analysis_done']:
56
  nested_col22.text("Please click 'Analyze Image'..")
57
  with nested_col22:
58
- if st.button('Analyze Image', key=f'analyze_{image_key}'):
59
- st.session_state['loading_in_progress'] = True
60
  caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
61
  self.update_image_data(image_key, caption, detected_objects_str, True)
62
- st.session_state['loading_in_progress'] = False
 
63
 
64
  # Initialize qa_history for each image
65
  qa_history = image_data.get('qa_history', [])
66
 
67
  if image_data['analysis_done']:
68
  question = nested_col22.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
69
- if nested_col22.button('Get Answer', key=f'answer_{image_key}'):
70
- st.session_state['loading_in_progress'] = True
71
  if question not in [q for q, _ in qa_history]:
72
  answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
 
73
  self.add_to_qa_history(image_key, question, answer)
74
  else: nested_col22.warning("This questions has already been answered.")
75
 
@@ -140,6 +142,7 @@ class InferenceRunner(StateManager):
140
 
141
 
142
  if self.is_model_loaded():
 
143
  free_gpu_resources()
144
  self.image_qa_app(self.get_model())
145
 
 
55
  if not image_data['analysis_done']:
56
  nested_col22.text("Please click 'Analyze Image'..")
57
  with nested_col22:
58
+ if st.button('Analyze Image', key=f'analyze_{image_key}', on_click=self.disable_widgets, disabled=self.is_widget_disabled):
59
+
60
  caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
61
  self.update_image_data(image_key, caption, detected_objects_str, True)
62
+ st.session_state['loading_in_progress'] = False
63
+
64
 
65
  # Initialize qa_history for each image
66
  qa_history = image_data.get('qa_history', [])
67
 
68
  if image_data['analysis_done']:
69
  question = nested_col22.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
70
+ if nested_col22.button('Get Answer', key=f'answer_{image_key}', on_click=self.disable_widgets, disabled=self.is_widget_disabled):
71
+
72
  if question not in [q for q, _ in qa_history]:
73
  answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
74
+ st.session_state['loading_in_progress'] = False
75
  self.add_to_qa_history(image_key, question, answer)
76
  else: nested_col22.warning("This questions has already been answered.")
77
 
 
142
 
143
 
144
  if self.is_model_loaded():
145
+ st.session_state['loading_in_progress'] = False
146
  free_gpu_resources()
147
  self.image_qa_app(self.get_model())
148