Update app.py
Browse files
app.py
CHANGED
|
@@ -56,29 +56,30 @@ def call_gemini(prompt, api_key):
|
|
| 56 |
|
| 57 |
country_codes = {
|
| 58 |
|
| 59 |
-
"
|
| 60 |
"السودان": "SD",
|
| 61 |
|
| 62 |
-
"
|
| 63 |
"مصر": "EG",
|
| 64 |
|
| 65 |
-
"
|
| 66 |
"كينيا": "KE",
|
| 67 |
|
| 68 |
-
"
|
| 69 |
"إثيوبيا": "ET",
|
| 70 |
|
| 71 |
-
"
|
| 72 |
"السعودية": "SA",
|
| 73 |
|
| 74 |
-
"
|
| 75 |
"الهند": "IN",
|
| 76 |
|
| 77 |
-
"
|
| 78 |
-
"
|
|
|
|
| 79 |
"امريكا": "US",
|
| 80 |
|
| 81 |
-
"
|
| 82 |
"كندا": "CA"
|
| 83 |
}
|
| 84 |
|
|
@@ -188,7 +189,10 @@ def get_species_links(species_name, country):
|
|
| 188 |
# GBIF
|
| 189 |
# -------------------------------------------------
|
| 190 |
|
| 191 |
-
gbif_api =
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
try:
|
| 194 |
|
|
@@ -196,7 +200,10 @@ def get_species_links(species_name, country):
|
|
| 196 |
|
| 197 |
if "usageKey" in r:
|
| 198 |
|
| 199 |
-
gbif_link =
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
links.append(
|
| 202 |
f"- [GBIF Species Page]({gbif_link})"
|
|
@@ -211,7 +218,9 @@ def get_species_links(species_name, country):
|
|
| 211 |
|
| 212 |
wiki_name = clean_name.replace(" ", "_")
|
| 213 |
|
| 214 |
-
wiki_url =
|
|
|
|
|
|
|
| 215 |
|
| 216 |
links.append(
|
| 217 |
f"- [Wikipedia Article]({wiki_url})"
|
|
@@ -247,7 +256,10 @@ def get_species_links(species_name, country):
|
|
| 247 |
# Encyclopedia of Life
|
| 248 |
# -------------------------------------------------
|
| 249 |
|
| 250 |
-
eol =
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
links.append(
|
| 253 |
f"- [Encyclopedia of Life]({eol})"
|
|
@@ -306,7 +318,7 @@ def get_species_links(species_name, country):
|
|
| 306 |
)
|
| 307 |
|
| 308 |
# -------------------------------------------------
|
| 309 |
-
# Conservation
|
| 310 |
# -------------------------------------------------
|
| 311 |
|
| 312 |
conservation = (
|
|
@@ -347,21 +359,33 @@ species_type = st.selectbox(
|
|
| 347 |
|
| 348 |
if st.button("Search Biodiversity"):
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
# -------------------------------------------------
|
| 351 |
# VALIDATION
|
| 352 |
# -------------------------------------------------
|
| 353 |
|
| 354 |
if not country:
|
| 355 |
|
| 356 |
-
st.warning(
|
|
|
|
|
|
|
| 357 |
|
| 358 |
st.stop()
|
| 359 |
|
| 360 |
-
country_code = country_codes.get(country)
|
| 361 |
-
|
| 362 |
if not country_code:
|
| 363 |
|
| 364 |
-
st.error(
|
|
|
|
|
|
|
| 365 |
|
| 366 |
st.stop()
|
| 367 |
|
|
|
|
| 56 |
|
| 57 |
country_codes = {
|
| 58 |
|
| 59 |
+
"sudan": "SD",
|
| 60 |
"السودان": "SD",
|
| 61 |
|
| 62 |
+
"egypt": "EG",
|
| 63 |
"مصر": "EG",
|
| 64 |
|
| 65 |
+
"kenya": "KE",
|
| 66 |
"كينيا": "KE",
|
| 67 |
|
| 68 |
+
"ethiopia": "ET",
|
| 69 |
"إثيوبيا": "ET",
|
| 70 |
|
| 71 |
+
"saudi arabia": "SA",
|
| 72 |
"السعودية": "SA",
|
| 73 |
|
| 74 |
+
"india": "IN",
|
| 75 |
"الهند": "IN",
|
| 76 |
|
| 77 |
+
"usa": "US",
|
| 78 |
+
"united states": "US",
|
| 79 |
+
"america": "US",
|
| 80 |
"امريكا": "US",
|
| 81 |
|
| 82 |
+
"canada": "CA",
|
| 83 |
"كندا": "CA"
|
| 84 |
}
|
| 85 |
|
|
|
|
| 189 |
# GBIF
|
| 190 |
# -------------------------------------------------
|
| 191 |
|
| 192 |
+
gbif_api = (
|
| 193 |
+
f"https://api.gbif.org/v1/species/match?"
|
| 194 |
+
f"name={encoded_species}"
|
| 195 |
+
)
|
| 196 |
|
| 197 |
try:
|
| 198 |
|
|
|
|
| 200 |
|
| 201 |
if "usageKey" in r:
|
| 202 |
|
| 203 |
+
gbif_link = (
|
| 204 |
+
f"https://www.gbif.org/species/"
|
| 205 |
+
f"{r['usageKey']}"
|
| 206 |
+
)
|
| 207 |
|
| 208 |
links.append(
|
| 209 |
f"- [GBIF Species Page]({gbif_link})"
|
|
|
|
| 218 |
|
| 219 |
wiki_name = clean_name.replace(" ", "_")
|
| 220 |
|
| 221 |
+
wiki_url = (
|
| 222 |
+
f"https://en.wikipedia.org/wiki/{wiki_name}"
|
| 223 |
+
)
|
| 224 |
|
| 225 |
links.append(
|
| 226 |
f"- [Wikipedia Article]({wiki_url})"
|
|
|
|
| 256 |
# Encyclopedia of Life
|
| 257 |
# -------------------------------------------------
|
| 258 |
|
| 259 |
+
eol = (
|
| 260 |
+
f"https://eol.org/search?q="
|
| 261 |
+
f"{encoded_species}"
|
| 262 |
+
)
|
| 263 |
|
| 264 |
links.append(
|
| 265 |
f"- [Encyclopedia of Life]({eol})"
|
|
|
|
| 318 |
)
|
| 319 |
|
| 320 |
# -------------------------------------------------
|
| 321 |
+
# Conservation
|
| 322 |
# -------------------------------------------------
|
| 323 |
|
| 324 |
conservation = (
|
|
|
|
| 359 |
|
| 360 |
if st.button("Search Biodiversity"):
|
| 361 |
|
| 362 |
+
# -------------------------------------------------
|
| 363 |
+
# CLEAN COUNTRY INPUT
|
| 364 |
+
# -------------------------------------------------
|
| 365 |
+
|
| 366 |
+
country_clean = country.strip().lower()
|
| 367 |
+
|
| 368 |
+
country_code = country_codes.get(
|
| 369 |
+
country_clean
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
# -------------------------------------------------
|
| 373 |
# VALIDATION
|
| 374 |
# -------------------------------------------------
|
| 375 |
|
| 376 |
if not country:
|
| 377 |
|
| 378 |
+
st.warning(
|
| 379 |
+
"Please enter a country."
|
| 380 |
+
)
|
| 381 |
|
| 382 |
st.stop()
|
| 383 |
|
|
|
|
|
|
|
| 384 |
if not country_code:
|
| 385 |
|
| 386 |
+
st.error(
|
| 387 |
+
f"Country '{country}' not supported yet."
|
| 388 |
+
)
|
| 389 |
|
| 390 |
st.stop()
|
| 391 |
|