DawnC commited on
Commit
dfb8cdd
ยท
1 Parent(s): 4ef836e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -391,33 +391,32 @@ async def predict(image):
391
  prob = float(prob.replace('%', ''))
392
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
393
 
394
- # ็”Ÿๆˆ่ˆ‡ๆฏๅ€‹ๅ“็จฎๅฐๆ‡‰็š„ๆŒ‰้ˆ•๏ผŒ็ทŠ้šจๅ…ถๅพŒ
395
  button_id = f"Dog {i+1}: More about {breed}"
396
- buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button> '
397
- buttons.append(button_id)
398
-
399
  dogs_info += "</ul>"
400
 
401
- # ๅฐ‡ๆฏๅ€‹ๆŒ‰้ˆ•ๅตŒๅ…ฅๅˆฐๆฏๅ€‹ๅ“็จฎๆ่ฟฐไธ‹ๆ–น
402
- dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
403
 
404
  else:
405
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
406
 
407
  dogs_info += '</div>' # ็ตๆŸ็•ถๅ‰็‹—็š„่ณ‡่จŠๅ€ๅกŠ
408
-
409
-
410
- # ็ขบไฟ `html_output` ๆœ‰่ณฆๅ€ผ
411
  html_output = f"""
412
- <style>
413
- .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); }}
414
- .dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
415
- .breed-buttons {{ margin-top: 10px; }}
416
- .breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
417
- </style>
418
- {dogs_info}
419
  """
420
 
 
421
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
422
 
423
  except Exception as e:
 
391
  prob = float(prob.replace('%', ''))
392
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
393
 
394
+ # ็”Ÿๆˆ่ˆ‡ๆฏๅ€‹ๅ“็จฎๅฐๆ‡‰็š„ๆŒ‰้ˆ•๏ผŒ้€™ๆฌกไธไฝฟ็”จ Gradio ็š„ๆŒ‰้ˆ•็”Ÿๆˆๆ–นๅผ๏ผŒ่€Œๆ˜ฏ็›ดๆŽฅ็”จ HTML ไพ†ๅตŒๅ…ฅๆŒ‰้ˆ•
395
  button_id = f"Dog {i+1}: More about {breed}"
396
+ buttons_html += f'<button style="display:inline-block; margin-right:10px;" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
397
+
 
398
  dogs_info += "</ul>"
399
 
400
+ # ๅฐ‡ๆŒ‰้ˆ•็›ดๆŽฅๅตŒๅ…ฅๆ่ฟฐๅ…ง
401
+ dogs_info += buttons_html
402
 
403
  else:
404
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
405
 
406
  dogs_info += '</div>' # ็ตๆŸ็•ถๅ‰็‹—็š„่ณ‡่จŠๅ€ๅกŠ
407
+
408
+ # ๆœ€ๅพŒ็”ŸๆˆๅฎŒๆ•ด็š„ HTML ่ผธๅ‡บ
 
409
  html_output = f"""
410
+ <style>
411
+ .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); }}
412
+ .dog-info h2 {{ background-color: #f0f0f0; padding: 10px; margin: -15px -15px 15px -15px; border-radius: 5px 5px 0 0; }}
413
+ .breed-buttons {{ margin-top: 10px; }}
414
+ .breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
415
+ </style>
416
+ {dogs_info}
417
  """
418
 
419
+
420
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
421
 
422
  except Exception as e: