m7mdal7aj commited on
Commit
8f568ec
1 Parent(s): 53586ab

Update my_model/tabs/run_inference.py

Browse files
Files changed (1) hide show
  1. my_model/tabs/run_inference.py +10 -13
my_model/tabs/run_inference.py CHANGED
@@ -30,7 +30,6 @@ class InferenceRunner(StateManager):
30
  """
31
 
32
  super().__init__()
33
- # self.initialize_state()
34
 
35
 
36
  def answer_question(self, caption, detected_objects_str, question):
@@ -41,8 +40,6 @@ class InferenceRunner(StateManager):
41
  caption (str): The caption generated for the image.
42
  detected_objects_str (str): String representation of objects detected in the image.
43
  question (str): The user's question about the image.
44
-
45
-
46
  Returns:
47
  str: The generated answer to the question.
48
  """
@@ -53,15 +50,8 @@ class InferenceRunner(StateManager):
53
  return answer, prompt_length
54
 
55
 
56
- def image_qa_app(self):
57
- """
58
- Main application interface for image-based question answering. It handles displaying
59
- of sample images, uploading of new images, and facilitates the QA process.
60
- """
61
-
62
-
63
  # Display sample images as clickable thumbnails
64
-
65
  self.col1.write("Choose from sample images:")
66
  cols = self.col1.columns(len(config.SAMPLE_IMAGES))
67
  for idx, sample_image_path in enumerate(config.SAMPLE_IMAGES):
@@ -72,13 +62,20 @@ class InferenceRunner(StateManager):
72
  if st.button(f'Select Sample Image {idx + 1}', key=f'sample_{idx}'):
73
  self.process_new_image(sample_image_path, image)
74
 
 
 
 
 
 
 
 
75
  # Image uploader
76
  uploaded_image = self.col1.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
77
  if uploaded_image is not None:
78
  self.process_new_image(uploaded_image.name, Image.open(uploaded_image))
79
 
80
  # Display and interact with each uploaded/selected image
81
- self.display_session_state()
82
  with self.col2:
83
  for image_key, image_data in self.get_images_data().items():
84
 
@@ -86,7 +83,7 @@ class InferenceRunner(StateManager):
86
  nested_col21, nested_col22 = st.columns([0.65, 0.35])
87
  image_for_display = self.resize_image(image_data['image'], 600)
88
  nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
89
- nested_col21.write(image_data['analysis_done'] , self.settings_changed , self.confidance_change)
90
  if not image_data['analysis_done'] or self.settings_changed or self.confidance_change: # if not done analysis before or even done but settings changed, then we need to analyze again
91
 
92
  nested_col22.text("Please click 'Analyze Image'..")
 
30
  """
31
 
32
  super().__init__()
 
33
 
34
 
35
  def answer_question(self, caption, detected_objects_str, question):
 
40
  caption (str): The caption generated for the image.
41
  detected_objects_str (str): String representation of objects detected in the image.
42
  question (str): The user's question about the image.
 
 
43
  Returns:
44
  str: The generated answer to the question.
45
  """
 
50
  return answer, prompt_length
51
 
52
 
53
+ def display_sample_images(self):
 
 
 
 
 
 
54
  # Display sample images as clickable thumbnails
 
55
  self.col1.write("Choose from sample images:")
56
  cols = self.col1.columns(len(config.SAMPLE_IMAGES))
57
  for idx, sample_image_path in enumerate(config.SAMPLE_IMAGES):
 
62
  if st.button(f'Select Sample Image {idx + 1}', key=f'sample_{idx}'):
63
  self.process_new_image(sample_image_path, image)
64
 
65
+ def image_qa_app(self):
66
+ """
67
+ Main application interface for image-based question answering. It handles displaying
68
+ of sample images, uploading of new images, and facilitates the QA process.
69
+ """
70
+
71
+ self.display_sample_images()
72
  # Image uploader
73
  uploaded_image = self.col1.file_uploader("Or upload an Image", type=["png", "jpg", "jpeg"])
74
  if uploaded_image is not None:
75
  self.process_new_image(uploaded_image.name, Image.open(uploaded_image))
76
 
77
  # Display and interact with each uploaded/selected image
78
+
79
  with self.col2:
80
  for image_key, image_data in self.get_images_data().items():
81
 
 
83
  nested_col21, nested_col22 = st.columns([0.65, 0.35])
84
  image_for_display = self.resize_image(image_data['image'], 600)
85
  nested_col21.image(image_for_display, caption=f'Uploaded Image: {image_key[-11:]}')
86
+
87
  if not image_data['analysis_done'] or self.settings_changed or self.confidance_change: # if not done analysis before or even done but settings changed, then we need to analyze again
88
 
89
  nested_col22.text("Please click 'Analyze Image'..")