Spaces:
Running
Running
wip
Browse files- .gitattributes +2 -0
- app.py +83 -0
- gbif_full_filtered.csv +3 -0
- stl_species.npy +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
gbif_full_filtered.csv filter=lfs diff=lfs merge=lfs -text
|
37 |
+
stl_species.npy filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from copy import deepcopy
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
|
8 |
+
def get_index_of_element_containing_word(lst, word):
|
9 |
+
# Create a list of indices where the word is found in the element
|
10 |
+
indices = [i for i, element in enumerate(lst) if word.lower() in element.lower()]
|
11 |
+
# Return the first index found, or -1 if the word is not found in any element
|
12 |
+
return indices[0] if indices else -1
|
13 |
+
|
14 |
+
pred_global = None
|
15 |
+
|
16 |
+
stl_preds = np.load("stl_species.npy")
|
17 |
+
df = pd.read_csv("gbif_full_filtered.csv")
|
18 |
+
obs = df.drop_duplicates(subset=["species"])["species"].tolist()
|
19 |
+
obs = list(sorted(obs))
|
20 |
+
del df
|
21 |
+
|
22 |
+
|
23 |
+
def update_fn(val):
|
24 |
+
if val=="Class":
|
25 |
+
return gr.Dropdown(label="Name", choices=class_list, interactive=True)
|
26 |
+
elif val=="Order":
|
27 |
+
return gr.Dropdown(label="Name", choices=order_list, interactive=True)
|
28 |
+
elif val=="Family":
|
29 |
+
return gr.Dropdown(label="Name", choices=family_list, interactive=True)
|
30 |
+
elif val=="Genus":
|
31 |
+
return gr.Dropdown(label="Name", choices=genus_list, interactive=True)
|
32 |
+
elif val=="Species":
|
33 |
+
return gr.Dropdown(label="Name", choices=obs, interactive=True)
|
34 |
+
|
35 |
+
def text_fn(taxon, name):
|
36 |
+
global pred_global
|
37 |
+
|
38 |
+
species_index = get_index_of_element_containing_word(obs, name)
|
39 |
+
preds = np.flip(stl_preds[:, species_index].reshape(510, 510), 1)
|
40 |
+
|
41 |
+
pred_global = preds
|
42 |
+
cmap = plt.get_cmap('plasma')
|
43 |
+
|
44 |
+
rgba_img = cmap(preds)
|
45 |
+
rgb_img = np.delete(rgba_img, 3, 2)
|
46 |
+
#return gr.Image(preds, label="Predicted Heatmap", visible=True)
|
47 |
+
return rgb_img
|
48 |
+
|
49 |
+
def thresh_fn(val):
|
50 |
+
global pred_global
|
51 |
+
preds = deepcopy(pred_global)
|
52 |
+
preds[preds<val] = 0
|
53 |
+
preds[preds>=val] = 1
|
54 |
+
cmap = plt.get_cmap('plasma')
|
55 |
+
|
56 |
+
rgba_img = cmap(preds)
|
57 |
+
rgb_img = np.delete(rgba_img, 3, 2)
|
58 |
+
return rgb_img
|
59 |
+
|
60 |
+
with gr.Blocks() as demo:
|
61 |
+
gr.Markdown(
|
62 |
+
"""
|
63 |
+
# Hierarchical Species Distribution Model!
|
64 |
+
This model predicts the distribution of species based on geographic, environmental, and natural language features.
|
65 |
+
""")
|
66 |
+
with gr.Row():
|
67 |
+
inp = gr.Dropdown(label="Taxonomic Hierarchy", choices=["Species"])
|
68 |
+
out = gr.Dropdown(label="Name", interactive=True)
|
69 |
+
inp.change(update_fn, inp, out)
|
70 |
+
|
71 |
+
with gr.Row():
|
72 |
+
check_button = gr.Button("Run Model")
|
73 |
+
|
74 |
+
with gr.Row():
|
75 |
+
slider = gr.Slider(minimum=0, maximum=1, step=0.01, default=0.5, label="Confidence Threshold")
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
pred = gr.Image(label="Predicted Heatmap", visible=True)
|
79 |
+
|
80 |
+
check_button.click(text_fn, inputs=[inp, out], outputs=[pred])
|
81 |
+
slider.change(thresh_fn, slider, outputs=pred)
|
82 |
+
|
83 |
+
demo.launch()
|
gbif_full_filtered.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f6e3a753d4444ca34e76402d1081de32412fd8bd6c818747b3a47b244c1ff70c
|
3 |
+
size 1402953121
|
stl_species.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:80be6ce0ac0dc1d11e9644f74aedce5177d66a66d4eb688b33c4b91283e5686c
|
3 |
+
size 6212228528
|