Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,8 @@
|
|
| 1 |
-
import os
|
| 2 |
import pandas as pd
|
| 3 |
from PIL import Image
|
| 4 |
-
|
| 5 |
-
import earthview as ev # Your custom library
|
| 6 |
import gradio as gr
|
| 7 |
-
|
| 8 |
-
# Path to the first shard of the Satellogic dataset
|
| 9 |
-
filename = os.path.join("dataset", "satellogic", "train-00000-of-00065.parquet")
|
| 10 |
-
|
| 11 |
-
# Check if the file exists
|
| 12 |
-
if not os.path.isfile(filename):
|
| 13 |
-
raise FileNotFoundError(f"{filename} not found")
|
| 14 |
-
|
| 15 |
-
# Loads a dataset with pandas, this loads a single file
|
| 16 |
-
data = pd.read_parquet(filename)
|
| 17 |
|
| 18 |
# Global variables to manage state
|
| 19 |
current_image = None
|
|
@@ -34,22 +23,26 @@ def item_to_bounds_timestamps(sample):
|
|
| 34 |
timestamps.append(t)
|
| 35 |
return bounds, timestamps
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
# Function to load and display the next image
|
| 38 |
def load_next_image():
|
| 39 |
global current_image, image_id, current_metadata_index, bounds, timestamps
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
sample = ev.item_to_images("satellogic", sample.to_dict())
|
| 49 |
-
current_image = sample["rgb"][0] # Get the first image
|
| 50 |
-
image_id += 1
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
# Function to handle rating submission
|
| 55 |
def submit_rating(rating, bounds_str):
|
|
@@ -58,7 +51,7 @@ def submit_rating(rating, bounds_str):
|
|
| 58 |
ratings.append(rating)
|
| 59 |
bounds.append(bounds_str)
|
| 60 |
timestamps.append("timestamp") # Use a valid timestamp if available
|
| 61 |
-
|
| 62 |
current_metadata_index += 1
|
| 63 |
|
| 64 |
return load_next_image()
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
from PIL import Image
|
| 3 |
+
import earthview as ev
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
+
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Global variables to manage state
|
| 8 |
current_image = None
|
|
|
|
| 23 |
timestamps.append(t)
|
| 24 |
return bounds, timestamps
|
| 25 |
|
| 26 |
+
# Load the dataset directly from Hugging Face
|
| 27 |
+
data = load_dataset("satellogic/EarthView", "satellogic", split="train", streaming=True)
|
| 28 |
+
|
| 29 |
# Function to load and display the next image
|
| 30 |
def load_next_image():
|
| 31 |
global current_image, image_id, current_metadata_index, bounds, timestamps
|
| 32 |
|
| 33 |
+
try:
|
| 34 |
+
sample = next(iter(data))
|
| 35 |
+
bounds_sample, timestamps_sample = item_to_bounds_timestamps(sample)
|
| 36 |
|
| 37 |
+
# Use earthview library to convert arrays to PIL images
|
| 38 |
+
sample = ev.item_to_images("satellogic", sample)
|
| 39 |
+
current_image = sample["rgb"][0] # Get the first image
|
| 40 |
+
image_id += 1
|
| 41 |
|
| 42 |
+
return current_image, f"Image ID: {image_id}", bounds_sample[0]
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
except StopIteration:
|
| 45 |
+
return None, "No more images", None
|
| 46 |
|
| 47 |
# Function to handle rating submission
|
| 48 |
def submit_rating(rating, bounds_str):
|
|
|
|
| 51 |
ratings.append(rating)
|
| 52 |
bounds.append(bounds_str)
|
| 53 |
timestamps.append("timestamp") # Use a valid timestamp if available
|
| 54 |
+
|
| 55 |
current_metadata_index += 1
|
| 56 |
|
| 57 |
return load_next_image()
|