Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,6 @@ import random
|
|
5 |
import pandas as pd
|
6 |
import os
|
7 |
from itertools import islice
|
8 |
-
import pyarrow as pa
|
9 |
-
import pyarrow.parquet as pq
|
10 |
|
11 |
# Configuration
|
12 |
chunk_size = 100 # Size of the chunks to shuffle
|
@@ -18,7 +16,7 @@ data_iter = iter(dataset)
|
|
18 |
shuffled_chunk = [] # Initialize an empty list to hold the current chunk
|
19 |
chunk_iter = None # Initialize the chunk iterator
|
20 |
|
21 |
-
# Initialize or load labels DataFrame
|
22 |
labels_df = None
|
23 |
if os.path.exists(label_file):
|
24 |
labels_df = pd.read_csv(label_file)
|
@@ -34,7 +32,7 @@ def get_next_image():
|
|
34 |
chunk = list(islice(data_iter, chunk_size))
|
35 |
if not chunk: # If the dataset is exhausted, reset the iterator
|
36 |
print("Dataset exhausted, resetting iterator.")
|
37 |
-
|
38 |
chunk = list(islice(data_iter, chunk_size))
|
39 |
if not chunk:
|
40 |
print("Still no data after reset.")
|
@@ -53,7 +51,9 @@ def get_next_image():
|
|
53 |
google_maps_link = utils.get_google_map_link(sample, "satellogic")
|
54 |
image_id = str(bounds)
|
55 |
|
56 |
-
if image_id not in labels_df["image_id"].values:
|
|
|
|
|
57 |
return image, image_id, bounds, google_maps_link
|
58 |
except StopIteration:
|
59 |
# Current chunk is exhausted, reset chunk variables to get a new one in the next iteration
|
@@ -86,6 +86,17 @@ def save_labels_parquet():
|
|
86 |
else:
|
87 |
return None
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
# Gradio interface
|
90 |
with gr.Blocks() as iface:
|
91 |
image_out = gr.Image(label="Satellite Image")
|
@@ -95,6 +106,7 @@ with gr.Blocks() as iface:
|
|
95 |
rating_radio = gr.Radio(["Cool", "Not Cool"], label="Rating")
|
96 |
with gr.Row():
|
97 |
submit_button = gr.Button("Submit Rating")
|
|
|
98 |
download_button = gr.Button("Download Labels (Parquet)")
|
99 |
download_output = gr.File(label="Download Labeled Data")
|
100 |
|
@@ -110,6 +122,12 @@ with gr.Blocks() as iface:
|
|
110 |
outputs=[download_output],
|
111 |
)
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# Load the first image
|
114 |
initial_image, initial_image_id, initial_bounds, initial_google_maps_link = get_next_image()
|
115 |
|
|
|
5 |
import pandas as pd
|
6 |
import os
|
7 |
from itertools import islice
|
|
|
|
|
8 |
|
9 |
# Configuration
|
10 |
chunk_size = 100 # Size of the chunks to shuffle
|
|
|
16 |
shuffled_chunk = [] # Initialize an empty list to hold the current chunk
|
17 |
chunk_iter = None # Initialize the chunk iterator
|
18 |
|
19 |
+
# Initialize or load labels DataFrame
|
20 |
labels_df = None
|
21 |
if os.path.exists(label_file):
|
22 |
labels_df = pd.read_csv(label_file)
|
|
|
32 |
chunk = list(islice(data_iter, chunk_size))
|
33 |
if not chunk: # If the dataset is exhausted, reset the iterator
|
34 |
print("Dataset exhausted, resetting iterator.")
|
35 |
+
reset_dataset_iterator() # Use the reset function
|
36 |
chunk = list(islice(data_iter, chunk_size))
|
37 |
if not chunk:
|
38 |
print("Still no data after reset.")
|
|
|
51 |
google_maps_link = utils.get_google_map_link(sample, "satellogic")
|
52 |
image_id = str(bounds)
|
53 |
|
54 |
+
if labels_df is not None and image_id not in labels_df["image_id"].values:
|
55 |
+
return image, image_id, bounds, google_maps_link
|
56 |
+
elif labels_df is None: # Handle case where labels_df is not initialized yet
|
57 |
return image, image_id, bounds, google_maps_link
|
58 |
except StopIteration:
|
59 |
# Current chunk is exhausted, reset chunk variables to get a new one in the next iteration
|
|
|
86 |
else:
|
87 |
return None
|
88 |
|
89 |
+
def reset_dataset_iterator():
|
90 |
+
global data_iter, shuffled_chunk, chunk_iter
|
91 |
+
data_iter = iter(ev.load_dataset("satellogic", streaming=True))
|
92 |
+
shuffled_chunk = []
|
93 |
+
chunk_iter = None
|
94 |
+
|
95 |
+
def load_different_batch():
|
96 |
+
print("Loading a different batch of images...")
|
97 |
+
reset_dataset_iterator()
|
98 |
+
return get_next_image() # Return the first image from the new batch
|
99 |
+
|
100 |
# Gradio interface
|
101 |
with gr.Blocks() as iface:
|
102 |
image_out = gr.Image(label="Satellite Image")
|
|
|
106 |
rating_radio = gr.Radio(["Cool", "Not Cool"], label="Rating")
|
107 |
with gr.Row():
|
108 |
submit_button = gr.Button("Submit Rating")
|
109 |
+
different_batch_button = gr.Button("Load Different Batch") # New button
|
110 |
download_button = gr.Button("Download Labels (Parquet)")
|
111 |
download_output = gr.File(label="Download Labeled Data")
|
112 |
|
|
|
122 |
outputs=[download_output],
|
123 |
)
|
124 |
|
125 |
+
different_batch_button.click(
|
126 |
+
fn=load_different_batch,
|
127 |
+
inputs=[],
|
128 |
+
outputs=[image_out, image_id_out, bounds_out, google_maps_link_out]
|
129 |
+
)
|
130 |
+
|
131 |
# Load the first image
|
132 |
initial_image, initial_image_id, initial_bounds, initial_google_maps_link = get_next_image()
|
133 |
|