DawnC commited on
Commit
3e11a8c
·
1 Parent(s): 220a9cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -194,16 +194,28 @@ def predict(image):
194
  # 檢查最高的預測機率
195
  top1_prob = topk_probs[0][0].item()
196
 
197
- if top1_prob >= 0.5:
198
  # 正確辨識時,返回該品種資訊
199
  predicted = topk_indices[0][0]
200
  breed = dog_breeds[predicted.item()]
201
  description = get_dog_description(breed)
202
  akc_link = get_akc_breeds_link()
203
 
204
- description_str = f"**Breed**: {breed}\n\n**Description**: {description}"
 
 
 
 
 
205
  description_str += f"\n\n**Want to learn more about dog breeds?** [Visit the AKC dog breeds page]({akc_link}) and search for {breed} to find detailed information."
206
 
 
 
 
 
 
 
 
207
  return description_str
208
 
209
  else:
@@ -226,7 +238,6 @@ def predict(image):
226
  except Exception as e:
227
  return f"An error occurred: {e}"
228
 
229
-
230
  iface = gr.Interface(
231
  fn=predict,
232
  inputs=gr.Image(label="Upload a dog image", type="numpy"),
 
194
  # 檢查最高的預測機率
195
  top1_prob = topk_probs[0][0].item()
196
 
197
+ if top1_prob >= 0.6:
198
  # 正確辨識時,返回該品種資訊
199
  predicted = topk_indices[0][0]
200
  breed = dog_breeds[predicted.item()]
201
  description = get_dog_description(breed)
202
  akc_link = get_akc_breeds_link()
203
 
204
+ if isinstance(description, dict):
205
+ description_str = "\n\n".join([f"**{key}**: {value}" for key, value in description.items()])
206
+ else:
207
+ description_str = description
208
+
209
+ # 添加AKC連結
210
  description_str += f"\n\n**Want to learn more about dog breeds?** [Visit the AKC dog breeds page]({akc_link}) and search for {breed} to find detailed information."
211
 
212
+ # 添加免責聲明
213
+ disclaimer = ("\n\n*Disclaimer: The external link provided leads to the American Kennel Club (AKC) dog breeds page. "
214
+ "You may need to search for the specific breed on that page. "
215
+ "I am not responsible for the content on external sites. "
216
+ "Please refer to the AKC's terms of use and privacy policy.*")
217
+ description_str += disclaimer
218
+
219
  return description_str
220
 
221
  else:
 
238
  except Exception as e:
239
  return f"An error occurred: {e}"
240
 
 
241
  iface = gr.Interface(
242
  fn=predict,
243
  inputs=gr.Image(label="Upload a dog image", type="numpy"),