GeorgeIbrahim commited on
Commit
10a1f44
·
1 Parent(s): df87278
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -96,27 +96,28 @@ def get_caption_for_image_id(image_path):
96
  print("Caption not found for image_id:", image_id) # Debugging line
97
  return None
98
 
 
 
99
  shown_counts = {}
100
 
101
  # Function to get a random image that hasn’t been fully annotated
102
  def get_next_image(session_data):
103
  with lock:
104
- # Filter available images based on annotation counts and split
105
  available_images = [
106
  img for img in image_files
107
  if img not in annotation_counts or
108
- ("val" in img and annotation_counts.get(img, 0) < 2) or
109
- ("val" not in img and annotation_counts.get(img, 0) == 0)
110
  ]
111
 
112
  print("Available images:", available_images) # Debugging line
113
 
114
- # Select an image to show based on split type
115
  if session_data["current_image"] is None and available_images:
116
  random.shuffle(available_images) # Shuffle for randomness
117
  for img in available_images:
118
- image_id = re.search(r'_(\d+)\.', img).group(1).lstrip('0') # Extract image ID
119
- split = "dev" if image_id in results else "train"
120
 
121
  # Show 'dev' images twice
122
  if split == "dev":
@@ -144,10 +145,9 @@ def save_annotation(caption, session_data):
144
  image_id = session_data["current_image"]
145
  print("Image ID before: ", image_id)
146
 
147
- match = re.search(r'_(\d+)\.', image_id)
148
- image_id_2 = match.group(1).lstrip('0')
149
- split = "dev" if image_id_2 in results else "train"
150
- print("Image ID after: ", image_id_2)
151
 
152
  # Save caption or "skipped" based on user input
153
  if caption.strip().lower() == "skip":
@@ -193,7 +193,8 @@ def save_annotation(caption, session_data):
193
  else:
194
  return gr.update(visible=False), gr.update(value="All images have been annotated!"), gr.update(value="")
195
 
196
-
 
197
  def initialize_interface(session_data):
198
  next_image = get_next_image(session_data)
199
  if next_image:
 
96
  print("Caption not found for image_id:", image_id) # Debugging line
97
  return None
98
 
99
+
100
+ # Initialize a dictionary to keep track of how many times each 'dev' image has been shown
101
  shown_counts = {}
102
 
103
  # Function to get a random image that hasn’t been fully annotated
104
  def get_next_image(session_data):
105
  with lock:
106
+ # Filter available images based on annotation counts and the 'split' column
107
  available_images = [
108
  img for img in image_files
109
  if img not in annotation_counts or
110
+ (dataset[img]['split'] == "dev" and annotation_counts.get(img, 0) < 2) or
111
+ (dataset[img]['split'] == "train" and annotation_counts.get(img, 0) == 0)
112
  ]
113
 
114
  print("Available images:", available_images) # Debugging line
115
 
116
+ # Select an image to show based on the 'split' column
117
  if session_data["current_image"] is None and available_images:
118
  random.shuffle(available_images) # Shuffle for randomness
119
  for img in available_images:
120
+ split = dataset[img]['split'] # Get the split value from the dataset
 
121
 
122
  # Show 'dev' images twice
123
  if split == "dev":
 
145
  image_id = session_data["current_image"]
146
  print("Image ID before: ", image_id)
147
 
148
+ # Determine the split directly from the dataset
149
+ split = dataset[image_id]['split']
150
+ print("Split for image:", split)
 
151
 
152
  # Save caption or "skipped" based on user input
153
  if caption.strip().lower() == "skip":
 
193
  else:
194
  return gr.update(visible=False), gr.update(value="All images have been annotated!"), gr.update(value="")
195
 
196
+
197
+
198
  def initialize_interface(session_data):
199
  next_image = get_next_image(session_data)
200
  if next_image: