Spaces:
Running
Running
Commit
·
94ce85f
1
Parent(s):
da4214f
Update app.py
Browse files
app.py
CHANGED
@@ -86,13 +86,22 @@ def classification(text, typology, confidence):
|
|
86 |
def masking(text):
|
87 |
text = gbif_normalization(text)
|
88 |
masked_text = text + ', [MASK] [MASK]'
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
image = return_species_image(new_species)
|
97 |
return text, image
|
98 |
|
|
|
86 |
def masking(text):
|
87 |
text = gbif_normalization(text)
|
88 |
masked_text = text + ', [MASK] [MASK]'
|
89 |
+
pred_genus = mask_model(masked_text, top_k=3)
|
90 |
+
for i in range(3):
|
91 |
+
new_genus = pred_genus[0][i]['token_str']
|
92 |
+
masked_text = text + f', {new_genus} [MASK]'
|
93 |
+
pred_epithet = mask_model(masked_text, top_k=3)
|
94 |
+
for j in range(3):
|
95 |
+
new_epithet = pred_epithet[j]['token_str']
|
96 |
+
new_species = new_genus + ' ' + new_epithet
|
97 |
+
url_species = f"https://api.gbif.org/v1/species/match?name={new_species}"
|
98 |
+
r = requests.get(url_species)
|
99 |
+
r = r.json()
|
100 |
+
if new_species not in text and r["matchType"] != "NONE":
|
101 |
+
text = f"The last species from this vegetation plot is probably {new_species}."
|
102 |
+
image = return_species_image(new_species)
|
103 |
+
return text, image
|
104 |
+
text = f"We can't find the last species from this vegetation plot."
|
105 |
image = return_species_image(new_species)
|
106 |
return text, image
|
107 |
|