File size: 2,834 Bytes
465c443
 
 
 
4f33c08
465c443
 
4f33c08
465c443
 
4f33c08
 
 
 
 
465c443
 
4f33c08
 
 
 
 
 
 
 
 
465c443
 
 
 
 
 
 
 
 
 
4f33c08
 
 
465c443
4f33c08
 
465c443
4f33c08
465c443
 
4f33c08
 
 
 
465c443
4f33c08
465c443
4f33c08
 
 
465c443
4f33c08
 
 
 
 
465c443
4f33c08
465c443
4f33c08
 
 
 
 
 
 
 
 
 
 
 
 
465c443
4f33c08
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import pandas as pd
from PIL import Image
from itertools import islice
import earthview as ev  # Your custom library
import gradio as gr

# Path to the first shard of the Satellogic dataset
filename = os.path.join("dataset", "satellogic", "train-00000-of-00065.parquet")

# Check if the file exists
if not os.path.isfile(filename):
    raise FileNotFoundError(f"{filename} not found")

# Loads a dataset with pandas, this loads a single file
data = pd.read_parquet(filename)

# Global variables to manage state
current_image = None
current_metadata_index = 0
ratings = []
image_id = 0
bounds = []
timestamps = []

# Function to transform a metadata sample to bounds and timestamps
def item_to_bounds_timestamps(sample):
    bounds_list = sample["metadata"]["bounds"]
    timestamp_list = sample["metadata"]["timestamp"]
    bounds = []
    timestamps = []
    for b, t in zip(bounds_list, timestamp_list):
        bounds.append(b)
        timestamps.append(t)
    return bounds, timestamps

# Function to load and display the next image
def load_next_image():
    global current_image, image_id, current_metadata_index, bounds, timestamps

    if current_metadata_index >= len(data):
        return None, "No more images", None

    sample = data.iloc[current_metadata_index]
    bounds_sample, timestamps_sample = item_to_bounds_timestamps(sample)

    # Use earthview library to convert arrays to PIL images
    sample = ev.item_to_images("satellogic", sample.to_dict())
    current_image = sample["rgb"][0]  # Get the first image
    image_id += 1

    return current_image, f"Image ID: {image_id}", bounds_sample[0]

# Function to handle rating submission
def submit_rating(rating, bounds_str):
    global image_id, current_metadata_index, ratings, bounds, timestamps

    ratings.append(rating)
    bounds.append(bounds_str)
    timestamps.append("timestamp")  # Use a valid timestamp if available
    
    current_metadata_index += 1

    return load_next_image()

# Gradio Interface Layout
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            image_display = gr.Image(label="Satellite Image", type="pil")
            image_id_display = gr.Textbox(label="Image ID")
            bounds_display = gr.Textbox(label="Bounds")
            load_button = gr.Button("Load Next Image")
            load_button.click(fn=load_next_image, outputs=[image_display, image_id_display, bounds_display])
        with gr.Column():
            rating_radio = gr.Radio(["0", "1"], label="Rating (0 = No, 1 = Yes)")
            submit_button = gr.Button("Submit Rating")
            submit_button.click(fn=lambda rating, bounds_str: submit_rating(rating, bounds_str), inputs=[rating_radio, bounds_display], outputs=[image_display, image_id_display, bounds_display])

# Launch the Gradio interface
demo.launch()