Jacksonnavigator7 commited on
Commit
e451eac
·
verified ·
1 Parent(s): 11d7ab7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -74,7 +74,6 @@ def get_bird_habitat_map(bird_name, check_tanzania=True):
74
  Is the {clean_name} bird native to or commonly found in Tanzania?
75
  Answer with ONLY "yes" or "no".
76
  """
77
-
78
  try:
79
  tanzania_check = client.chat.completions.create(
80
  messages=[{"role": "user", "content": tanzania_check_prompt}],
@@ -119,7 +118,7 @@ def get_bird_habitat_map(bird_name, check_tanzania=True):
119
  "description": "Could not retrieve specific habitat information for this bird."}
120
  ]
121
  return locations, is_in_tanzania
122
- except:
123
  return [{"name": "Error retrieving data", "lat": 0, "lon": 0,
124
  "description": "Please try again or check your connection."}], False
125
 
@@ -157,7 +156,6 @@ def create_habitat_map(habitat_locations):
157
  def format_bird_info(raw_info, language="en"):
158
  """Improve the formatting of bird information"""
159
  formatted = raw_info
160
-
161
  warning_text = "NOT TYPICALLY FOUND IN TANZANIA"
162
  warning_translation = "HAPATIKANI SANA TANZANIA" if language == "sw" else warning_text
163
 
@@ -171,7 +169,6 @@ def format_bird_info(raw_info, language="en"):
171
 
172
  formatted = formatted.replace('<p><p>', '<p>')
173
  formatted = formatted.replace('</p></p>', '</p>')
174
-
175
  return formatted
176
 
177
  def get_bird_info(bird_name, language="en"):
@@ -220,6 +217,7 @@ def predict_and_get_info(img, language="en"):
220
  top_bird = str(pred)
221
  clean_top_bird = clean_bird_name(top_bird)
222
 
 
223
  if top_bird.lower() == "other" and float(probs[pred_idx]) > 0.8:
224
  message = (
225
  "This image does not appear to match any bird species in our trained dataset. "
@@ -420,7 +418,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
420
  {answer}
421
  ---
422
  """
423
- return new_exchange + history
 
424
 
425
  def clear_conversation_history():
426
  return ""
@@ -483,4 +482,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
483
  outputs=[conversation_history]
484
  )
485
 
 
486
  app.launch(share=True)
 
74
  Is the {clean_name} bird native to or commonly found in Tanzania?
75
  Answer with ONLY "yes" or "no".
76
  """
 
77
  try:
78
  tanzania_check = client.chat.completions.create(
79
  messages=[{"role": "user", "content": tanzania_check_prompt}],
 
118
  "description": "Could not retrieve specific habitat information for this bird."}
119
  ]
120
  return locations, is_in_tanzania
121
+ except Exception as e:
122
  return [{"name": "Error retrieving data", "lat": 0, "lon": 0,
123
  "description": "Please try again or check your connection."}], False
124
 
 
156
  def format_bird_info(raw_info, language="en"):
157
  """Improve the formatting of bird information"""
158
  formatted = raw_info
 
159
  warning_text = "NOT TYPICALLY FOUND IN TANZANIA"
160
  warning_translation = "HAPATIKANI SANA TANZANIA" if language == "sw" else warning_text
161
 
 
169
 
170
  formatted = formatted.replace('<p><p>', '<p>')
171
  formatted = formatted.replace('</p></p>', '</p>')
 
172
  return formatted
173
 
174
  def get_bird_info(bird_name, language="en"):
 
217
  top_bird = str(pred)
218
  clean_top_bird = clean_bird_name(top_bird)
219
 
220
+ # Check if top prediction is "Other" with high confidence (>80%)
221
  if top_bird.lower() == "other" and float(probs[pred_idx]) > 0.8:
222
  message = (
223
  "This image does not appear to match any bird species in our trained dataset. "
 
418
  {answer}
419
  ---
420
  """
421
+ updated_history = new_exchange + history
422
+ return updated_history
423
 
424
  def clear_conversation_history():
425
  return ""
 
482
  outputs=[conversation_history]
483
  )
484
 
485
+ # Launch the app
486
  app.launch(share=True)