Spaces:
Running
Running
Update metadata.parquet with "gbif_taxon_id" (#3)
Browse files- Use gbif_taxon_id for GBIF link lookup (e6ca92128986db5f685798081d91fc6d38815a7d)
- components/metadata.parquet +2 -2
- components/query.py +6 -6
components/metadata.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc17e3263f1e735162c5f4f3356c297b3723002258698190657d93f759bd669f
|
3 |
+
size 131082909
|
components/query.py
CHANGED
@@ -42,7 +42,7 @@ def get_sample(df, pred_taxon, rank):
|
|
42 |
'''
|
43 |
logger.info(f"Getting sample for taxon: {pred_taxon} at rank: {rank}")
|
44 |
try:
|
45 |
-
filepath,
|
46 |
except Exception as e:
|
47 |
logger.error(f"Error retrieving sample data: {e}")
|
48 |
return None, f"We encountered the following error trying to retrieve a sample image: {e}."
|
@@ -58,8 +58,8 @@ def get_sample(df, pred_taxon, rank):
|
|
58 |
)
|
59 |
img_resp = requests.get(img_src)
|
60 |
img = Image.open(io.BytesIO(img_resp.content))
|
61 |
-
if
|
62 |
-
gbif_url = GBIF_URL +
|
63 |
if eol_page_id:
|
64 |
eol_url = EOL_URL + eol_page_id
|
65 |
if is_exact:
|
@@ -100,7 +100,7 @@ def get_sample_data(df, pred_taxon, rank):
|
|
100 |
--------
|
101 |
filepath : str
|
102 |
Filepath of selected sample image for predicted taxon.
|
103 |
-
|
104 |
GBIF page ID associated with predicted taxon for more information.
|
105 |
eol_page_id : str
|
106 |
EOL page ID associated with predicted taxon for more information.
|
@@ -125,9 +125,9 @@ def get_sample_data(df, pred_taxon, rank):
|
|
125 |
if exact_df.shape[0] > 0:
|
126 |
df_filtered = exact_df.sample()
|
127 |
full_name = " ".join(df_filtered.select(RANKS[:rank+1]).row(0))
|
128 |
-
return df_filtered["file_path"][0], df_filtered["
|
129 |
|
130 |
# If no exact matches, return any entry with the specified rank
|
131 |
df_filtered = df.sample()
|
132 |
full_name = " ".join(df_filtered.select(RANKS[:rank+1]).row(0)) + " " + " ".join(df_filtered.select(RANKS[rank+1:]).row(0))
|
133 |
-
return df_filtered["file_path"][0], df_filtered["
|
|
|
42 |
'''
|
43 |
logger.info(f"Getting sample for taxon: {pred_taxon} at rank: {rank}")
|
44 |
try:
|
45 |
+
filepath, gbif_taxon_id, eol_page_id, full_name, is_exact = get_sample_data(df, pred_taxon, rank)
|
46 |
except Exception as e:
|
47 |
logger.error(f"Error retrieving sample data: {e}")
|
48 |
return None, f"We encountered the following error trying to retrieve a sample image: {e}."
|
|
|
58 |
)
|
59 |
img_resp = requests.get(img_src)
|
60 |
img = Image.open(io.BytesIO(img_resp.content))
|
61 |
+
if gbif_taxon_id:
|
62 |
+
gbif_url = GBIF_URL + gbif_taxon_id
|
63 |
if eol_page_id:
|
64 |
eol_url = EOL_URL + eol_page_id
|
65 |
if is_exact:
|
|
|
100 |
--------
|
101 |
filepath : str
|
102 |
Filepath of selected sample image for predicted taxon.
|
103 |
+
gbif_taxon_id: str
|
104 |
GBIF page ID associated with predicted taxon for more information.
|
105 |
eol_page_id : str
|
106 |
EOL page ID associated with predicted taxon for more information.
|
|
|
125 |
if exact_df.shape[0] > 0:
|
126 |
df_filtered = exact_df.sample()
|
127 |
full_name = " ".join(df_filtered.select(RANKS[:rank+1]).row(0))
|
128 |
+
return df_filtered["file_path"][0], df_filtered["gbif_taxon_id"].cast(pl.String)[0], df_filtered["eol_page_id"].cast(pl.String)[0], full_name, True
|
129 |
|
130 |
# If no exact matches, return any entry with the specified rank
|
131 |
df_filtered = df.sample()
|
132 |
full_name = " ".join(df_filtered.select(RANKS[:rank+1]).row(0)) + " " + " ".join(df_filtered.select(RANKS[rank+1:]).row(0))
|
133 |
+
return df_filtered["file_path"][0], df_filtered["gbif_taxon_id"].cast(pl.String)[0], df_filtered["eol_page_id"].cast(pl.String)[0], full_name, False
|