Spaces:
Sleeping
Sleeping
updates
Browse files
app.py
CHANGED
|
@@ -54,39 +54,39 @@ class VideoAnnotator:
|
|
| 54 |
# --- Start Edit: Filter out already annotated videos ---
|
| 55 |
logger.info(f"Checking for existing annotations in {self.annotation_repo_id}")
|
| 56 |
try:
|
|
|
|
| 57 |
annotated_files = self.api.list_repo_files(
|
| 58 |
repo_id=self.annotation_repo_id,
|
| 59 |
repo_type=self.annotation_repo_type,
|
| 60 |
-
path_in_repo="annotations"
|
| 61 |
)
|
| 62 |
-
# Extract base video names from annotation filenames
|
|
|
|
| 63 |
annotated_video_basenames = set(
|
| 64 |
-
os.path.basename(f).replace('.jsonl', '')
|
|
|
|
|
|
|
| 65 |
)
|
| 66 |
logger.info(f"Found {len(annotated_video_basenames)} existing annotation files.")
|
| 67 |
|
| 68 |
-
# Filter the video list
|
| 69 |
self.video_files = [
|
| 70 |
-
vf for vf in all_video_files
|
| 71 |
if os.path.basename(vf) not in annotated_video_basenames
|
| 72 |
]
|
| 73 |
-
|
| 74 |
logger.info(f"Filtered list: {len(self.video_files)} videos remaining to be annotated.")
|
| 75 |
|
| 76 |
except Exception as e:
|
|
|
|
| 77 |
logger.error(f"Could not list or process annotation files: {e}. Proceeding with all videos, but conflicts may occur.")
|
| 78 |
self.video_files = all_video_files # Fallback: load all if check fails
|
| 79 |
# --- End Edit ---
|
| 80 |
|
| 81 |
-
# print(self.video_files) # Optional: keep if needed for debugging
|
| 82 |
-
|
| 83 |
-
# logger.info(f"Found {len(self.video_files)} video files") # Updated log message above
|
| 84 |
-
# print(f"Video files found: {self.video_files}") # Optional: keep if needed for debugging
|
| 85 |
-
|
| 86 |
if not self.video_files:
|
| 87 |
logger.warning("No videos left to annotate!")
|
| 88 |
# Optionally, display a message in the UI here if possible
|
| 89 |
-
|
| 90 |
return len(self.video_files) > 0
|
| 91 |
except Exception as e:
|
| 92 |
logger.error(f"Error accessing HuggingFace dataset: {e}")
|
|
@@ -261,7 +261,7 @@ def create_interface():
|
|
| 261 |
|
| 262 |
with gr.Column(scale=2): # Column for Annotations and Save Button
|
| 263 |
annotation_components = []
|
| 264 |
-
gr.Markdown("
|
| 265 |
|
| 266 |
# Display annotation radio buttons vertically in this column
|
| 267 |
for category, options in ANNOTATION_CATEGORIES.items():
|
|
@@ -271,7 +271,6 @@ def create_interface():
|
|
| 271 |
)
|
| 272 |
annotation_components.append(radio)
|
| 273 |
|
| 274 |
-
# --- Start Edit: Add Progress Display and attach change listeners ---
|
| 275 |
progress_display = gr.Markdown(value=update_progress(*[None]*total_categories)) # Initial progress
|
| 276 |
|
| 277 |
# Attach change listener to each radio button
|
|
@@ -281,7 +280,6 @@ def create_interface():
|
|
| 281 |
inputs=annotation_components,
|
| 282 |
outputs=progress_display
|
| 283 |
)
|
| 284 |
-
# --- End Edit ---
|
| 285 |
|
| 286 |
save_btn = gr.Button("Save Annotations", variant="primary")
|
| 287 |
|
|
|
|
| 54 |
# --- Start Edit: Filter out already annotated videos ---
|
| 55 |
logger.info(f"Checking for existing annotations in {self.annotation_repo_id}")
|
| 56 |
try:
|
| 57 |
+
# List files in the 'annotations' directory of the annotation repo
|
| 58 |
annotated_files = self.api.list_repo_files(
|
| 59 |
repo_id=self.annotation_repo_id,
|
| 60 |
repo_type=self.annotation_repo_type,
|
| 61 |
+
path_in_repo="annotations" # Specify the directory
|
| 62 |
)
|
| 63 |
+
# Extract base video names from annotation filenames
|
| 64 |
+
# e.g., "annotations/video1.mp4.jsonl" -> "video1.mp4"
|
| 65 |
annotated_video_basenames = set(
|
| 66 |
+
os.path.basename(f).replace('.jsonl', '')
|
| 67 |
+
for f in annotated_files
|
| 68 |
+
if f.startswith("annotations/") and f.endswith(".jsonl") # Ensure it's in the correct folder and has the right extension
|
| 69 |
)
|
| 70 |
logger.info(f"Found {len(annotated_video_basenames)} existing annotation files.")
|
| 71 |
|
| 72 |
+
# Filter the video list: keep only videos whose basename is NOT in the annotated set
|
| 73 |
self.video_files = [
|
| 74 |
+
vf for vf in all_video_files
|
| 75 |
if os.path.basename(vf) not in annotated_video_basenames
|
| 76 |
]
|
| 77 |
+
|
| 78 |
logger.info(f"Filtered list: {len(self.video_files)} videos remaining to be annotated.")
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
+
# Log error and fallback to using all videos if the check fails
|
| 82 |
logger.error(f"Could not list or process annotation files: {e}. Proceeding with all videos, but conflicts may occur.")
|
| 83 |
self.video_files = all_video_files # Fallback: load all if check fails
|
| 84 |
# --- End Edit ---
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
if not self.video_files:
|
| 87 |
logger.warning("No videos left to annotate!")
|
| 88 |
# Optionally, display a message in the UI here if possible
|
| 89 |
+
|
| 90 |
return len(self.video_files) > 0
|
| 91 |
except Exception as e:
|
| 92 |
logger.error(f"Error accessing HuggingFace dataset: {e}")
|
|
|
|
| 261 |
|
| 262 |
with gr.Column(scale=2): # Column for Annotations and Save Button
|
| 263 |
annotation_components = []
|
| 264 |
+
gr.Markdown("## Annotations") # Header for the annotation section
|
| 265 |
|
| 266 |
# Display annotation radio buttons vertically in this column
|
| 267 |
for category, options in ANNOTATION_CATEGORIES.items():
|
|
|
|
| 271 |
)
|
| 272 |
annotation_components.append(radio)
|
| 273 |
|
|
|
|
| 274 |
progress_display = gr.Markdown(value=update_progress(*[None]*total_categories)) # Initial progress
|
| 275 |
|
| 276 |
# Attach change listener to each radio button
|
|
|
|
| 280 |
inputs=annotation_components,
|
| 281 |
outputs=progress_display
|
| 282 |
)
|
|
|
|
| 283 |
|
| 284 |
save_btn = gr.Button("Save Annotations", variant="primary")
|
| 285 |
|