DawnC commited on
Commit
1b5460a
โ€ข
1 Parent(s): edded80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -133,10 +133,26 @@ def preprocess_image(image):
133
  return transform(image).unsqueeze(0)
134
 
135
 
136
- def get_akc_breeds_link(breed):
137
- base_url = "https://www.akc.org/dog-breeds/"
138
- breed_url = breed.lower().replace('_', '-')
139
- return f"{base_url}{breed_url}/"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
 
142
  async def predict_single_dog(image):
@@ -424,7 +440,6 @@ async def predict(image):
424
  <span class="value">{description['Lifespan']}</span>
425
  </div>
426
  </div>
427
-
428
  <h2 class="section-title">
429
  <span class="icon">๐Ÿ•</span> TEMPERAMENT & PERSONALITY
430
  </h2>
@@ -440,7 +455,6 @@ async def predict(image):
440
  </span>
441
  </span>
442
  </div>
443
-
444
  <h2 class="section-title">
445
  <span class="icon">๐Ÿ’ช</span> CARE REQUIREMENTS
446
  </h2>
@@ -491,7 +505,6 @@ async def predict(image):
491
  <span class="value">{description['Care Level']}</span>
492
  </div>
493
  </div>
494
-
495
  <h2 class="section-title">
496
  <span class="icon">๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ</span> FAMILY COMPATIBILITY
497
  </h2>
@@ -511,14 +524,12 @@ async def predict(image):
511
  <span class="value">{description['Good with Children']}</span>
512
  </div>
513
  </div>
514
-
515
  <h2 class="section-title">
516
  <span class="icon">๐Ÿ“</span> DESCRIPTION
517
  </h2>
518
  <div class="description-section">
519
  <p>{description.get('Description', '')}</p>
520
  </div>
521
-
522
  <div class="action-section">
523
  <a href="{get_akc_breeds_link(breed)}" target="_blank" class="akc-button">
524
  <span class="icon">๐ŸŒ</span>
@@ -583,6 +594,7 @@ async def predict(image):
583
  return error_msg, None, None
584
 
585
 
 
586
  def show_details_html(choice, previous_output, initial_state):
587
  if not choice:
588
  return previous_output, gr.update(visible=True), initial_state
@@ -804,7 +816,7 @@ def main():
804
 
805
  # Footer
806
  gr.HTML('''
807
- For more details on this project and other work, feel free to visit my GitHub
808
  <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">
809
  Dog Breed Classifier
810
  </a>
@@ -814,4 +826,4 @@ def main():
814
 
815
  if __name__ == "__main__":
816
  iface = main()
817
- iface.launch(share=True)
 
133
  return transform(image).unsqueeze(0)
134
 
135
 
136
+ def get_akc_breeds_link(breed: str) -> str:
137
+ """Generate AKC breed page URL with intelligent name handling"""
138
+ # ๅŸบๆœฌ็š„ๅญ—็ฌฆไธฒ่™•็†
139
+ breed_name = breed.lower()
140
+
141
+ # ่™•็†ๅธธ่ฆ‹็š„ๅ็จฑๆ ผๅผ
142
+ breed_name = breed_name.replace('_', '-')
143
+ breed_name = breed_name.replace("'", '')
144
+ breed_name = breed_name.replace(" ", '-')
145
+
146
+ # ่™•็†็‰นๆฎŠๆƒ…ๆณ
147
+ special_cases = {
148
+ 'mexican-hairless': 'xoloitzcuintli',
149
+ 'brabancon-griffon': 'brussels-griffon',
150
+ 'bull-mastiff': 'bullmastiff',
151
+ 'walker-hound': 'treeing-walker-coonhound'
152
+ }
153
+
154
+ breed_name = special_cases.get(breed_name, breed_name)
155
+ return f"https://www.akc.org/dog-breeds/{breed_name}/"
156
 
157
 
158
  async def predict_single_dog(image):
 
440
  <span class="value">{description['Lifespan']}</span>
441
  </div>
442
  </div>
 
443
  <h2 class="section-title">
444
  <span class="icon">๐Ÿ•</span> TEMPERAMENT & PERSONALITY
445
  </h2>
 
455
  </span>
456
  </span>
457
  </div>
 
458
  <h2 class="section-title">
459
  <span class="icon">๐Ÿ’ช</span> CARE REQUIREMENTS
460
  </h2>
 
505
  <span class="value">{description['Care Level']}</span>
506
  </div>
507
  </div>
 
508
  <h2 class="section-title">
509
  <span class="icon">๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ</span> FAMILY COMPATIBILITY
510
  </h2>
 
524
  <span class="value">{description['Good with Children']}</span>
525
  </div>
526
  </div>
 
527
  <h2 class="section-title">
528
  <span class="icon">๐Ÿ“</span> DESCRIPTION
529
  </h2>
530
  <div class="description-section">
531
  <p>{description.get('Description', '')}</p>
532
  </div>
 
533
  <div class="action-section">
534
  <a href="{get_akc_breeds_link(breed)}" target="_blank" class="akc-button">
535
  <span class="icon">๐ŸŒ</span>
 
594
  return error_msg, None, None
595
 
596
 
597
+
598
  def show_details_html(choice, previous_output, initial_state):
599
  if not choice:
600
  return previous_output, gr.update(visible=True), initial_state
 
816
 
817
  # Footer
818
  gr.HTML('''
819
+ For more details on this project and other work, feel free to visit my GitHub
820
  <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">
821
  Dog Breed Classifier
822
  </a>
 
826
 
827
  if __name__ == "__main__":
828
  iface = main()
829
+ iface.launch(share=True, debug=True)