Spaces:
Running
Running
Commit
·
8da738a
1
Parent(s):
c82104c
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import requests
|
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
|
| 6 |
# Initialize models
|
| 7 |
-
classification_model = pipeline("text-classification", model="models/text_classification_model", tokenizer="models/text_classification_model")
|
| 8 |
mask_model = pipeline("fill-mask", model="models/fill_mask_model", tokenizer="models/fill_mask_model", top_k=100)
|
| 9 |
|
| 10 |
def return_habitat_image(habitat_label):
|
|
@@ -65,9 +65,12 @@ def gbif_normalization(text):
|
|
| 65 |
def classification(text, k):
|
| 66 |
text = gbif_normalization(text)
|
| 67 |
result = classification_model(text)
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
return text, image_output
|
| 72 |
|
| 73 |
def masking(text):
|
|
|
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
|
| 6 |
# Initialize models
|
| 7 |
+
classification_model = pipeline("text-classification", model="models/text_classification_model", tokenizer="models/text_classification_model", top_k=5)
|
| 8 |
mask_model = pipeline("fill-mask", model="models/fill_mask_model", tokenizer="models/fill_mask_model", top_k=100)
|
| 9 |
|
| 10 |
def return_habitat_image(habitat_label):
|
|
|
|
| 65 |
def classification(text, k):
|
| 66 |
text = gbif_normalization(text)
|
| 67 |
result = classification_model(text)
|
| 68 |
+
habitat_labels = [res['label'] for res in result[:k]]
|
| 69 |
+
if k == 1:
|
| 70 |
+
text = f"This vegetation plot belongs to the habitat {habitat_labels[0]}."
|
| 71 |
+
else:
|
| 72 |
+
text = f"This vegetation plot belongs to the habitats {', '.join(habitat_labels[:-1])} and {habitat_labels[-1]}."
|
| 73 |
+
image_output = return_habitat_image(habitat_labels[0])
|
| 74 |
return text, image_output
|
| 75 |
|
| 76 |
def masking(text):
|