mjwong commited on
Commit
77c5f52
·
verified ·
1 Parent(s): 9bafc50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -141,8 +141,14 @@ def app_function(uploaded_image: Optional[np.ndarray], country: Optional[str]) -
141
  summary = "Found top 5 similar wildlife images."
142
 
143
  logger.info("app_function: Performing taxonomic lookup for '%s'", proposed_scientific)
144
- response = requests.get(f"{SPECIES_RANK_API_URL}{proposed_scientific}")
145
- taxonomic_data = response.json()
 
 
 
 
 
 
146
  proposed_kingdom = taxonomic_data.get("kingdom", "N/A")
147
  proposed_phylum = taxonomic_data.get("phylum", "N/A")
148
  proposed_class = taxonomic_data.get("class", "N/A")
 
141
  summary = "Found top 5 similar wildlife images."
142
 
143
  logger.info("app_function: Performing taxonomic lookup for '%s'", proposed_scientific)
144
+ try:
145
+ response = requests.get(f"{SPECIES_RANK_API_URL}{proposed_scientific}", timeout=10)
146
+ response.raise_for_status()
147
+ taxonomic_data = response.json()
148
+ except requests.exceptions.RequestException as e:
149
+ logger.error("app_function: Taxonomic lookup failed for '%s'. Exception: %s", proposed_scientific, e)
150
+ taxonomic_data = {}
151
+
152
  proposed_kingdom = taxonomic_data.get("kingdom", "N/A")
153
  proposed_phylum = taxonomic_data.get("phylum", "N/A")
154
  proposed_class = taxonomic_data.get("class", "N/A")