Spaces:
Running
Running
Commit
·
ccf126e
1
Parent(s):
c180063
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ def return_text(habitat_label, habitat_score, confidence):
|
|
| 22 |
text = f"We can't assign an habitat to this vegetation plot with a confidence of at least {confidence}%."
|
| 23 |
return text
|
| 24 |
|
| 25 |
-
def
|
| 26 |
floraveg_url = f"https://floraveg.eu/habitat/overview/{habitat_label}"
|
| 27 |
response = requests.get(floraveg_url)
|
| 28 |
if response.status_code == 200:
|
|
@@ -39,6 +39,22 @@ def return_image(habitat_label, habitat_score, confidence):
|
|
| 39 |
image = gr.Image(value=image_url)
|
| 40 |
return image
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def classification(text, typology, confidence, task):
|
| 43 |
model = return_model(task)
|
| 44 |
dataset = return_dataset()
|
|
@@ -47,7 +63,7 @@ def classification(text, typology, confidence, task):
|
|
| 47 |
habitat_label = dataset['train'].features['label'].names[int(habitat_label.split('_')[1])]
|
| 48 |
habitat_score = result[0]['score']
|
| 49 |
formatted_output = return_text(habitat_label, habitat_score, confidence)
|
| 50 |
-
image_output =
|
| 51 |
return formatted_output, image_output
|
| 52 |
|
| 53 |
def masking(text, task):
|
|
@@ -55,8 +71,9 @@ def masking(text, task):
|
|
| 55 |
masked_text = text + ', [MASK] [MASK]'
|
| 56 |
pred = model(masked_text, top_k=1)
|
| 57 |
new_species = [pred[i][0]['token_str'] for i in range(len(pred))]
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
return text, image
|
| 61 |
|
| 62 |
def plantbert(text, typology, confidence, task):
|
|
|
|
| 22 |
text = f"We can't assign an habitat to this vegetation plot with a confidence of at least {confidence}%."
|
| 23 |
return text
|
| 24 |
|
| 25 |
+
def return_habitat_image(habitat_label, habitat_score, confidence):
|
| 26 |
floraveg_url = f"https://floraveg.eu/habitat/overview/{habitat_label}"
|
| 27 |
response = requests.get(floraveg_url)
|
| 28 |
if response.status_code == 200:
|
|
|
|
| 39 |
image = gr.Image(value=image_url)
|
| 40 |
return image
|
| 41 |
|
| 42 |
+
def return_species_image(species):
|
| 43 |
+
species = species[0].capitalize() + species[1:]
|
| 44 |
+
floraveg_url = f"https://floraveg.eu/taxon/overview/{species}"
|
| 45 |
+
response = requests.get(floraveg_url)
|
| 46 |
+
if response.status_code == 200:
|
| 47 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 48 |
+
img_tag = soup.find('img', src=lambda x: x and x.startswith("https://files.ibot.cas.cz/cevs/images/taxa/large/"))
|
| 49 |
+
if img_tag:
|
| 50 |
+
image_url = img_tag['src']
|
| 51 |
+
else:
|
| 52 |
+
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 53 |
+
else:
|
| 54 |
+
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 55 |
+
image = gr.Image(value=image_url)
|
| 56 |
+
return image
|
| 57 |
+
|
| 58 |
def classification(text, typology, confidence, task):
|
| 59 |
model = return_model(task)
|
| 60 |
dataset = return_dataset()
|
|
|
|
| 63 |
habitat_label = dataset['train'].features['label'].names[int(habitat_label.split('_')[1])]
|
| 64 |
habitat_score = result[0]['score']
|
| 65 |
formatted_output = return_text(habitat_label, habitat_score, confidence)
|
| 66 |
+
image_output = return_habitat_image(habitat_label, habitat_score, confidence)
|
| 67 |
return formatted_output, image_output
|
| 68 |
|
| 69 |
def masking(text, task):
|
|
|
|
| 71 |
masked_text = text + ', [MASK] [MASK]'
|
| 72 |
pred = model(masked_text, top_k=1)
|
| 73 |
new_species = [pred[i][0]['token_str'] for i in range(len(pred))]
|
| 74 |
+
new_species = ' '.join(new_species)
|
| 75 |
+
text = text + ', ' + new_species
|
| 76 |
+
image = return_species_image(new_species)
|
| 77 |
return text, image
|
| 78 |
|
| 79 |
def plantbert(text, typology, confidence, task):
|