Spaces:
Sleeping
Sleeping
No more update descriptions until I have a working version
Browse files
app.py
CHANGED
@@ -46,17 +46,14 @@ def get_images(batch_size, state):
|
|
46 |
images = []
|
47 |
metadatas = []
|
48 |
for _ in range(batch_size):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
images.append(image)
|
58 |
-
metadatas.append(metadata)
|
59 |
-
|
60 |
return images, DataFrame(metadatas)
|
61 |
|
62 |
# --- Save Labeled Data ---
|
@@ -66,8 +63,7 @@ def save_labeled_data(label, state):
|
|
66 |
if sample is None:
|
67 |
return "No image to label", None, DataFrame()
|
68 |
|
69 |
-
image = sample["rgb"][0]
|
70 |
-
|
71 |
image_bytes = image.convert("RGB").tobytes()
|
72 |
labeled_data.append({
|
73 |
"image": image_bytes,
|
@@ -80,46 +76,38 @@ def save_labeled_data(label, state):
|
|
80 |
|
81 |
new_sample = get_next_sample()
|
82 |
if new_sample is None:
|
83 |
-
|
84 |
-
|
85 |
|
86 |
state["sample"] = new_sample
|
87 |
-
|
88 |
new_image = new_sample["rgb"][0]
|
89 |
new_metadata = new_sample["metadata"]
|
90 |
new_metadata["map"] = f'<a href="{utils.get_google_map_link(new_sample, DATASET_SUBSET)}" target="_blank">🧭</a>'
|
91 |
-
|
92 |
return "", [new_image], DataFrame([new_metadata])
|
93 |
|
94 |
# --- Gradio Interface ---
|
95 |
# --- Labeling UI ---
|
96 |
def labeling_ui():
|
97 |
-
|
98 |
state = gr.State({"sample": None, "subset": DATASET_SUBSET})
|
99 |
|
100 |
with gr.Row():
|
101 |
with gr.Column():
|
102 |
gallery = gr.Gallery(label="Satellite Image", interactive=False, columns=1, object_fit="scale-down")
|
103 |
-
|
104 |
with gr.Row():
|
105 |
cool_button = gr.Button("Cool")
|
106 |
not_cool_button = gr.Button("Not Cool")
|
107 |
-
|
108 |
table = gr.DataFrame(datatype="html")
|
109 |
|
110 |
def initialize_labeling_ui():
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
return sample, image, metadata
|
116 |
|
117 |
-
initial_sample,
|
118 |
-
gallery.value =
|
119 |
table.value = initial_metadata
|
120 |
-
state.value
|
121 |
|
122 |
-
# Handle button clicks
|
123 |
cool_button.click(
|
124 |
fn=lambda label, state: save_labeled_data(label, state),
|
125 |
inputs=[gr.Textbox(visible=False, value="cool"), state],
|
@@ -133,7 +121,6 @@ def labeling_ui():
|
|
133 |
|
134 |
# --- Display UI ---
|
135 |
def display_ui():
|
136 |
-
|
137 |
def get_random_cool_images(n):
|
138 |
cool_samples = [d for d in labeled_data if d["label"] == "cool"]
|
139 |
return [Image.frombytes("RGB", (384, 384), s["image"]) for s in cool_samples] if len(cool_samples) >= n else []
|
@@ -158,7 +145,6 @@ def display_ui():
|
|
158 |
with gr.Row():
|
159 |
new_image_component = gr.Image(label="New Image", type="pil")
|
160 |
metadata_display = gr.Textbox(label="Metadata (Bounds)")
|
161 |
-
|
162 |
with gr.Row():
|
163 |
cool_images_gallery = gr.Gallery(label="Cool Examples", value=[], columns=DISPLAY_N_COOL)
|
164 |
|
@@ -186,4 +172,4 @@ with gr.Blocks() as demo:
|
|
186 |
with gr.TabItem("Display"):
|
187 |
display_ui()
|
188 |
|
189 |
-
demo.launch(debug=True
|
|
|
46 |
images = []
|
47 |
metadatas = []
|
48 |
for _ in range(batch_size):
|
49 |
+
sample = get_next_sample()
|
50 |
+
if sample is None:
|
51 |
+
break
|
52 |
+
image = sample["rgb"][0]
|
53 |
+
metadata = sample["metadata"]
|
54 |
+
metadata["map"] = f'<a href="{utils.get_google_map_link(sample, subset)}" target="_blank">🧭</a>'
|
55 |
+
images.append(image)
|
56 |
+
metadatas.append(metadata)
|
|
|
|
|
|
|
57 |
return images, DataFrame(metadatas)
|
58 |
|
59 |
# --- Save Labeled Data ---
|
|
|
63 |
if sample is None:
|
64 |
return "No image to label", None, DataFrame()
|
65 |
|
66 |
+
image = sample["rgb"][0]
|
|
|
67 |
image_bytes = image.convert("RGB").tobytes()
|
68 |
labeled_data.append({
|
69 |
"image": image_bytes,
|
|
|
76 |
|
77 |
new_sample = get_next_sample()
|
78 |
if new_sample is None:
|
79 |
+
state["sample"] = None
|
80 |
+
return "Dataset exhausted.", None, DataFrame()
|
81 |
|
82 |
state["sample"] = new_sample
|
|
|
83 |
new_image = new_sample["rgb"][0]
|
84 |
new_metadata = new_sample["metadata"]
|
85 |
new_metadata["map"] = f'<a href="{utils.get_google_map_link(new_sample, DATASET_SUBSET)}" target="_blank">🧭</a>'
|
|
|
86 |
return "", [new_image], DataFrame([new_metadata])
|
87 |
|
88 |
# --- Gradio Interface ---
|
89 |
# --- Labeling UI ---
|
90 |
def labeling_ui():
|
|
|
91 |
state = gr.State({"sample": None, "subset": DATASET_SUBSET})
|
92 |
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|
95 |
gallery = gr.Gallery(label="Satellite Image", interactive=False, columns=1, object_fit="scale-down")
|
|
|
96 |
with gr.Row():
|
97 |
cool_button = gr.Button("Cool")
|
98 |
not_cool_button = gr.Button("Not Cool")
|
|
|
99 |
table = gr.DataFrame(datatype="html")
|
100 |
|
101 |
def initialize_labeling_ui():
|
102 |
+
sample = get_next_sample()
|
103 |
+
images, metadata = get_images(1, {"sample": None, "subset": DATASET_SUBSET})
|
104 |
+
return sample, images, metadata
|
|
|
|
|
105 |
|
106 |
+
initial_sample, initial_images, initial_metadata = initialize_labeling_ui()
|
107 |
+
gallery.value = initial_images
|
108 |
table.value = initial_metadata
|
109 |
+
state.value = {"sample": initial_sample, "subset": DATASET_SUBSET}
|
110 |
|
|
|
111 |
cool_button.click(
|
112 |
fn=lambda label, state: save_labeled_data(label, state),
|
113 |
inputs=[gr.Textbox(visible=False, value="cool"), state],
|
|
|
121 |
|
122 |
# --- Display UI ---
|
123 |
def display_ui():
|
|
|
124 |
def get_random_cool_images(n):
|
125 |
cool_samples = [d for d in labeled_data if d["label"] == "cool"]
|
126 |
return [Image.frombytes("RGB", (384, 384), s["image"]) for s in cool_samples] if len(cool_samples) >= n else []
|
|
|
145 |
with gr.Row():
|
146 |
new_image_component = gr.Image(label="New Image", type="pil")
|
147 |
metadata_display = gr.Textbox(label="Metadata (Bounds)")
|
|
|
148 |
with gr.Row():
|
149 |
cool_images_gallery = gr.Gallery(label="Cool Examples", value=[], columns=DISPLAY_N_COOL)
|
150 |
|
|
|
172 |
with gr.TabItem("Display"):
|
173 |
display_ui()
|
174 |
|
175 |
+
demo.launch(debug=True)
|