m7mdal7aj commited on
Commit
8cedf13
1 Parent(s): 7316948

Update my_model/tabs/run_inference.py

Browse files
Files changed (1) hide show
  1. my_model/tabs/run_inference.py +25 -24
my_model/tabs/run_inference.py CHANGED
@@ -47,30 +47,31 @@ class InferenceRunner(StateManager):
47
 
48
  # Display and interact with each uploaded/selected image
49
  with self.col2:
50
- nested_col21, nested_col22 = st.columns([0.7, 0.3])
51
- for image_key, image_data in self.get_images_data().items():
52
- image_for_display = self.resize_image(image_data['image'], 600)
53
- nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
54
- if not image_data['analysis_done']:
55
- nested_col22.text("Please click 'Analyze Image'..")
56
- if nested_col22.button('Analyze Image', key=f'analyze_{image_key}'):
57
- caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
58
- self.update_image_data(image_key, caption, detected_objects_str, True)
59
-
60
- # Initialize qa_history for each image
61
- qa_history = image_data.get('qa_history', [])
62
-
63
- if image_data['analysis_done']:
64
- question = nested_col22.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
65
- if nested_col22.button('Get Answer', key=f'answer_{image_key}'):
66
- if question not in [q for q, _ in qa_history]:
67
- answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
68
- self.add_to_qa_history(image_key, question, answer)
69
- else: nested_col22.warning("This questions has already been answered.")
70
-
71
- # Display Q&A history for each image
72
- for q, a in qa_history:
73
- nested_col22.text(f"Q: {q}\nA: {a}\n")
 
74
 
75
 
76
  def run_inference(self):
 
47
 
48
  # Display and interact with each uploaded/selected image
49
  with self.col2:
50
+ with st.container():
51
+ nested_col21, nested_col22 = st.columns([0.7, 0.3])
52
+ for image_key, image_data in self.get_images_data().items():
53
+ image_for_display = self.resize_image(image_data['image'], 600)
54
+ nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
55
+ if not image_data['analysis_done']:
56
+ nested_col22.text("Please click 'Analyze Image'..")
57
+ if nested_col22.button('Analyze Image', key=f'analyze_{image_key}'):
58
+ caption, detected_objects_str, image_with_boxes = self.analyze_image(image_data['image'], kbvqa)
59
+ self.update_image_data(image_key, caption, detected_objects_str, True)
60
+
61
+ # Initialize qa_history for each image
62
+ qa_history = image_data.get('qa_history', [])
63
+
64
+ if image_data['analysis_done']:
65
+ question = nested_col22.text_input(f"Ask a question about this image ({image_key[-11:]}):", key=f'question_{image_key}')
66
+ if nested_col22.button('Get Answer', key=f'answer_{image_key}'):
67
+ if question not in [q for q, _ in qa_history]:
68
+ answer = self.answer_question(image_data['caption'], image_data['detected_objects_str'], question, kbvqa)
69
+ self.add_to_qa_history(image_key, question, answer)
70
+ else: nested_col22.warning("This questions has already been answered.")
71
+
72
+ # Display Q&A history for each image
73
+ for q, a in qa_history:
74
+ nested_col22.text(f"Q: {q}\nA: {a}\n")
75
 
76
 
77
  def run_inference(self):