Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,11 @@ import random
|
|
| 7 |
classification_model = pipeline("text-classification", model="plantbert_text_classification_model", tokenizer="plantbert_text_classification_model")
|
| 8 |
mask_model = pipeline("fill-mask", model="plantbert_fill_mask_model", tokenizer="plantbert_fill_mask_model", top_k=14189)
|
| 9 |
|
| 10 |
-
def return_text(habitat_label
|
| 11 |
-
|
| 12 |
-
text = f"This vegetation plot belongs to the habitat {habitat_label} with the probability {habitat_score*100:.2f}%."
|
| 13 |
-
else:
|
| 14 |
-
text = f"We can't assign an habitat to this vegetation plot with a confidence of at least {confidence}%."
|
| 15 |
return text
|
| 16 |
|
| 17 |
-
def return_habitat_image(habitat_label
|
| 18 |
floraveg_url = f"https://floraveg.eu/habitat/overview/{habitat_label}"
|
| 19 |
response = requests.get(floraveg_url)
|
| 20 |
if response.status_code == 200:
|
|
@@ -26,8 +23,6 @@ def return_habitat_image(habitat_label, habitat_score, confidence):
|
|
| 26 |
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 27 |
else:
|
| 28 |
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 29 |
-
if habitat_score*100 < confidence:
|
| 30 |
-
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 31 |
image_url = "https://www.commissionoceanindien.org/wp-content/uploads/2018/07/plantnet.jpg"
|
| 32 |
image = gr.Image(value=image_url)
|
| 33 |
return image
|
|
@@ -71,13 +66,12 @@ def gbif_normalization(text):
|
|
| 71 |
text = text.lower()
|
| 72 |
return text
|
| 73 |
|
| 74 |
-
def classification(text
|
| 75 |
text = gbif_normalization(text)
|
| 76 |
result = classification_model(text)
|
| 77 |
habitat_label = result[0]['label']
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
image_output = return_habitat_image(habitat_label, habitat_score, confidence)
|
| 81 |
return formatted_output, image_output
|
| 82 |
|
| 83 |
def masking(text):
|
|
@@ -159,14 +153,12 @@ with gr.Blocks() as demo:
|
|
| 159 |
with gr.Row():
|
| 160 |
with gr.Column():
|
| 161 |
species = gr.Textbox(lines=2, label="Species", placeholder="Enter a list of comma-separated binomial names here.")
|
| 162 |
-
typology = gr.Dropdown(["EUNIS"], value="EUNIS", label="Typology", info="Will add more typologies later!")
|
| 163 |
-
confidence = gr.Slider(0, 100, value=90, label="Confidence", info="Choose the level of confidence for the prediction.")
|
| 164 |
with gr.Column():
|
| 165 |
text_output_1 = gr.Textbox()
|
| 166 |
text_output_2 = gr.Image()
|
| 167 |
text_button = gr.Button("Classify")
|
| 168 |
gr.Markdown("""<h5 style="text-align: center;">An example of input</h5>""")
|
| 169 |
-
gr.Examples([["sparganium erectum, calystegia sepium, persicaria amphibia"
|
| 170 |
|
| 171 |
with gr.Tab("Missing species finding"):
|
| 172 |
gr.Markdown("""<h3 style="text-align: center;">Finding the missing species!</h3>""")
|
|
|
|
| 7 |
classification_model = pipeline("text-classification", model="plantbert_text_classification_model", tokenizer="plantbert_text_classification_model")
|
| 8 |
mask_model = pipeline("fill-mask", model="plantbert_fill_mask_model", tokenizer="plantbert_fill_mask_model", top_k=14189)
|
| 9 |
|
| 10 |
+
def return_text(habitat_label):
|
| 11 |
+
text = f"This vegetation plot belongs to the habitat {habitat_label}."
|
|
|
|
|
|
|
|
|
|
| 12 |
return text
|
| 13 |
|
| 14 |
+
def return_habitat_image(habitat_label):
|
| 15 |
floraveg_url = f"https://floraveg.eu/habitat/overview/{habitat_label}"
|
| 16 |
response = requests.get(floraveg_url)
|
| 17 |
if response.status_code == 200:
|
|
|
|
| 23 |
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
| 24 |
else:
|
| 25 |
image_url = "https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled-1150x647.png"
|
|
|
|
|
|
|
| 26 |
image_url = "https://www.commissionoceanindien.org/wp-content/uploads/2018/07/plantnet.jpg"
|
| 27 |
image = gr.Image(value=image_url)
|
| 28 |
return image
|
|
|
|
| 66 |
text = text.lower()
|
| 67 |
return text
|
| 68 |
|
| 69 |
+
def classification(text):
|
| 70 |
text = gbif_normalization(text)
|
| 71 |
result = classification_model(text)
|
| 72 |
habitat_label = result[0]['label']
|
| 73 |
+
formatted_output = return_text(habitat_label)
|
| 74 |
+
image_output = return_habitat_image(habitat_label)
|
|
|
|
| 75 |
return formatted_output, image_output
|
| 76 |
|
| 77 |
def masking(text):
|
|
|
|
| 153 |
with gr.Row():
|
| 154 |
with gr.Column():
|
| 155 |
species = gr.Textbox(lines=2, label="Species", placeholder="Enter a list of comma-separated binomial names here.")
|
|
|
|
|
|
|
| 156 |
with gr.Column():
|
| 157 |
text_output_1 = gr.Textbox()
|
| 158 |
text_output_2 = gr.Image()
|
| 159 |
text_button = gr.Button("Classify")
|
| 160 |
gr.Markdown("""<h5 style="text-align: center;">An example of input</h5>""")
|
| 161 |
+
gr.Examples([["sparganium erectum, calystegia sepium, persicaria amphibia"]], [species], [text_output_1, text_output_2], classification, True)
|
| 162 |
|
| 163 |
with gr.Tab("Missing species finding"):
|
| 164 |
gr.Markdown("""<h3 style="text-align: center;">Finding the missing species!</h3>""")
|