DawnC commited on
Commit
21b74d9
1 Parent(s): 150a33b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -49
app.py CHANGED
@@ -10,54 +10,81 @@ from PIL import Image
10
  from data_manager import get_dog_description
11
  from urllib.parse import quote
12
 
13
- dog_breeds = ["Afghan_Hound(阿富汗獵犬)", "African_Hunting_Dog(非洲野犬)", "Airedale(艾爾谷犬)",
14
- "American_Staffordshire_Terrier(美國斯塔福郡梗)", "Appenzeller(亞賓澤爾犬)",
15
- "Australian_Terrier(澳大利亞梗)", "Bedlington_Terrier(貝德靈頓梗)",
16
- "Bernese_Mountain_Dog(伯恩山犬)", "Blenheim_Spaniel(布萊尼姆獵犬)",
17
- "Border_Collie(邊境牧羊犬)", "Border_Terrier(邊境梗)", "Boston_Bull(波士頓梗)",
18
- "Bouvier_Des_Flandres(法蘭德斯牧羊犬)", "Brabancon_Griffon(布魯塞爾格里芬犬)",
19
- "Brittany_Spaniel(布列塔尼獵犬)", "Cardigan(卡迪根威爾士柯基犬)",
20
- "Chesapeake_Bay_Retriever(切薩皮克灣獵犬)", "Chihuahua(吉娃娃)",
21
- "Dandie_Dinmont(丹第丁蒙梗)", "Doberman(杜賓犬)", "English_Foxhound(英國獵狐犬)",
22
- "English_Setter(英國雪達犬)", "English_Springer(英國跳獵犬)",
23
- "EntleBucher(恩特雷布赫山地犬)", "Eskimo_Dog(愛斯基摩犬)", "French_Bulldog(法國鬥牛犬)",
24
- "German_Shepherd(德國牧羊犬)", "German_Short-Haired_Pointer(德國短毛指示犬)",
25
- "Gordon_Setter(戈登雪達犬)", "Great_Dane(大丹犬)", "Great_Pyrenees(大白熊犬)",
26
- "Greater_Swiss_Mountain_Dog(大瑞士山地犬)", "Ibizan_Hound(依比沙獵犬)",
27
- "Irish_Setter(愛爾蘭雪達犬)", "Irish_Terrier(愛爾蘭梗)",
28
- "Irish_Water_Spaniel(愛爾蘭水獵犬)", "Irish_Wolfhound(愛爾蘭獵狼犬)",
29
- "Italian_Greyhound(義大利灰狗)", "Japanese_Spaniel(日本狆)",
30
- "Kerry_Blue_Terrier(凱利藍梗)", "Labrador_Retriever(拉布拉多尋回犬)",
31
- "Lakeland_Terrier(湖畔梗)", "Leonberg(獅毛狗)", "Lhasa(拉薩犬)",
32
- "Maltese_Dog(馬爾濟斯犬)", "Mexican_Hairless(墨西哥無毛犬)", "Newfoundland(紐芬蘭犬)",
33
- "Norfolk_Terrier(諾福克梗)", "Norwegian_Elkhound(挪威獵麋犬)",
34
- "Norwich_Terrier(諾利治梗)", "Old_English_Sheepdog(古代英國牧羊犬)",
35
- "Pekinese(北京犬)", "Pembroke(威爾士柯基犬)", "Pomeranian(博美犬)",
36
- "Rhodesian_Ridgeback(羅得西亞脊背犬)", "Rottweiler(羅威納犬)",
37
- "Saint_Bernard(聖伯納犬)", "Saluki(薩路基獵犬)", "Samoyed(薩摩耶犬)",
38
- "Scotch_Terrier(蘇格蘭梗)", "Scottish_Deerhound(蘇格蘭獵鹿犬)",
39
- "Sealyham_Terrier(錫利哈姆梗)", "Shetland_Sheepdog(設得蘭牧羊犬)",
40
- "Shih-Tzu(西施犬)", "Siberian_Husky(西伯利亞哈士奇)",
41
- "Staffordshire_Bullterrier(斯塔福郡鬥牛梗)", "Sussex_Spaniel(蘇塞克斯獵犬)",
42
- "Tibetan_Mastiff(藏獒)", "Tibetan_Terrier(西藏梗)", "Walker_Hound(沃克獵犬)",
43
- "Weimaraner(威瑪犬)", "Welsh_Springer_Spaniel(威爾士跳獵犬)",
44
- "West_Highland_White_Terrier(西高地白梗)", "Yorkshire_Terrier(約克夏梗)",
45
- "Affenpinscher(猴犬)", "Basenji(巴辛吉犬)", "Basset(巴吉度獵犬)", "Beagle(比格犬)",
46
- "Black-and-Tan_Coonhound(黑褐獵浣熊犬)", "Bloodhound(尋血獵犬)",
47
- "Bluetick(布魯提克獵犬)", "Borzoi(俄羅斯獵狼犬)", "Boxer(拳師犬)", "Briard(布里亞犬)",
48
- "Bull_Mastiff(獒犬)", "Cairn(凱恩梗)", "Chow(鬆獅犬)", "Clumber(克倫伯獵犬)",
49
- "Cocker_Spaniel(可卡獵犬)", "Collie(柯利牧羊犬)", "Curly-Coated_Retriever(捲毛尋回犬)",
50
- "Dhole(豺)", "Dingo(澳洲野犬)", "Flat-Coated_Retriever(平毛尋回犬)",
51
- "Giant_Schnauzer(大型雪納瑞犬)", "Golden_Retriever(黃金獵犬)",
52
- "Groenendael(比利時牧羊犬)", "Keeshond(荷蘭毛獅犬)", "Kelpie(澳洲卡爾比犬)",
53
- "Komondor(匈牙利牧羊犬)", "Kuvasz(庫瓦茲犬)", "Malamute(阿拉斯加雪橇犬)",
54
- "Malinois(比利時瑪利諾犬)", "Miniature_Pinscher(迷你杜賓犬)",
55
- "Miniature_Poodle(迷你貴賓犬)", "Miniature_Schnauzer(迷你雪納瑞犬)",
56
- "Otterhound(水獺獵犬)", "Papillon(蝴蝶犬)", "Pug(巴哥犬)", "Redbone(紅骨獵浣熊犬)",
57
- "Schipperke(舒柏奇犬)", "Silky_Terrier(絲毛梗)",
58
- "Soft-Coated_Wheaten_Terrier(愛爾蘭軟毛梗)", "Standard_Poodle(標準貴賓犬)",
59
- "Standard_Schnauzer(標準雪納瑞犬)", "Toy_Poodle(玩具貴賓犬)", "Toy_Terrier(玩具梗)",
60
- "Vizsla(維茲拉犬)", "Whippet(惠比特犬)", "Wire-Haired_Fox_Terrier(硬毛獵狐梗)"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  class MultiHeadAttention(nn.Module):
63
 
@@ -165,7 +192,7 @@ def predict(image):
165
  description = get_dog_description(breed)
166
  return format_description(description, breed), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
167
 
168
- elif top1_prob < 0.2:
169
  return ("The image is too unclear or the dog breed is not in the dataset. Please upload a clearer image of the dog.",
170
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False))
171
  else:
 
10
  from data_manager import get_dog_description
11
  from urllib.parse import quote
12
 
13
+ # dog_breeds = ["Afghan_Hound(阿富汗獵犬)", "African_Hunting_Dog(非洲野犬)", "Airedale(艾爾谷犬)",
14
+ # "American_Staffordshire_Terrier(美國斯塔福郡梗)", "Appenzeller(亞賓澤爾犬)",
15
+ # "Australian_Terrier(澳大利亞梗)", "Bedlington_Terrier(貝德靈頓梗)",
16
+ # "Bernese_Mountain_Dog(伯恩山犬)", "Blenheim_Spaniel(布萊尼姆獵犬)",
17
+ # "Border_Collie(邊境牧羊犬)", "Border_Terrier(邊境梗)", "Boston_Bull(波士頓梗)",
18
+ # "Bouvier_Des_Flandres(法蘭德斯牧羊犬)", "Brabancon_Griffon(布魯塞爾格里芬犬)",
19
+ # "Brittany_Spaniel(布列塔尼獵犬)", "Cardigan(卡迪根威爾士柯基犬)",
20
+ # "Chesapeake_Bay_Retriever(切薩皮克灣獵犬)", "Chihuahua(吉娃娃)",
21
+ # "Dandie_Dinmont(丹第丁蒙梗)", "Doberman(杜賓犬)", "English_Foxhound(英國獵狐犬)",
22
+ # "English_Setter(英國雪達犬)", "English_Springer(英國跳獵犬)",
23
+ # "EntleBucher(恩特雷布赫山地犬)", "Eskimo_Dog(愛斯基摩犬)", "French_Bulldog(法國鬥牛犬)",
24
+ # "German_Shepherd(德國牧羊犬)", "German_Short-Haired_Pointer(德國短毛指示犬)",
25
+ # "Gordon_Setter(戈登雪達犬)", "Great_Dane(大丹犬)", "Great_Pyrenees(大白熊犬)",
26
+ # "Greater_Swiss_Mountain_Dog(大瑞士山地犬)", "Ibizan_Hound(依比沙獵犬)",
27
+ # "Irish_Setter(愛爾蘭雪達犬)", "Irish_Terrier(愛爾蘭梗)",
28
+ # "Irish_Water_Spaniel(愛爾蘭水獵犬)", "Irish_Wolfhound(愛爾蘭獵狼犬)",
29
+ # "Italian_Greyhound(義大利灰狗)", "Japanese_Spaniel(日本狆)",
30
+ # "Kerry_Blue_Terrier(凱利藍梗)", "Labrador_Retriever(拉布拉多尋回犬)",
31
+ # "Lakeland_Terrier(湖畔梗)", "Leonberg(獅毛狗)", "Lhasa(拉薩犬)",
32
+ # "Maltese_Dog(馬爾濟斯犬)", "Mexican_Hairless(墨西哥無毛犬)", "Newfoundland(紐芬蘭犬)",
33
+ # "Norfolk_Terrier(諾福克梗)", "Norwegian_Elkhound(挪威獵麋犬)",
34
+ # "Norwich_Terrier(諾利治梗)", "Old_English_Sheepdog(古代英國牧羊犬)",
35
+ # "Pekinese(北京犬)", "Pembroke(威爾士柯基犬)", "Pomeranian(博美犬)",
36
+ # "Rhodesian_Ridgeback(羅得西亞脊背犬)", "Rottweiler(羅威納犬)",
37
+ # "Saint_Bernard(聖伯納犬)", "Saluki(薩路基獵犬)", "Samoyed(薩摩耶犬)",
38
+ # "Scotch_Terrier(蘇格蘭梗)", "Scottish_Deerhound(蘇格蘭獵鹿犬)",
39
+ # "Sealyham_Terrier(錫利哈姆梗)", "Shetland_Sheepdog(設得蘭牧羊犬)",
40
+ # "Shih-Tzu(西施犬)", "Siberian_Husky(西伯利亞哈士奇)",
41
+ # "Staffordshire_Bullterrier(斯塔福郡鬥牛梗)", "Sussex_Spaniel(蘇塞克斯獵犬)",
42
+ # "Tibetan_Mastiff(藏獒)", "Tibetan_Terrier(西藏梗)", "Walker_Hound(沃克獵犬)",
43
+ # "Weimaraner(威瑪犬)", "Welsh_Springer_Spaniel(威爾士跳獵犬)",
44
+ # "West_Highland_White_Terrier(西高地白梗)", "Yorkshire_Terrier(約克夏梗)",
45
+ # "Affenpinscher(猴犬)", "Basenji(巴辛吉犬)", "Basset(巴吉度獵犬)", "Beagle(比格犬)",
46
+ # "Black-and-Tan_Coonhound(黑褐獵浣熊犬)", "Bloodhound(尋血獵犬)",
47
+ # "Bluetick(布魯提克獵犬)", "Borzoi(俄羅斯獵狼犬)", "Boxer(拳師犬)", "Briard(布里亞犬)",
48
+ # "Bull_Mastiff(獒犬)", "Cairn(凱恩梗)", "Chow(鬆獅犬)", "Clumber(克倫伯獵犬)",
49
+ # "Cocker_Spaniel(可卡獵犬)", "Collie(柯利牧羊犬)", "Curly-Coated_Retriever(捲毛尋回犬)",
50
+ # "Dhole(豺)", "Dingo(澳洲野犬)", "Flat-Coated_Retriever(平毛尋回犬)",
51
+ # "Giant_Schnauzer(大型雪納瑞犬)", "Golden_Retriever(黃金獵犬)",
52
+ # "Groenendael(比利時牧羊犬)", "Keeshond(荷蘭毛獅犬)", "Kelpie(澳洲卡爾比犬)",
53
+ # "Komondor(匈牙利牧羊犬)", "Kuvasz(庫瓦茲犬)", "Malamute(阿拉斯加雪橇犬)",
54
+ # "Malinois(比利時瑪利諾犬)", "Miniature_Pinscher(迷你杜賓犬)",
55
+ # "Miniature_Poodle(迷你貴賓犬)", "Miniature_Schnauzer(迷你雪納瑞犬)",
56
+ # "Otterhound(水獺獵犬)", "Papillon(蝴蝶犬)", "Pug(巴哥犬)", "Redbone(紅骨獵浣熊犬)",
57
+ # "Schipperke(舒柏奇犬)", "Silky_Terrier(絲毛梗)",
58
+ # "Soft-Coated_Wheaten_Terrier(愛爾蘭軟毛梗)", "Standard_Poodle(標準貴賓犬)",
59
+ # "Standard_Schnauzer(標準雪納瑞犬)", "Toy_Poodle(玩具貴賓犬)", "Toy_Terrier(玩具梗)",
60
+ # "Vizsla(維茲拉犬)", "Whippet(惠比特犬)", "Wire-Haired_Fox_Terrier(硬毛獵狐梗)"]
61
+
62
+ dog_breeds = ["Afghan_Hound", "African_Hunting_Dog", "Airedale", "American_Staffordshire_Terrier",
63
+ "Appenzeller", "Australian_Terrier", "Bedlington_Terrier", "Bernese_Mountain_Dog",
64
+ "Blenheim_Spaniel", "Border_Collie", "Border_Terrier", "Boston_Bull", "Bouvier_Des_Flandres",
65
+ "Brabancon_Griffon", "Brittany_Spaniel", "Cardigan", "Chesapeake_Bay_Retriever",
66
+ "Chihuahua", "Dandie_Dinmont", "Doberman", "English_Foxhound", "English_Setter",
67
+ "English_Springer", "EntleBucher", "Eskimo_Dog", "French_Bulldog", "German_Shepherd",
68
+ "German_Short-Haired_Pointer", "Gordon_Setter", "Great_Dane", "Great_Pyrenees",
69
+ "Greater_Swiss_Mountain_Dog", "Ibizan_Hound", "Irish_Setter", "Irish_Terrier",
70
+ "Irish_Water_Spaniel", "Irish_Wolfhound", "Italian_Greyhound", "Japanese_Spaniel",
71
+ "Kerry_Blue_Terrier", "Labrador_Retriever", "Lakeland_Terrier", "Leonberg", "Lhasa",
72
+ "Maltese_Dog", "Mexican_Hairless", "Newfoundland", "Norfolk_Terrier", "Norwegian_Elkhound",
73
+ "Norwich_Terrier", "Old_English_Sheepdog", "Pekinese", "Pembroke", "Pomeranian",
74
+ "Rhodesian_Ridgeback", "Rottweiler", "Saint_Bernard", "Saluki", "Samoyed",
75
+ "Scotch_Terrier", "Scottish_Deerhound", "Sealyham_Terrier", "Shetland_Sheepdog",
76
+ "Shih-Tzu", "Siberian_Husky", "Staffordshire_Bullterrier", "Sussex_Spaniel",
77
+ "Tibetan_Mastiff", "Tibetan_Terrier", "Walker_Hound", "Weimaraner",
78
+ "Welsh_Springer_Spaniel", "West_Highland_White_Terrier", "Yorkshire_Terrier",
79
+ "Affenpinscher", "Basenji", "Basset", "Beagle", "Black-and-Tan_Coonhound", "Bloodhound",
80
+ "Bluetick", "Borzoi", "Boxer", "Briard", "Bull_Mastiff", "Cairn", "Chow", "Clumber",
81
+ "Cocker_Spaniel", "Collie", "Curly-Coated_Retriever", "Dhole", "Dingo",
82
+ "Flat-Coated_Retriever", "Giant_Schnauzer", "Golden_Retriever", "Groenendael", "Keeshond",
83
+ "Kelpie", "Komondor", "Kuvasz", "Malamute", "Malinois", "Miniature_Pinscher",
84
+ "Miniature_Poodle", "Miniature_Schnauzer", "Otterhound", "Papillon", "Pug", "Redbone",
85
+ "Schipperke", "Silky_Terrier", "Soft-Coated_Wheaten_Terrier", "Standard_Poodle",
86
+ "Standard_Schnauzer", "Toy_Poodle", "Toy_Terrier", "Vizsla", "Whippet",
87
+ "Wire-Haired_Fox_Terrier"]
88
 
89
  class MultiHeadAttention(nn.Module):
90
 
 
192
  description = get_dog_description(breed)
193
  return format_description(description, breed), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
194
 
195
+ elif top1_prob < 0.1:
196
  return ("The image is too unclear or the dog breed is not in the dataset. Please upload a clearer image of the dog.",
197
  gr.update(visible=False), gr.update(visible=False), gr.update(visible=False))
198
  else: