Update my_model/tabs/run_inference.py
Browse files- 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 |
-
|
50 |
-
|
51 |
-
self.
|
52 |
-
|
53 |
-
|
54 |
-
if
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
if
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
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):
|