DawnC commited on
Commit
3d8bdba
ยท
1 Parent(s): b76b4a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -18
app.py CHANGED
@@ -366,8 +366,6 @@ async def predict(image):
366
  dogs_info = ""
367
 
368
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
369
- # ๅฐ‡ buttons_html ่ˆ‡ๆฏๅ€‹ๅ“็จฎ็š„ๅ€ๅกŠ็ถๅฎš
370
- buttons_html = ""
371
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
372
  color = color_list[i % len(color_list)]
373
  draw.rectangle(box, outline=color, width=3)
@@ -389,24 +387,18 @@ async def predict(image):
389
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
390
  dogs_info += "</ul>"
391
 
392
- buttons_html += '<div class="breed-buttons">' # ๆ–ฐ็š„ๆŒ‰้ˆ•ๅ€ๅกŠ
393
  for breed in topk_breeds[:3]:
394
  button_id = f"Dog {i+1}: More about {breed}"
395
- buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
396
  buttons.append(button_id)
397
- buttons_html += '</div>' # ็ตๆŸๆŒ‰้ˆ•ๅ€ๅกŠ
398
-
399
- # ๅฐ‡ๆŒ‰้ˆ•็›ดๆŽฅๆ’ๅ…ฅๆฏๅ€‹ๅ€ๅกŠๅ…ง
400
- dogs_info += buttons_html
401
 
402
  else:
403
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
404
-
405
- dogs_info += '</div>' # ็ตๆŸ็‹—ๅ€ๅกŠ
406
-
407
-
408
-
409
-
410
  html_output = f"""
411
  <style>
412
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
@@ -416,7 +408,7 @@ async def predict(image):
416
  </style>
417
  {dogs_info}
418
  """
419
-
420
  if buttons:
421
  html_output += """
422
  <script>
@@ -436,7 +428,7 @@ async def predict(image):
436
  "show_back": True,
437
  "image": annotated_image,
438
  "is_multi_dog": len(dogs) > 1,
439
- "html_output": html_output
440
  }
441
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
442
  else:
@@ -446,7 +438,7 @@ async def predict(image):
446
  "show_back": False,
447
  "image": annotated_image,
448
  "is_multi_dog": len(dogs) > 1,
449
- "html_output": html_output
450
  }
451
  return html_output, annotated_image, gr.update(visible=False, choices=[]), initial_state
452
 
@@ -455,7 +447,6 @@ async def predict(image):
455
  print(error_msg)
456
  return error_msg, None, gr.update(visible=False, choices=[]), None
457
 
458
-
459
 
460
 
461
  def show_details_html(choice, previous_output, initial_state):
 
366
  dogs_info = ""
367
 
368
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
 
 
369
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
370
  color = color_list[i % len(color_list)]
371
  draw.rectangle(box, outline=color, width=3)
 
387
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
388
  dogs_info += "</ul>"
389
 
390
+ dogs_info += '<div class="breed-buttons">'
391
  for breed in topk_breeds[:3]:
392
  button_id = f"Dog {i+1}: More about {breed}"
393
+ dogs_info += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
394
  buttons.append(button_id)
395
+ dogs_info += '</div>'
 
 
 
396
 
397
  else:
398
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
399
+
400
+ dogs_info += '</div>'
401
+
 
 
 
402
  html_output = f"""
403
  <style>
404
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
 
408
  </style>
409
  {dogs_info}
410
  """
411
+
412
  if buttons:
413
  html_output += """
414
  <script>
 
428
  "show_back": True,
429
  "image": annotated_image,
430
  "is_multi_dog": len(dogs) > 1,
431
+ "html_output": html_output
432
  }
433
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
434
  else:
 
438
  "show_back": False,
439
  "image": annotated_image,
440
  "is_multi_dog": len(dogs) > 1,
441
+ "html_output": html_output
442
  }
443
  return html_output, annotated_image, gr.update(visible=False, choices=[]), initial_state
444
 
 
447
  print(error_msg)
448
  return error_msg, None, gr.update(visible=False, choices=[]), None
449
 
 
450
 
451
 
452
  def show_details_html(choice, previous_output, initial_state):