GeorgeIbrahim commited on
Commit
9aec593
·
1 Parent(s): 35eb21a
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -95,7 +95,7 @@ def get_caption_for_image_id(image_path):
95
  # Return None if the image_id is not found
96
  print("Caption not found for image_id:", image_id) # Debugging line
97
  return None
98
-
99
  # Function to get a random image that hasn’t been fully annotated
100
  def get_next_image(session_data):
101
  with lock:
@@ -103,8 +103,8 @@ def get_next_image(session_data):
103
  available_images = [
104
  img for img in image_files
105
  if img not in annotation_counts or
106
- ("val" in img and annotation_counts.get(img, 0) < 2) or
107
- ("val" not in img and annotation_counts.get(img, 0) == 0)
108
  ]
109
 
110
  print("Available images:", available_images) # Debugging line
@@ -127,6 +127,10 @@ def save_annotation(caption, session_data):
127
 
128
  with lock:
129
  image_id = session_data["current_image"]
 
 
 
 
130
 
131
  # Save caption or "skipped" based on user input
132
  if caption.strip().lower() == "skip":
@@ -139,11 +143,13 @@ def save_annotation(caption, session_data):
139
  new_data = Dataset.from_dict({
140
  "image_id": [image_id],
141
  "caption": [caption],
142
- "annotation_count": [annotation_count + 1] # Increment the annotation count
 
143
  }, features=Features({
144
  'image_id': Value(dtype='string'),
145
  'caption': Value(dtype='string'),
146
- 'annotation_count': Value(dtype='int32') # Ensure int32 type
 
147
  }))
148
 
149
  # Update the annotation count in the dictionary
 
95
  # Return None if the image_id is not found
96
  print("Caption not found for image_id:", image_id) # Debugging line
97
  return None
98
+
99
  # Function to get a random image that hasn’t been fully annotated
100
  def get_next_image(session_data):
101
  with lock:
 
103
  available_images = [
104
  img for img in image_files
105
  if img not in annotation_counts or
106
+ (split.get(img, 0) == "dev" and annotation_counts.get(img, 0) < 2) or
107
+ (split.get(img, 0) == "train" and annotation_counts.get(img, 0) == 0)
108
  ]
109
 
110
  print("Available images:", available_images) # Debugging line
 
127
 
128
  with lock:
129
  image_id = session_data["current_image"]
130
+
131
+ match = re.search(r'_(\d+)\.', image_id)
132
+ image_id = match.group(1).lstrip('0')
133
+ split = "dev" if image_id in results else "train"
134
 
135
  # Save caption or "skipped" based on user input
136
  if caption.strip().lower() == "skip":
 
143
  new_data = Dataset.from_dict({
144
  "image_id": [image_id],
145
  "caption": [caption],
146
+ "annotation_count": [annotation_count + 1],
147
+ "split": [split]
148
  }, features=Features({
149
  'image_id': Value(dtype='string'),
150
  'caption': Value(dtype='string'),
151
+ 'annotation_count': Value(dtype='int32'),
152
+ 'split': Value(dtype='string')
153
  }))
154
 
155
  # Update the annotation count in the dictionary