m7mdal7aj commited on
Commit
7316948
1 Parent(s): 5667733

Update my_model/tabs/run_inference.py

Browse files
Files changed (1) hide show
  1. my_model/tabs/run_inference.py +25 -22
my_model/tabs/run_inference.py CHANGED
@@ -46,28 +46,31 @@ class InferenceRunner(StateManager):
46
  self.process_new_image(uploaded_image.name, Image.open(uploaded_image), kbvqa)
47
 
48
  # Display and interact with each uploaded/selected image
49
- for image_key, image_data in self.get_images_data().items():
50
- image_for_display = self.resize_image(image_data['image'], 600)
51
- self.col2.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
52
- if not image_data['analysis_done']:
53
- self.col2.text("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
-
58
- # Initialize qa_history for each image
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)
67
-
68
- # Display Q&A history for each image
69
- for q, a in qa_history:
70
- self.col2.text(f"Q: {q}\nA: {a}\n")
 
 
 
71
 
72
 
73
  def run_inference(self):
 
46
  self.process_new_image(uploaded_image.name, Image.open(uploaded_image), kbvqa)
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):