Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,11 +16,7 @@ warnings.filterwarnings("ignore", category=FutureWarning)
|
|
| 16 |
|
| 17 |
# Load dataset from Hugging Face
|
| 18 |
dataset = load_dataset("hangunwoo07/Naturing_Bird_Data")
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
dataset = dataset['train']['features'] # Access the train split directly
|
| 22 |
-
|
| 23 |
-
print(dataset)
|
| 24 |
|
| 25 |
# Load bird data
|
| 26 |
with open('DB/bird_data.json', 'r', encoding='utf-8') as f:
|
|
@@ -36,45 +32,16 @@ with open('DB/class_names.json', 'r', encoding='utf-8') as f:
|
|
| 36 |
# Constants
|
| 37 |
DSHS_LOCATION = [36.373719, 127.370415]
|
| 38 |
|
| 39 |
-
def load_bird_image_dataset(dataset_path):
|
| 40 |
-
"""
|
| 41 |
-
Load a bird image dataset stored in a zip file with subfolders for each bird species.
|
| 42 |
-
|
| 43 |
-
Args:
|
| 44 |
-
dataset_path (str): Path to the zip file containing the dataset.
|
| 45 |
-
|
| 46 |
-
Returns:
|
| 47 |
-
dict: A dictionary where the keys are the bird species names and the values are lists of image file paths.
|
| 48 |
-
"""
|
| 49 |
-
bird_images = {}
|
| 50 |
-
|
| 51 |
-
with ZipFile(dataset_path, 'r') as zip_file:
|
| 52 |
-
for filename in zip_file.namelist():
|
| 53 |
-
if filename.endswith('.jpg'):
|
| 54 |
-
# Extract the bird species name from the file path
|
| 55 |
-
species = filename.split('\\')[1]
|
| 56 |
-
|
| 57 |
-
# Initialize the list for the current species if it doesn't exist
|
| 58 |
-
if species not in bird_images:
|
| 59 |
-
bird_images[species] = []
|
| 60 |
-
|
| 61 |
-
# Add the file path to the list for the current species
|
| 62 |
-
bird_images[species].append(filename)
|
| 63 |
-
|
| 64 |
-
print(f"filename: {filename}")
|
| 65 |
-
|
| 66 |
-
return bird_images
|
| 67 |
-
|
| 68 |
def create_image_popup(bird_name, image_filename):
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
encoded = base64.b64encode(image_bytes).decode()
|
| 76 |
return f'<img src="data:image/jpeg;base64,{encoded}" width="200px">'
|
| 77 |
-
|
|
|
|
| 78 |
|
| 79 |
def create_map():
|
| 80 |
"""
|
|
|
|
| 16 |
|
| 17 |
# Load dataset from Hugging Face
|
| 18 |
dataset = load_dataset("hangunwoo07/Naturing_Bird_Data")
|
| 19 |
+
dataset = dataset['train'] # Access the train split directly
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Load bird data
|
| 22 |
with open('DB/bird_data.json', 'r', encoding='utf-8') as f:
|
|
|
|
| 32 |
# Constants
|
| 33 |
DSHS_LOCATION = [36.373719, 127.370415]
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
def create_image_popup(bird_name, image_filename):
|
| 36 |
+
target_image = '/'.join(bird_name, image_filename.split())
|
| 37 |
+
row_index = metadata[metadata['image'] == target_image].index[0] - 1
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
with open(dataset['image'][row_index], 'rb') as image_file:
|
| 41 |
+
encoded = base64.b64encode(image_file.read()).decode()
|
|
|
|
| 42 |
return f'<img src="data:image/jpeg;base64,{encoded}" width="200px">'
|
| 43 |
+
except:
|
| 44 |
+
return ''
|
| 45 |
|
| 46 |
def create_map():
|
| 47 |
"""
|