dropbop commited on
Commit
d56788b
·
verified ·
1 Parent(s): 7a6ee1c

Fix labeling_ui and save_labeled_data functions

Browse files

# Key Changes:

## labeling_ui():

Removed the lines that were trying to use .update() on the components.

Created a new function initialize_labeling_ui() to set the initial values of the components. This function returns the initial image, metadata, and label count.

We call initialize_labeling_ui() and set the values of the components directly using image_component.value, metadata_text.value, and label_count_text.value.

## save_labeled_data():

The function now returns the new image, metadata, and count values. Gradio will automatically update the image_component, metadata_text, and label_count_text components with these returned values.

Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -92,11 +92,17 @@ def labeling_ui():
92
  )
93
 
94
  # Initialize with the first sample
95
- image, metadata, count = get_next_sample()
96
- if image is not None:
97
- image_component.update(value=image) # Use .update() to set the value
98
- metadata_text.update(value=str(metadata["bounds"])) # Use .update()
99
- label_count_text.update(value=f"Labeled {count} samples.") # Use .update()
 
 
 
 
 
 
100
 
101
  # --- Display UI ---
102
  def display_ui():
 
92
  )
93
 
94
  # Initialize with the first sample
95
+ def initialize_labeling_ui():
96
+ image, metadata, count = get_next_sample()
97
+ if image is not None:
98
+ return image, str(metadata["bounds"]), f"Labeled {count} samples."
99
+ else:
100
+ return None, "", "No samples loaded."
101
+
102
+ initial_image, initial_metadata, initial_count = initialize_labeling_ui()
103
+ image_component.value = initial_image
104
+ metadata_text.value = initial_metadata
105
+ label_count_text.value = initial_count
106
 
107
  # --- Display UI ---
108
  def display_ui():