Spaces:
Running
on
Zero
Running
on
Zero
Upload 9 files
Browse files- animal_detector.db +0 -0
- app.py +481 -0
- breed_comparison.py +127 -0
- breed_recommendation.py +136 -0
- dog_database.py +218 -0
- html_templates.py +600 -0
- recommendation_html_format.py +482 -0
- scoring_calculation_system.py +293 -0
- styles.py +1238 -0
animal_detector.db
ADDED
Binary file (81.9 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,481 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import os
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
import torch.nn as nn
|
6 |
+
import gradio as gr
|
7 |
+
from torchvision.models import efficientnet_v2_m, EfficientNet_V2_M_Weights
|
8 |
+
from torchvision.ops import nms, box_iou
|
9 |
+
import torch.nn.functional as F
|
10 |
+
from torchvision import transforms
|
11 |
+
from PIL import Image, ImageDraw, ImageFont, ImageFilter
|
12 |
+
from dog_database import get_dop_description
|
13 |
+
from scoring_calculation_system import UserPreferences
|
14 |
+
from recommendation_html_format import format_recommendation_html, get_breed_recommendations
|
15 |
+
from history_manager import UserHistoryManager
|
16 |
+
from search_history import create_history_tab, create_history_component
|
17 |
+
from styles import get_css_styles
|
18 |
+
from breed_detection import create_detection_tab
|
19 |
+
from breed_comparison import create_comparison_tab
|
20 |
+
from breed_recommendation import create_recommendation_tab
|
21 |
+
from html_templates import (
|
22 |
+
format_description_html,
|
23 |
+
format_single_dog_result,
|
24 |
+
format_multiple_breeds_result,
|
25 |
+
format_error_message,
|
26 |
+
format_warning_html,
|
27 |
+
format_multi_dog_container,
|
28 |
+
format_breed_details_html,
|
29 |
+
get_color_scheme,
|
30 |
+
get_akc_breeds_link
|
31 |
+
)
|
32 |
+
from urllib.parse import quote
|
33 |
+
from ultralytics import YOLO
|
34 |
+
import asyncio
|
35 |
+
import traceback
|
36 |
+
|
37 |
+
|
38 |
+
model_yolo = YOLO('yolov8l.pt')
|
39 |
+
|
40 |
+
history_manager = UserHistoryManager()
|
41 |
+
|
42 |
+
dog_breeds = ["Afghan_Hound", "African_Hunting_Dog", "Airedale", "American_Staffordshire_Terrier",
|
43 |
+
"Appenzeller", "Australian_Terrier", "Bedlington_Terrier", "Bernese_Mountain_Dog",
|
44 |
+
"Blenheim_Spaniel", "Border_Collie", "Border_Terrier", "Boston_Bull", "Bouvier_Des_Flandres",
|
45 |
+
"Brabancon_Griffon", "Brittany_Spaniel", "Cardigan", "Chesapeake_Bay_Retriever",
|
46 |
+
"Chihuahua", "Dandie_Dinmont", "Doberman", "English_Foxhound", "English_Setter",
|
47 |
+
"English_Springer", "EntleBucher", "Eskimo_Dog", "French_Bulldog", "German_Shepherd",
|
48 |
+
"German_Short-Haired_Pointer", "Gordon_Setter", "Great_Dane", "Great_Pyrenees",
|
49 |
+
"Greater_Swiss_Mountain_Dog", "Ibizan_Hound", "Irish_Setter", "Irish_Terrier",
|
50 |
+
"Irish_Water_Spaniel", "Irish_Wolfhound", "Italian_Greyhound", "Japanese_Spaniel",
|
51 |
+
"Kerry_Blue_Terrier", "Labrador_Retriever", "Lakeland_Terrier", "Leonberg", "Lhasa",
|
52 |
+
"Maltese_Dog", "Mexican_Hairless", "Newfoundland", "Norfolk_Terrier", "Norwegian_Elkhound",
|
53 |
+
"Norwich_Terrier", "Old_English_Sheepdog", "Pekinese", "Pembroke", "Pomeranian",
|
54 |
+
"Rhodesian_Ridgeback", "Rottweiler", "Saint_Bernard", "Saluki", "Samoyed",
|
55 |
+
"Scotch_Terrier", "Scottish_Deerhound", "Sealyham_Terrier", "Shetland_Sheepdog",
|
56 |
+
"Shih-Tzu", "Siberian_Husky", "Staffordshire_Bullterrier", "Sussex_Spaniel",
|
57 |
+
"Tibetan_Mastiff", "Tibetan_Terrier", "Walker_Hound", "Weimaraner",
|
58 |
+
"Welsh_Springer_Spaniel", "West_Highland_White_Terrier", "Yorkshire_Terrier",
|
59 |
+
"Affenpinscher", "Basenji", "Basset", "Beagle", "Black-and-Tan_Coonhound", "Bloodhound",
|
60 |
+
"Bluetick", "Borzoi", "Boxer", "Briard", "Bull_Mastiff", "Cairn", "Chow", "Clumber",
|
61 |
+
"Cocker_Spaniel", "Collie", "Curly-Coated_Retriever", "Dhole", "Dingo",
|
62 |
+
"Flat-Coated_Retriever", "Giant_Schnauzer", "Golden_Retriever", "Groenendael", "Keeshond",
|
63 |
+
"Kelpie", "Komondor", "Kuvasz", "Malamute", "Malinois", "Miniature_Pinscher",
|
64 |
+
"Miniature_Poodle", "Miniature_Schnauzer", "Otterhound", "Papillon", "Pug", "Redbone",
|
65 |
+
"Schipperke", "Silky_Terrier", "Soft-Coated_Wheaten_Terrier", "Standard_Poodle",
|
66 |
+
"Standard_Schnauzer", "Toy_Poodle", "Toy_Terrier", "Vizsla", "Whippet",
|
67 |
+
"Wire-Haired_Fox_Terrier"]
|
68 |
+
|
69 |
+
class MultiHeadAttention(nn.Module):
|
70 |
+
|
71 |
+
def __init__(self, in_dim, num_heads=8):
|
72 |
+
super().__init__()
|
73 |
+
self.num_heads = num_heads
|
74 |
+
self.head_dim = max(1, in_dim // num_heads)
|
75 |
+
self.scaled_dim = self.head_dim * num_heads
|
76 |
+
self.fc_in = nn.Linear(in_dim, self.scaled_dim)
|
77 |
+
self.query = nn.Linear(self.scaled_dim, self.scaled_dim)
|
78 |
+
self.key = nn.Linear(self.scaled_dim, self.scaled_dim)
|
79 |
+
self.value = nn.Linear(self.scaled_dim, self.scaled_dim)
|
80 |
+
self.fc_out = nn.Linear(self.scaled_dim, in_dim)
|
81 |
+
|
82 |
+
def forward(self, x):
|
83 |
+
N = x.shape[0]
|
84 |
+
x = self.fc_in(x)
|
85 |
+
q = self.query(x).view(N, self.num_heads, self.head_dim)
|
86 |
+
k = self.key(x).view(N, self.num_heads, self.head_dim)
|
87 |
+
v = self.value(x).view(N, self.num_heads, self.head_dim)
|
88 |
+
|
89 |
+
energy = torch.einsum("nqd,nkd->nqk", [q, k])
|
90 |
+
attention = F.softmax(energy / (self.head_dim ** 0.5), dim=2)
|
91 |
+
|
92 |
+
out = torch.einsum("nqk,nvd->nqd", [attention, v])
|
93 |
+
out = out.reshape(N, self.scaled_dim)
|
94 |
+
out = self.fc_out(out)
|
95 |
+
return out
|
96 |
+
|
97 |
+
class BaseModel(nn.Module):
|
98 |
+
def __init__(self, num_classes, device='cuda' if torch.cuda.is_available() else 'cpu'):
|
99 |
+
super().__init__()
|
100 |
+
self.device = device
|
101 |
+
self.backbone = efficientnet_v2_m(weights=EfficientNet_V2_M_Weights.IMAGENET1K_V1)
|
102 |
+
self.feature_dim = self.backbone.classifier[1].in_features
|
103 |
+
self.backbone.classifier = nn.Identity()
|
104 |
+
|
105 |
+
self.num_heads = max(1, min(8, self.feature_dim // 64))
|
106 |
+
self.attention = MultiHeadAttention(self.feature_dim, num_heads=self.num_heads)
|
107 |
+
|
108 |
+
self.classifier = nn.Sequential(
|
109 |
+
nn.LayerNorm(self.feature_dim),
|
110 |
+
nn.Dropout(0.3),
|
111 |
+
nn.Linear(self.feature_dim, num_classes)
|
112 |
+
)
|
113 |
+
|
114 |
+
self.to(device)
|
115 |
+
|
116 |
+
def forward(self, x):
|
117 |
+
x = x.to(self.device)
|
118 |
+
features = self.backbone(x)
|
119 |
+
attended_features = self.attention(features)
|
120 |
+
logits = self.classifier(attended_features)
|
121 |
+
return logits, attended_features
|
122 |
+
|
123 |
+
|
124 |
+
num_classes = 120
|
125 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
126 |
+
model = BaseModel(num_classes=num_classes, device=device)
|
127 |
+
|
128 |
+
checkpoint = torch.load('/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/(120)best_model/best_model_81_dog.pth', map_location=torch.device('cpu'))
|
129 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
130 |
+
|
131 |
+
# evaluation mode
|
132 |
+
model.eval()
|
133 |
+
|
134 |
+
# Image preprocessing function
|
135 |
+
def preprocess_image(image):
|
136 |
+
# If the image is numpy.ndarray turn into PIL.Image
|
137 |
+
if isinstance(image, np.ndarray):
|
138 |
+
image = Image.fromarray(image)
|
139 |
+
|
140 |
+
# Use torchvision.transforms to process images
|
141 |
+
transform = transforms.Compose([
|
142 |
+
transforms.Resize((224, 224)),
|
143 |
+
transforms.ToTensor(),
|
144 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
145 |
+
])
|
146 |
+
|
147 |
+
return transform(image).unsqueeze(0)
|
148 |
+
|
149 |
+
async def predict_single_dog(image):
|
150 |
+
image_tensor = preprocess_image(image)
|
151 |
+
with torch.no_grad():
|
152 |
+
output = model(image_tensor)
|
153 |
+
logits = output[0] if isinstance(output, tuple) else output
|
154 |
+
probabilities = F.softmax(logits, dim=1)
|
155 |
+
topk_probs, topk_indices = torch.topk(probabilities, k=3)
|
156 |
+
top1_prob = topk_probs[0][0].item()
|
157 |
+
topk_breeds = [dog_breeds[idx.item()] for idx in topk_indices[0]]
|
158 |
+
|
159 |
+
# Calculate relative probabilities for display
|
160 |
+
raw_probs = [prob.item() for prob in topk_probs[0]]
|
161 |
+
sum_probs = sum(raw_probs)
|
162 |
+
relative_probs = [f"{(prob/sum_probs * 100):.2f}%" for prob in raw_probs]
|
163 |
+
|
164 |
+
return top1_prob, topk_breeds, relative_probs
|
165 |
+
|
166 |
+
|
167 |
+
async def detect_multiple_dogs(image, conf_threshold=0.3, iou_threshold=0.45):
|
168 |
+
results = model_yolo(image, conf=conf_threshold, iou=iou_threshold)[0]
|
169 |
+
dogs = []
|
170 |
+
boxes = []
|
171 |
+
for box in results.boxes:
|
172 |
+
if box.cls == 16: # COCO dataset class for dog is 16
|
173 |
+
xyxy = box.xyxy[0].tolist()
|
174 |
+
confidence = box.conf.item()
|
175 |
+
boxes.append((xyxy, confidence))
|
176 |
+
|
177 |
+
if not boxes:
|
178 |
+
dogs.append((image, 1.0, [0, 0, image.width, image.height]))
|
179 |
+
else:
|
180 |
+
nms_boxes = non_max_suppression(boxes, iou_threshold)
|
181 |
+
|
182 |
+
for box, confidence in nms_boxes:
|
183 |
+
x1, y1, x2, y2 = box
|
184 |
+
w, h = x2 - x1, y2 - y1
|
185 |
+
x1 = max(0, x1 - w * 0.05)
|
186 |
+
y1 = max(0, y1 - h * 0.05)
|
187 |
+
x2 = min(image.width, x2 + w * 0.05)
|
188 |
+
y2 = min(image.height, y2 + h * 0.05)
|
189 |
+
cropped_image = image.crop((x1, y1, x2, y2))
|
190 |
+
dogs.append((cropped_image, confidence, [x1, y1, x2, y2]))
|
191 |
+
|
192 |
+
return dogs
|
193 |
+
|
194 |
+
|
195 |
+
def non_max_suppression(boxes, iou_threshold):
|
196 |
+
keep = []
|
197 |
+
boxes = sorted(boxes, key=lambda x: x[1], reverse=True)
|
198 |
+
while boxes:
|
199 |
+
current = boxes.pop(0)
|
200 |
+
keep.append(current)
|
201 |
+
boxes = [box for box in boxes if calculate_iou(current[0], box[0]) < iou_threshold]
|
202 |
+
return keep
|
203 |
+
|
204 |
+
|
205 |
+
def calculate_iou(box1, box2):
|
206 |
+
x1 = max(box1[0], box2[0])
|
207 |
+
y1 = max(box1[1], box2[1])
|
208 |
+
x2 = min(box1[2], box2[2])
|
209 |
+
y2 = min(box1[3], box2[3])
|
210 |
+
|
211 |
+
intersection = max(0, x2 - x1) * max(0, y2 - y1)
|
212 |
+
area1 = (box1[2] - box1[0]) * (box1[3] - box1[1])
|
213 |
+
area2 = (box2[2] - box2[0]) * (box2[3] - box2[1])
|
214 |
+
|
215 |
+
iou = intersection / float(area1 + area2 - intersection)
|
216 |
+
return iou
|
217 |
+
|
218 |
+
|
219 |
+
async def process_single_dog(image):
|
220 |
+
"""Process a single dog image and return breed predictions and HTML output."""
|
221 |
+
top1_prob, topk_breeds, relative_probs = await predict_single_dog(image)
|
222 |
+
|
223 |
+
# Case 1: Low confidence - unclear image or breed not in dataset
|
224 |
+
if top1_prob < 0.2:
|
225 |
+
error_message = format_warning_html(
|
226 |
+
'The image is unclear or the breed is not in the dataset. Please upload a clearer image of a dog.'
|
227 |
+
)
|
228 |
+
initial_state = {
|
229 |
+
"explanation": error_message,
|
230 |
+
"image": None,
|
231 |
+
"is_multi_dog": False
|
232 |
+
}
|
233 |
+
return error_message, None, initial_state
|
234 |
+
|
235 |
+
breed = topk_breeds[0]
|
236 |
+
|
237 |
+
# Case 2: High confidence - single breed result
|
238 |
+
if top1_prob >= 0.45:
|
239 |
+
description = get_dog_description(breed)
|
240 |
+
html_content = format_single_dog_result(breed, description)
|
241 |
+
initial_state = {
|
242 |
+
"explanation": html_content,
|
243 |
+
"image": image,
|
244 |
+
"is_multi_dog": False
|
245 |
+
}
|
246 |
+
return html_content, image, initial_state
|
247 |
+
|
248 |
+
# Case 3: Medium confidence - show top 3 breeds with relative probabilities
|
249 |
+
description = get_dog_description(breed)
|
250 |
+
breeds_html = format_multiple_breeds_result(
|
251 |
+
topk_breeds=topk_breeds,
|
252 |
+
relative_probs=relative_probs,
|
253 |
+
color='#34C759', # 使用單狗顏色
|
254 |
+
index=1, # 因為是單狗處理,所以index為1
|
255 |
+
get_dog_description=get_dog_description
|
256 |
+
)
|
257 |
+
|
258 |
+
initial_state = {
|
259 |
+
"explanation": breeds_html,
|
260 |
+
"image": image,
|
261 |
+
"is_multi_dog": False
|
262 |
+
}
|
263 |
+
return breeds_html, image, initial_state
|
264 |
+
|
265 |
+
|
266 |
+
def create_breed_comparison(breed1: str, breed2: str) -> dict:
|
267 |
+
breed1_info = get_dog_description(breed1)
|
268 |
+
breed2_info = get_dog_description(breed2)
|
269 |
+
|
270 |
+
# 標準化數值轉換
|
271 |
+
value_mapping = {
|
272 |
+
'Size': {'Small': 1, 'Medium': 2, 'Large': 3, 'Giant': 4},
|
273 |
+
'Exercise_Needs': {'Low': 1, 'Moderate': 2, 'High': 3, 'Very High': 4},
|
274 |
+
'Care_Level': {'Low': 1, 'Moderate': 2, 'High': 3},
|
275 |
+
'Grooming_Needs': {'Low': 1, 'Moderate': 2, 'High': 3}
|
276 |
+
}
|
277 |
+
|
278 |
+
comparison_data = {
|
279 |
+
breed1: {},
|
280 |
+
breed2: {}
|
281 |
+
}
|
282 |
+
|
283 |
+
for breed, info in [(breed1, breed1_info), (breed2, breed2_info)]:
|
284 |
+
comparison_data[breed] = {
|
285 |
+
'Size': value_mapping['Size'].get(info['Size'], 2), # 預設 Medium
|
286 |
+
'Exercise_Needs': value_mapping['Exercise_Needs'].get(info['Exercise Needs'], 2), # 預設 Moderate
|
287 |
+
'Care_Level': value_mapping['Care_Level'].get(info['Care Level'], 2),
|
288 |
+
'Grooming_Needs': value_mapping['Grooming_Needs'].get(info['Grooming Needs'], 2),
|
289 |
+
'Good_with_Children': info['Good with Children'] == 'Yes',
|
290 |
+
'Original_Data': info
|
291 |
+
}
|
292 |
+
|
293 |
+
return comparison_data
|
294 |
+
|
295 |
+
|
296 |
+
async def predict(image):
|
297 |
+
"""
|
298 |
+
Main prediction function that handles both single and multiple dog detection.
|
299 |
+
|
300 |
+
Args:
|
301 |
+
image: PIL Image or numpy array
|
302 |
+
|
303 |
+
Returns:
|
304 |
+
tuple: (html_output, annotated_image, initial_state)
|
305 |
+
"""
|
306 |
+
if image is None:
|
307 |
+
return format_warning_html("Please upload an image to start."), None, None
|
308 |
+
|
309 |
+
try:
|
310 |
+
if isinstance(image, np.ndarray):
|
311 |
+
image = Image.fromarray(image)
|
312 |
+
|
313 |
+
# Detect dogs in the image
|
314 |
+
dogs = await detect_multiple_dogs(image)
|
315 |
+
color_scheme = get_color_scheme(len(dogs) == 1)
|
316 |
+
|
317 |
+
# Prepare for annotation
|
318 |
+
annotated_image = image.copy()
|
319 |
+
draw = ImageDraw.Draw(annotated_image)
|
320 |
+
|
321 |
+
try:
|
322 |
+
font = ImageFont.truetype("arial.ttf", 24)
|
323 |
+
except:
|
324 |
+
font = ImageFont.load_default()
|
325 |
+
|
326 |
+
dogs_info = ""
|
327 |
+
|
328 |
+
# Process each detected dog
|
329 |
+
for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
330 |
+
color = color_scheme if len(dogs) == 1 else color_scheme[i % len(color_scheme)]
|
331 |
+
|
332 |
+
# Draw box and label on image
|
333 |
+
draw.rectangle(box, outline=color, width=4)
|
334 |
+
label = f"Dog {i+1}"
|
335 |
+
label_bbox = draw.textbbox((0, 0), label, font=font)
|
336 |
+
label_width = label_bbox[2] - label_bbox[0]
|
337 |
+
label_height = label_bbox[3] - label_bbox[1]
|
338 |
+
|
339 |
+
# Draw label background and text
|
340 |
+
label_x = box[0] + 5
|
341 |
+
label_y = box[1] + 5
|
342 |
+
draw.rectangle(
|
343 |
+
[label_x - 2, label_y - 2, label_x + label_width + 4, label_y + label_height + 4],
|
344 |
+
fill='white',
|
345 |
+
outline=color,
|
346 |
+
width=2
|
347 |
+
)
|
348 |
+
draw.text((label_x, label_y), label, fill=color, font=font)
|
349 |
+
|
350 |
+
# Predict breed
|
351 |
+
top1_prob, topk_breeds, relative_probs = await predict_single_dog(cropped_image)
|
352 |
+
combined_confidence = detection_confidence * top1_prob
|
353 |
+
|
354 |
+
# Format results based on confidence
|
355 |
+
if combined_confidence < 0.2:
|
356 |
+
dogs_info += format_error_message(color, i+1)
|
357 |
+
elif top1_prob >= 0.45:
|
358 |
+
breed = topk_breeds[0]
|
359 |
+
description = get_dog_description(breed)
|
360 |
+
dogs_info += format_single_dog_result(breed, description, color)
|
361 |
+
else:
|
362 |
+
dogs_info += format_multiple_breeds_result(
|
363 |
+
topk_breeds,
|
364 |
+
relative_probs,
|
365 |
+
color,
|
366 |
+
i+1,
|
367 |
+
get_dog_description
|
368 |
+
)
|
369 |
+
|
370 |
+
# Wrap final HTML output
|
371 |
+
html_output = format_multi_dog_container(dogs_info)
|
372 |
+
|
373 |
+
# Prepare initial state
|
374 |
+
initial_state = {
|
375 |
+
"dogs_info": dogs_info,
|
376 |
+
"image": annotated_image,
|
377 |
+
"is_multi_dog": len(dogs) > 1,
|
378 |
+
"html_output": html_output
|
379 |
+
}
|
380 |
+
|
381 |
+
return html_output, annotated_image, initial_state
|
382 |
+
|
383 |
+
except Exception as e:
|
384 |
+
error_msg = f"An error occurred: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
385 |
+
print(error_msg)
|
386 |
+
return format_warning_html(error_msg), None, None
|
387 |
+
|
388 |
+
|
389 |
+
def show_details_html(choice, previous_output, initial_state):
|
390 |
+
"""
|
391 |
+
Generate detailed HTML view for a selected breed.
|
392 |
+
|
393 |
+
Args:
|
394 |
+
choice: str, Selected breed option
|
395 |
+
previous_output: str, Previous HTML output
|
396 |
+
initial_state: dict, Current state information
|
397 |
+
|
398 |
+
Returns:
|
399 |
+
tuple: (html_output, gradio_update, updated_state)
|
400 |
+
"""
|
401 |
+
if not choice:
|
402 |
+
return previous_output, gr.update(visible=True), initial_state
|
403 |
+
|
404 |
+
try:
|
405 |
+
breed = choice.split("More about ")[-1]
|
406 |
+
description = get_dog_description(breed)
|
407 |
+
html_output = format_breed_details_html(description, breed)
|
408 |
+
|
409 |
+
# Update state
|
410 |
+
initial_state["current_description"] = html_output
|
411 |
+
initial_state["original_buttons"] = initial_state.get("buttons", [])
|
412 |
+
|
413 |
+
return html_output, gr.update(visible=True), initial_state
|
414 |
+
|
415 |
+
except Exception as e:
|
416 |
+
error_msg = f"An error occurred while showing details: {e}"
|
417 |
+
print(error_msg)
|
418 |
+
return format_warning_html(error_msg), gr.update(visible=True), initial_state
|
419 |
+
|
420 |
+
def main():
|
421 |
+
with gr.Blocks(css=get_css_styles()) as iface:
|
422 |
+
# Header HTML
|
423 |
+
gr.HTML("""
|
424 |
+
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
425 |
+
<h1 style='font-size: 2.5em; margin-bottom: 10px; color: #2D3748;'>
|
426 |
+
🐾 PawMatch AI
|
427 |
+
</h1>
|
428 |
+
<h2 style='font-size: 1.2em; font-weight: normal; color: #4A5568; margin-top: 5px;'>
|
429 |
+
Your Smart Dog Breed Guide
|
430 |
+
</h2>
|
431 |
+
<div style='width: 50px; height: 3px; background: linear-gradient(90deg, #4299e1, #48bb78); margin: 15px auto;'></div>
|
432 |
+
<p style='color: #718096; font-size: 0.9em;'>
|
433 |
+
Powered by AI • Breed Recognition • Smart Matching • Companion Guide
|
434 |
+
</p>
|
435 |
+
</header>
|
436 |
+
""")
|
437 |
+
|
438 |
+
# 先創建歷史組件實例(但不創建標籤頁)
|
439 |
+
history_component = create_history_component()
|
440 |
+
|
441 |
+
with gr.Tabs():
|
442 |
+
# 1. 品種檢測標籤頁
|
443 |
+
example_images = [
|
444 |
+
'/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/test_images/Border_Collie.jpg',
|
445 |
+
'/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/test_images/Golden_Retriever.jpeg',
|
446 |
+
'/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/test_images/Saint_Bernard.jpeg',
|
447 |
+
'/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/test_images/Samoyed.jpg',
|
448 |
+
'/content/drive/Othercomputers/我的 MacBook Pro/Learning/Cats_Dogs_Detector/test_images/French_Bulldog.jpeg'
|
449 |
+
]
|
450 |
+
detection_components = create_detection_tab(predict, example_images)
|
451 |
+
|
452 |
+
# 2. 品種比較標籤頁
|
453 |
+
comparison_components = create_comparison_tab(
|
454 |
+
dog_breeds=dog_breeds,
|
455 |
+
get_dog_description=get_dog_description
|
456 |
+
)
|
457 |
+
|
458 |
+
# 3. 品種推薦標籤頁
|
459 |
+
recommendation_components = create_recommendation_tab(
|
460 |
+
UserPreferences=UserPreferences,
|
461 |
+
get_breed_recommendations=get_breed_recommendations,
|
462 |
+
format_recommendation_html=format_recommendation_html,
|
463 |
+
history_component=history_component
|
464 |
+
)
|
465 |
+
|
466 |
+
# 4. 最後創建歷史記錄標籤頁
|
467 |
+
create_history_tab(history_component)
|
468 |
+
|
469 |
+
# Footer
|
470 |
+
gr.HTML('''
|
471 |
+
For more details on this project and other work, feel free to visit my GitHub
|
472 |
+
<a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">
|
473 |
+
Dog Breed Classifier
|
474 |
+
</a>
|
475 |
+
''')
|
476 |
+
|
477 |
+
return iface
|
478 |
+
|
479 |
+
if __name__ == "__main__":
|
480 |
+
iface = main()
|
481 |
+
iface.launch(share=True, debug=True)
|
breed_comparison.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from dog_database import get_dog_description
|
4 |
+
|
5 |
+
def create_comparison_tab(dog_breeds, get_dog_description):
|
6 |
+
"""创建品种比较标签页
|
7 |
+
|
8 |
+
Args:
|
9 |
+
dog_breeds: 狗品种列表
|
10 |
+
get_dog_description: 获取品种描述的函数
|
11 |
+
"""
|
12 |
+
with gr.TabItem("Breed Comparison"):
|
13 |
+
gr.HTML("<p style='text-align: center;'>Select two dog breeds to compare their characteristics and care requirements.</p>")
|
14 |
+
|
15 |
+
with gr.Row():
|
16 |
+
breed1_dropdown = gr.Dropdown(
|
17 |
+
choices=dog_breeds,
|
18 |
+
label="Select First Breed",
|
19 |
+
value="Golden_Retriever"
|
20 |
+
)
|
21 |
+
breed2_dropdown = gr.Dropdown(
|
22 |
+
choices=dog_breeds,
|
23 |
+
label="Select Second Breed",
|
24 |
+
value="Border_Collie"
|
25 |
+
)
|
26 |
+
|
27 |
+
compare_btn = gr.Button("Compare Breeds")
|
28 |
+
comparison_output = gr.HTML(label="Comparison Results")
|
29 |
+
|
30 |
+
def show_comparison(breed1, breed2):
|
31 |
+
if not breed1 or not breed2:
|
32 |
+
return "Please select two breeds to compare"
|
33 |
+
|
34 |
+
breed1_info = get_dog_description(breed1)
|
35 |
+
breed2_info = get_dog_description(breed2)
|
36 |
+
|
37 |
+
html_output = f"""
|
38 |
+
<div class="dog-info-card">
|
39 |
+
<div class="comparison-grid" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
|
40 |
+
<div class="breed-info">
|
41 |
+
<h2 class="section-title">
|
42 |
+
<span class="icon">🐕</span> {breed1.replace('_', ' ')}
|
43 |
+
</h2>
|
44 |
+
<div class="info-section">
|
45 |
+
<div class="info-item">
|
46 |
+
<span class="tooltip">
|
47 |
+
<span class="icon">📏</span>
|
48 |
+
<span class="label">Size:</span>
|
49 |
+
<span class="value">{breed1_info['Size']}</span>
|
50 |
+
</span>
|
51 |
+
</div>
|
52 |
+
<div class="info-item">
|
53 |
+
<span class="tooltip">
|
54 |
+
<span class="icon">🏃</span>
|
55 |
+
<span class="label">Exercise Needs:</span>
|
56 |
+
<span class="value">{breed1_info['Exercise Needs']}</span>
|
57 |
+
</span>
|
58 |
+
</div>
|
59 |
+
<div class="info-item">
|
60 |
+
<span class="tooltip">
|
61 |
+
<span class="icon">✂️</span>
|
62 |
+
<span class="label">Grooming:</span>
|
63 |
+
<span class="value">{breed1_info['Grooming Needs']}</span>
|
64 |
+
</span>
|
65 |
+
</div>
|
66 |
+
<div class="info-item">
|
67 |
+
<span class="tooltip">
|
68 |
+
<span class="icon">👨👩👧👦</span>
|
69 |
+
<span class="label">Good with Children:</span>
|
70 |
+
<span class="value">{breed1_info['Good with Children']}</span>
|
71 |
+
</span>
|
72 |
+
</div>
|
73 |
+
</div>
|
74 |
+
</div>
|
75 |
+
|
76 |
+
<div class="breed-info">
|
77 |
+
<h2 class="section-title">
|
78 |
+
<span class="icon">🐕</span> {breed2.replace('_', ' ')}
|
79 |
+
</h2>
|
80 |
+
<div class="info-section">
|
81 |
+
<div class="info-item">
|
82 |
+
<span class="tooltip">
|
83 |
+
<span class="icon">📏</span>
|
84 |
+
<span class="label">Size:</span>
|
85 |
+
<span class="value">{breed2_info['Size']}</span>
|
86 |
+
</span>
|
87 |
+
</div>
|
88 |
+
<div class="info-item">
|
89 |
+
<span class="tooltip">
|
90 |
+
<span class="icon">🏃</span>
|
91 |
+
<span class="label">Exercise Needs:</span>
|
92 |
+
<span class="value">{breed2_info['Exercise Needs']}</span>
|
93 |
+
</span>
|
94 |
+
</div>
|
95 |
+
<div class="info-item">
|
96 |
+
<span class="tooltip">
|
97 |
+
<span class="icon">✂️</span>
|
98 |
+
<span class="label">Grooming:</span>
|
99 |
+
<span class="value">{breed2_info['Grooming Needs']}</span>
|
100 |
+
</span>
|
101 |
+
</div>
|
102 |
+
<div class="info-item">
|
103 |
+
<span class="tooltip">
|
104 |
+
<span class="icon">👨👩👧👦</span>
|
105 |
+
<span class="label">Good with Children:</span>
|
106 |
+
<span class="value">{breed2_info['Good with Children']}</span>
|
107 |
+
</span>
|
108 |
+
</div>
|
109 |
+
</div>
|
110 |
+
</div>
|
111 |
+
</div>
|
112 |
+
</div>
|
113 |
+
"""
|
114 |
+
return html_output
|
115 |
+
|
116 |
+
compare_btn.click(
|
117 |
+
show_comparison,
|
118 |
+
inputs=[breed1_dropdown, breed2_dropdown],
|
119 |
+
outputs=comparison_output
|
120 |
+
)
|
121 |
+
|
122 |
+
return {
|
123 |
+
'breed1_dropdown': breed1_dropdown,
|
124 |
+
'breed2_dropdown': breed2_dropdown,
|
125 |
+
'compare_btn': compare_btn,
|
126 |
+
'comparison_output': comparison_output
|
127 |
+
}
|
breed_recommendation.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from recommendation_html_format import format_recommendation_html, get_breed_recommendations
|
4 |
+
|
5 |
+
def create_recommendation_tab(UserPreferences, get_breed_recommendations, format_recommendation_html, history_component):
|
6 |
+
"""创建品种推荐标签页
|
7 |
+
|
8 |
+
Args:
|
9 |
+
UserPreferences: 用户偏好类
|
10 |
+
get_breed_recommendations: 获取品种推荐的函数
|
11 |
+
format_recommendation_html: 格式化推荐结果的函数
|
12 |
+
history_component: 历史记录组件
|
13 |
+
"""
|
14 |
+
with gr.TabItem("Breed Recommendation"):
|
15 |
+
gr.HTML("<p style='text-align: center;'>Tell us about your lifestyle, and we'll recommend the perfect dog breeds for you!</p>")
|
16 |
+
|
17 |
+
with gr.Row():
|
18 |
+
with gr.Column():
|
19 |
+
living_space = gr.Radio(
|
20 |
+
choices=["apartment", "house_small", "house_large"],
|
21 |
+
label="What type of living space do you have?",
|
22 |
+
info="Choose your current living situation",
|
23 |
+
value="apartment"
|
24 |
+
)
|
25 |
+
|
26 |
+
exercise_time = gr.Slider(
|
27 |
+
minimum=0,
|
28 |
+
maximum=180,
|
29 |
+
value=60,
|
30 |
+
label="Daily exercise time (minutes)",
|
31 |
+
info="Consider walks, play time, and training"
|
32 |
+
)
|
33 |
+
|
34 |
+
grooming_commitment = gr.Radio(
|
35 |
+
choices=["low", "medium", "high"],
|
36 |
+
label="Grooming commitment level",
|
37 |
+
info="Low: monthly, Medium: weekly, High: daily",
|
38 |
+
value="medium"
|
39 |
+
)
|
40 |
+
|
41 |
+
with gr.Column():
|
42 |
+
experience_level = gr.Radio(
|
43 |
+
choices=["beginner", "intermediate", "advanced"],
|
44 |
+
label="Dog ownership experience",
|
45 |
+
info="Be honest - this helps find the right match",
|
46 |
+
value="beginner"
|
47 |
+
)
|
48 |
+
|
49 |
+
has_children = gr.Checkbox(
|
50 |
+
label="Have children at home",
|
51 |
+
info="Helps recommend child-friendly breeds"
|
52 |
+
)
|
53 |
+
|
54 |
+
noise_tolerance = gr.Radio(
|
55 |
+
choices=["low", "medium", "high"],
|
56 |
+
label="Noise tolerance level",
|
57 |
+
info="Some breeds are more vocal than others",
|
58 |
+
value="medium"
|
59 |
+
)
|
60 |
+
|
61 |
+
get_recommendations_btn = gr.Button("Find My Perfect Match! 🔍", variant="primary")
|
62 |
+
recommendation_output = gr.HTML(label="Breed Recommendations")
|
63 |
+
|
64 |
+
def on_find_match_click(*args):
|
65 |
+
try:
|
66 |
+
user_prefs = UserPreferences(
|
67 |
+
living_space=args[0],
|
68 |
+
exercise_time=args[1],
|
69 |
+
grooming_commitment=args[2],
|
70 |
+
experience_level=args[3],
|
71 |
+
has_children=args[4],
|
72 |
+
noise_tolerance=args[5],
|
73 |
+
space_for_play=True if args[0] != "apartment" else False,
|
74 |
+
other_pets=False,
|
75 |
+
climate="moderate",
|
76 |
+
health_sensitivity="medium", # 新增: 默認中等敏感度
|
77 |
+
barking_acceptance=args[5] # 使用 noise_tolerance 作為 barking_acceptance
|
78 |
+
)
|
79 |
+
|
80 |
+
recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
81 |
+
|
82 |
+
history_results = [{
|
83 |
+
'breed': rec['breed'],
|
84 |
+
'rank': rec['rank'],
|
85 |
+
'overall_score': rec['final_score'],
|
86 |
+
'base_score': rec['base_score'],
|
87 |
+
'bonus_score': rec['bonus_score'],
|
88 |
+
'scores': rec['scores']
|
89 |
+
} for rec in recommendations]
|
90 |
+
|
91 |
+
# 保存到歷史記錄,也需要更新保存的偏好設定
|
92 |
+
history_component.save_search(
|
93 |
+
user_preferences={
|
94 |
+
'living_space': args[0],
|
95 |
+
'exercise_time': args[1],
|
96 |
+
'grooming_commitment': args[2],
|
97 |
+
'experience_level': args[3],
|
98 |
+
'has_children': args[4],
|
99 |
+
'noise_tolerance': args[5],
|
100 |
+
'health_sensitivity': "medium",
|
101 |
+
'barking_acceptance': args[5]
|
102 |
+
},
|
103 |
+
results=history_results
|
104 |
+
)
|
105 |
+
|
106 |
+
return format_recommendation_html(recommendations)
|
107 |
+
|
108 |
+
except Exception as e:
|
109 |
+
print(f"Error in find match: {str(e)}")
|
110 |
+
import traceback
|
111 |
+
print(traceback.format_exc())
|
112 |
+
return "Error getting recommendations"
|
113 |
+
|
114 |
+
get_recommendations_btn.click(
|
115 |
+
fn=on_find_match_click,
|
116 |
+
inputs=[
|
117 |
+
living_space,
|
118 |
+
exercise_time,
|
119 |
+
grooming_commitment,
|
120 |
+
experience_level,
|
121 |
+
has_children,
|
122 |
+
noise_tolerance
|
123 |
+
],
|
124 |
+
outputs=recommendation_output
|
125 |
+
)
|
126 |
+
|
127 |
+
return {
|
128 |
+
'living_space': living_space,
|
129 |
+
'exercise_time': exercise_time,
|
130 |
+
'grooming_commitment': grooming_commitment,
|
131 |
+
'experience_level': experience_level,
|
132 |
+
'has_children': has_children,
|
133 |
+
'noise_tolerance': noise_tolerance,
|
134 |
+
'get_recommendations_btn': get_recommendations_btn,
|
135 |
+
'recommendation_output': recommendation_output
|
136 |
+
}
|
dog_database.py
ADDED
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import sqlite3
|
3 |
+
from dataclasses import dataclass
|
4 |
+
from typing import List, Dict, Optional
|
5 |
+
from decimal import Decimal
|
6 |
+
from breed_health_info import breed_health_info, default_health_note
|
7 |
+
from breed_noise_info import breed_noise_info
|
8 |
+
import numpy as np
|
9 |
+
|
10 |
+
|
11 |
+
def create_table():
|
12 |
+
conn = sqlite3.connect('animal_detector.db')
|
13 |
+
cursor = conn.cursor()
|
14 |
+
|
15 |
+
cursor.execute('''
|
16 |
+
CREATE TABLE IF NOT EXISTS AnimalCatalog (
|
17 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
18 |
+
Species TEXT NOT NULL,
|
19 |
+
Breed TEXT NOT NULL,
|
20 |
+
Size_Category TEXT,
|
21 |
+
Typical_Lifespan TEXT,
|
22 |
+
Temperament TEXT,
|
23 |
+
Care_Level TEXT,
|
24 |
+
Good_With_Children BOOLEAN,
|
25 |
+
Exercise_Needs TEXT,
|
26 |
+
Grooming_Needs TEXT,
|
27 |
+
Brief_Description TEXT
|
28 |
+
)
|
29 |
+
''')
|
30 |
+
|
31 |
+
conn.commit()
|
32 |
+
cursor.close()
|
33 |
+
conn.close()
|
34 |
+
|
35 |
+
# 創建表
|
36 |
+
create_table()
|
37 |
+
|
38 |
+
def insert_dog_data():
|
39 |
+
conn = sqlite3.connect('animal_detector.db')
|
40 |
+
cursor = conn.cursor()
|
41 |
+
|
42 |
+
dog_data = [
|
43 |
+
('Dog', 'Afghan_Hound', 'Large', '12-18 years', 'Independent, dignified, aloof', 'High', True, 'High', 'High', 'Known for their long, silky coat and regal appearance, Afghan Hounds are ancient sighthounds with a unique, elegant presence.'),
|
44 |
+
('Dog', 'African_Hunting_Dog', 'Medium', '10-12 years', 'Social, intelligent, energetic', 'Very High', False, 'Very High', 'Low', 'Also called African Wild Dogs, these are not domestic dogs and are endangered in their native habitats.'),
|
45 |
+
('Dog', 'Airedale', 'Large', '10-12 years', 'Friendly, clever, courageous', 'High', True, 'High', 'High', 'Known as the "King of Terriers," Airedales are the largest of the terrier breeds and very versatile. Originally from Aire Valley of Yorkshire, they served in police and military roles while maintaining their hunting abilities.'),
|
46 |
+
('Dog', 'American_Staffordshire_Terrier', 'Medium', '12-16 years', 'Confident, good-natured, courageous', 'Moderate', True, 'High', 'Low', 'Often confused with Pit Bulls, Am Staffs are strong, muscular dogs with a gentle and loving nature.'),
|
47 |
+
('Dog', 'Appenzeller', 'Medium', '12-15 years', 'Reliable, fearless, lively', 'High', True, 'High', 'Moderate', 'Swiss mountain dogs known for their agility and enthusiasm, Appenzellers make excellent working and family dogs. Traditional cattle herders from the Swiss Alps, they combine working intelligence with devoted guardianship.'),
|
48 |
+
('Dog', 'Australian_Terrier', 'Small', '12-15 years', 'Courageous, spirited, alert', 'Moderate', True, 'Moderate', 'Moderate', 'Small, sturdy terriers originally bred to control rodents, known for their confident personality. First breed developed in Australia, combining the tenacity of old terrier breeds with adaptability to harsh conditions.'),
|
49 |
+
('Dog', 'Bedlington_Terrier', 'Medium', '11-16 years', 'Mild, gentle, lively', 'High', True, 'Moderate', 'High', 'Known for their lamb-like appearance, Bedlington Terriers are energetic and good with families. Despite their gentle look, they were originally miners\' dogs bred for hunting vermin and remain surprisingly fast and athletic.'),
|
50 |
+
('Dog', 'Bernese_Mountain_Dog', 'Large', '6-8 years', 'Good-natured, calm, strong', 'High', True, 'Moderate', 'High', 'Large, tri-colored Swiss working dogs known for their gentle nature and striking appearance. Despite their short lifespan, they are excellent family companions and draft dogs. Often called "Berners", they are patient with children but prone to heat sensitivity due to their thick coat.'),
|
51 |
+
('Dog', 'Blenheim_Spaniel', 'Small', '12-14 years', 'Affectionate, gentle, lively', 'Moderate', True, 'Moderate', 'High', 'A color variety of the Cavalier King Charles Spaniel, known for their red and white coat and friendly nature.'),
|
52 |
+
('Dog', 'Border_Collie', 'Medium', '12-15 years', 'Intelligent, energetic, alert', 'High', True, 'Very High', 'Moderate', 'Often considered the most intelligent dog breed, Border Collies are tireless workers with intense herding instincts. Known for their "eye" - a distinctive herding gaze, they excel in dog sports and need constant mental stimulation to prevent boredom.'),
|
53 |
+
('Dog', 'Border_Terrier', 'Small', '12-15 years', 'Affectionate, intelligent, even-tempered', 'Moderate', True, 'High', 'Low', 'Small but tough terriers with an otter-like head, known for their friendly and adaptable nature.'),
|
54 |
+
('Dog', 'Boston_Bull', 'Small', '11-13 years', 'Friendly, lively, intelligent', 'Moderate', True, 'Moderate', 'Low', 'Also known as Boston Terriers, these "American Gentlemen" are friendly and adaptable. First bred in Boston as fighting dogs, they evolved into beloved companions known for their tuxedo-like coat pattern and gentle disposition.'),
|
55 |
+
('Dog', 'Bouvier_Des_Flandres', 'Large', '10-12 years', 'Gentle, loyal, rational', 'High', True, 'High', 'High', 'Large, powerful herding dogs with a tousled coat, known for their versatility and even temperament. Originally bred as cattle drivers in Flanders, they excel in various roles from farm work to family protection.'),
|
56 |
+
('Dog', 'Brabancon_Griffon', 'Small', '12-15 years', 'Self-important, sensitive, affectionate', 'Moderate', False, 'Moderate', 'Low', 'Also known as the Brussels Griffon, these small dogs have a distinctive beard and mustache, giving them an almost human-like expression.'),
|
57 |
+
('Dog', 'Brittany_Spaniel', 'Medium', '12-14 years', 'Bright, fun-loving, upbeat', 'High', True, 'High', 'Moderate', 'Versatile hunting dogs and active companions, Brittanys are known for their energy and intelligence. Originally from France, these agile bird dogs excel in both hunting and family life with their eager and athletic nature.'),
|
58 |
+
('Dog', 'Cardigan', 'Small', '12-15 years', 'Affectionate, loyal, intelligent', 'Moderate', True, 'Moderate', 'Moderate', 'Distinguished from Pembroke Welsh Corgis by their long tail, Cardigans are intelligent herding dogs with a fox-like appearance.'),
|
59 |
+
('Dog', 'Chesapeake_Bay_Retriever', 'Large', '10-13 years', 'Bright, sensitive, affectionate', 'High', True, 'High', 'Moderate', 'Known for their waterproof coat, Chessies are strong swimmers and excellent retrievers. Developed in the American Chesapeake Bay region, they are famous for their ability to work in icy waters and their distinctive wavy coat.'),
|
60 |
+
('Dog', 'Chihuahua', 'Small', '12-20 years', 'Charming, graceful, sassy', 'Moderate', False, 'Low', 'Low', 'One of the smallest dog breeds, known for their big personalities and loyalty to their owners. Named after Mexico\'s largest state, they are ancient companions with terrier-like attitudes and remarkably long lifespans for dogs.'),
|
61 |
+
('Dog', 'Dandie_Dinmont', 'Small', '12-15 years', 'Independent, intelligent, dignified', 'Moderate', True, 'Moderate', 'Moderate', 'Recognizable by their long body and distinctive topknot of hair on their head. Named after a character in Sir Walter Scott novel, these unique terriers combine determination with dignity, making them distinctive companions.'),
|
62 |
+
('Dog', 'Doberman', 'Large', '10-12 years', 'Loyal, fearless, alert', 'High', True, 'High', 'Low', 'Sleek, athletic dogs known for their intelligence and loyalty, often used as guard dogs. Highly trainable and protective, they excel in both working roles and as family guardians.'),
|
63 |
+
('Dog', 'English_Foxhound', 'Medium', '10-13 years', 'Friendly, active, gentle', 'High', True, 'Very High', 'Low', 'Athletic, pack-oriented hounds originally bred for fox hunting in England. Known for their stamina, melodious voice, and strong hunting instincts.'),
|
64 |
+
('Dog', 'English_Setter', 'Large', '10-12 years', 'Gentle, friendly, placid', 'High', True, 'High', 'High', 'Known for their speckled coat or "belton" markings, English Setters are elegant bird dogs and affectionate companions.'),
|
65 |
+
('Dog', 'English_Springer', 'Medium', '12-14 years', 'Friendly, playful, obedient', 'High', True, 'High', 'High', 'Energetic and eager to please, Springers are excellent hunting dogs and loving family pets. Their name comes from their hunting style of "springing" at game birds, combining strong work ethics with a merry, affectionate family nature.'),
|
66 |
+
('Dog', 'EntleBucher', 'Medium', '11-13 years', 'Loyal, enthusiastic, intelligent', 'High', True, 'High', 'Low', 'The smallest of the Swiss Mountain Dogs, known for their agility and herding abilities. Originally from the Swiss valley of Entlebuch, they combine the strength of mountain dogs with remarkable agility and quick thinking.'),
|
67 |
+
('Dog', 'Eskimo_Dog', 'Large', '10-15 years', 'Alert, loyal, intelligent', 'High', True, 'High', 'High', 'Also known as the Canadian Eskimo Dog, these are strong, resilient working dogs adapted to Arctic conditions. Ancient breed used by Inuit people for hunting and transportation, known for their power and endurance.'),
|
68 |
+
('Dog', 'French_Bulldog', 'Small', '10-12 years', 'Playful, adaptable, smart', 'Moderate', True, 'Low', 'Low', 'French Bulldogs are small, muscular dogs with a smooth coat, short face, and bat-like ears. They are affectionate, playful, and well-suited for family living.'),
|
69 |
+
('Dog', 'German_Shepherd', 'Large', '10-13 years', 'Confident, courageous, smart', 'High', True, 'High', 'Moderate', 'Versatile working dogs, German Shepherds excel in various roles from police work to family protection.'),
|
70 |
+
('Dog', 'German_Short-Haired_Pointer', 'Large', '10-12 years', 'Friendly, intelligent, willing to please', 'High', True, 'Very High', 'Moderate', 'Versatile hunting dogs known for their pointer stance, these dogs excel in both water and land retrieving.'),
|
71 |
+
('Dog', 'Gordon_Setter', 'Large', '10-12 years', 'Confident, fearless, alert', 'High', True, 'High', 'High', 'The largest of the setter breeds, Gordon Setters are known for their black and tan coloring and loyal nature. Developed in Scotland, these noble bird dogs combine strong hunting abilities with devoted family loyalty.'),
|
72 |
+
('Dog', 'Great_Dane', 'Giant', '7-10 years', 'Friendly, patient, dependable', 'High', True, 'Moderate', 'Low', 'One of the largest dog breeds, Great Danes are known as gentle giants with a friendly disposition. Originally bred for hunting large game, these noble giants now excel as loving family companions despite their imposing size.'),
|
73 |
+
('Dog', 'Great_Pyrenees', 'Large', '10-12 years', 'Patient, calm, gentle', 'High', True, 'Moderate', 'High', 'Large, powerful dogs originally bred to guard livestock, known for their gentle and protective nature. These ancient guardians of the Pyrenees mountains combine strength and nobility with a deep devotion to family and flock.'),
|
74 |
+
('Dog', 'Greater_Swiss_Mountain_dog', 'Large', '8-11 years', 'Faithful, alert, vigilant', 'Moderate', True, 'Moderate', 'Low', 'Large, strong working dogs with a tricolor coat, Swissies are gentle giants with a calm temperament.'),
|
75 |
+
('Dog', 'Ibizan_Hound', 'Medium', '12-14 years', 'Even-tempered, loyal, independent', 'Moderate', True, 'High', 'Low', 'Sleek, athletic sighthounds known for their large, erect ears and red and white coats. Ancient breed from Balearic Islands, they can jump remarkable heights and were bred to hunt rabbits in difficult terrain.'),
|
76 |
+
('Dog', 'Irish_Setter', 'Large', '11-15 years', 'Outgoing, sweet-tempered, active', 'High', True, 'High', 'High', 'Recognizable by their rich red coat, Irish Setters are energetic and playful dogs that love family life.'),
|
77 |
+
('Dog', 'Irish_Terrier', 'Medium', '12-16 years', 'Bold, daring, intelligent', 'Moderate', True, 'High', 'Moderate', 'Known as the Daredevil of dogdom, Irish Terriers are courageous and loyal with a distinctive red coat. One of the oldest terrier breeds, they earned fame for their bravery as messenger dogs in World War I.'),
|
78 |
+
('Dog', 'Irish_Water_Spaniel', 'Large', '10-12 years', 'Playful, brave, intelligent', 'High', True, 'High', 'High', 'Largest of the spaniels, known for their curly, liver-colored coat and rat-like tail. These distinctive water retrievers combine the agility of a spaniel with the endurance of a retriever, featuring a water-repellent double coat.'),
|
79 |
+
('Dog', 'Irish_Wolfhound', 'Giant', '6-8 years', 'Gentle, patient, dignified', 'High', True, 'Moderate', 'Moderate', 'The tallest of all dog breeds, Irish Wolfhounds are gentle giants known for their calm and friendly nature. Ancient warriors of Ireland, they once hunted wolves but now serve as peaceful family companions.'),
|
80 |
+
('Dog', 'Italian_Greyhound', 'Small', '12-15 years', 'Sensitive, alert, playful', 'Moderate', False, 'Moderate', 'Low', 'Miniature sighthounds known for their elegant appearance and affectionate nature, Italian Greyhounds make excellent companion dogs.'),
|
81 |
+
('Dog', 'Japanese_Spaniel', 'Small', '10-12 years', 'Charming, noble, affectionate', 'Moderate', False, 'Low', 'High', 'Also known as the Japanese Chin, these small companion dogs have a distinctive flat face and were once favorites of Japanese nobility.'),
|
82 |
+
('Dog', 'Kerry_Blue_Terrier', 'Medium', '12-15 years', 'Alert, adaptable, people-oriented', 'High', True, 'High', 'High', 'Medium-sized terriers with a distinctive blue coat, known for their versatility and intelligence. Originally from County Kerry, Ireland, they were all-purpose farm dogs that evolved into capable working and companion animals.'),
|
83 |
+
('Dog', 'Labrador_Retriever', 'Large', '10-12 years', 'Friendly, outgoing, even-tempered', 'Moderate', True, 'High', 'Moderate', 'One of the most popular dog breeds, known for their friendly nature and excellent retrieving skills. Originally from Newfoundland, these versatile dogs excel as family companions, service dogs, and working retrievers.'),
|
84 |
+
('Dog', 'Lakeland_Terrier', 'Small', '12-16 years', 'Bold, friendly, confident', 'Moderate', True, 'High', 'High', 'Named after the Lake District in England, these terriers are sturdy and bold with a wiry coat. Developed to protect sheep from foxes, they remain confident and fearless while being adaptable family companions.'),
|
85 |
+
('Dog', 'Leonberg', 'Giant', '7-9 years', 'Gentle, friendly, intelligent', 'High', True, 'Moderate', 'High', 'Large, muscular dogs with a lion-like mane, known for their gentle nature and water rescue abilities. Created in the German town of Leonberg, these gentle giants combine strength with remarkable patience and grace.'),
|
86 |
+
('Dog', 'Lhasa', 'Small', '12-15 years', 'Confident, smart, comical', 'High', False, 'Low', 'High', 'Lhasa Apsos are small but sturdy dogs with a long, flowing coat. They were originally bred as indoor sentinel dogs in Buddhist monasteries.'),
|
87 |
+
('Dog', 'Maltese_Dog', 'Small', '12-15 years', 'Gentle, playful, charming', 'High', False, 'Low', 'High', 'Small, elegant dogs with long, silky white coats, known for their sweet and affectionate nature. Ancient breed of Mediterranean origin, they were cherished by nobles for centuries and remain adaptable, gentle companions.'),
|
88 |
+
('Dog', 'Mexican_Hairless', 'Varies', '12-15 years', 'Loyal, alert, cheerful', 'Moderate', True, 'Moderate', 'Low', 'Also known as the Xoloitzcuintli, these dogs come in three sizes and can be either hairless or coated, known for their ancient history in Mexico.'),
|
89 |
+
('Dog', 'Newfoundland', 'Giant', '8-10 years', 'Sweet, patient, devoted', 'High', True, 'Moderate', 'High', 'Large, strong dogs known for their water rescue abilities and gentle nature, especially with children. These powerful swimmers have a natural lifesaving instinct and are famous for their calm, noble temperament.'),
|
90 |
+
('Dog', 'Norfolk_Terrier', 'Small', '12-15 years', 'Fearless, spirited, companionable', 'Moderate', True, 'Moderate', 'Moderate', 'Small, sturdy terriers with a wiry coat, known for their playful and affectionate nature.'),
|
91 |
+
('Dog', 'Norwegian_Elkhound', 'Medium', '12-15 years', 'Bold, playful, loyal', 'High', True, 'High', 'High', 'Ancient Nordic breed known for their silver-gray coat and curled tail, originally used for hunting moose and other large game.'),
|
92 |
+
('Dog', 'Norwich_Terrier', 'Small', '12-15 years', 'Fearless, loyal, affectionate', 'Moderate', True, 'Moderate', 'Moderate', 'One of the smallest terriers, Norwich Terriers are hardy, fearless, and affectionate companions.'),
|
93 |
+
('Dog', 'Old_English_Sheepdog', 'Large', '10-12 years', 'Adaptable, gentle, intelligent', 'High', True, 'Moderate', 'High', 'Recognizable by their shaggy coat, Old English Sheepdogs are adaptable and good-natured. Once droving dogs of western England, they combine herding ability with a playful, protective nature toward their families.'),
|
94 |
+
('Dog', 'Pekinese', 'Small', '12-14 years', 'Affectionate, loyal, regal in manner', 'Moderate', False, 'Low', 'High', 'Also spelled Pekingese, these small dogs with flat faces and long coats were once sacred to Chinese royalty.'),
|
95 |
+
('Dog', 'Pembroke', 'Small', '12-15 years', 'Affectionate, intelligent, outgoing', 'Moderate', True, 'Moderate', 'Moderate', 'Known for their short legs and long bodies, Pembroke Welsh Corgis are herding dogs favored by the British royal family.'),
|
96 |
+
('Dog', 'Pomeranian', 'Small', '12-16 years', 'Lively, bold, inquisitive', 'Moderate', False, 'Low', 'High', 'Small, fluffy dogs with fox-like faces, known for their vivacious personalities and luxurious coats. Once larger sled dogs, these bred-down companions retain their bold spirit and were favored by royalty including Queen Victoria.'),
|
97 |
+
('Dog', 'Rhodesian_Ridgeback', 'Large', '10-12 years', 'Dignified, intelligent, strong-willed', 'Moderate', True, 'High', 'Low', 'Large, muscular dogs known for the ridge of hair along their backs, originally bred to hunt lions in Africa.'),
|
98 |
+
('Dog', 'Rottweiler', 'Large', '8-10 years', 'Loyal, loving, confident guardian', 'High', True, 'High', 'Low', 'Powerful and protective, Rottweilers are excellent guard dogs but also loving family companions when well-trained.'),
|
99 |
+
('Dog', 'Saint_Bernard', 'Giant', '8-10 years', 'Gentle, patient, friendly', 'High', True, 'Moderate', 'High', 'Known for their massive size and gentle nature, Saint Bernards were originally bred for rescue work in the Swiss Alps.'),
|
100 |
+
('Dog', 'Saluki', 'Large', '12-14 years', 'Gentle, dignified, independent-minded', 'High', True, 'High', 'Low', 'Ancient sighthounds known for their grace and speed, Salukis have a distinctive feathered coat and ears.'),
|
101 |
+
('Dog', 'Samoyed', 'Medium', '12-14 years', 'Friendly, gentle, adaptable', 'High', True, 'High', 'High', 'Beautiful white Arctic dogs known for their "smiling" expression and thick, fluffy coat. Originally bred for sledding and herding reindeer, they combine working dog capability with a warm, family-friendly nature.'),
|
102 |
+
('Dog', 'Scotch_Terrier', 'Small', '11-13 years', 'Independent, confident, spirited', 'Moderate', True, 'Moderate', 'High', 'Also known as the Scottish Terrier, these distinctive dogs with beards and eyebrows are known for their dignified, almost human-like personality.'),
|
103 |
+
('Dog', 'Scottish_Deerhound', 'Large', '8-11 years', 'Gentle, dignified, polite', 'High', True, 'High', 'Moderate', 'Large, wiry-coated sighthounds resembling Greyhounds, known for their gentle nature and hunting ability.'),
|
104 |
+
('Dog', 'Sealyham_Terrier', 'Small', '12-14 years', 'Alert, outgoing, calm', 'Moderate', True, 'Moderate', 'High', 'Originally bred for hunting, Sealyhams are now rare but make charming and sturdy companions. Developed in Wales to hunt badgers and otters, they combine terrier tenacity with a surprisingly calm demeanor.'),
|
105 |
+
('Dog', 'Shetland_Sheepdog', 'Small', '12-14 years', 'Playful, energetic, intelligent', 'High', True, 'High', 'High', 'Small herding dogs resembling miniature Collies, known for their intelligence and agility. Originally from the Shetland Islands, these "Shelties" excel in obedience, herding, and agility competitions while being devoted family companions.'),
|
106 |
+
('Dog', 'Shih-Tzu', 'Small', '10-16 years', 'Affectionate, playful, outgoing', 'High', True, 'Low', 'High', 'Small, affectionate companion dogs known for their long, silky coat and sweet personality. Originally bred for Chinese royalty, they are excellent lap dogs and adapt well to both city and suburban life.'),
|
107 |
+
('Dog', 'Siberian_Husky', 'Medium', '12-14 years', 'Outgoing, mischievous, loyal', 'High', True, 'Very High', 'Moderate', 'Beautiful sled dogs known for their striking blue eyes, thick coats, and wolf-like appearance. Originally bred by the Chukchi people of northeastern Asia, they combine endurance with a friendly, adventurous spirit.'),
|
108 |
+
('Dog', 'Staffordshire_Bullterrier', 'Medium', '12-14 years', 'Courageous, intelligent, loyal', 'Moderate', True, 'High', 'Low', 'Strong, muscular terriers known for their courage and affectionate nature, especially with children.'),
|
109 |
+
('Dog', 'Sussex_Spaniel', 'Medium', '11-13 years', 'Calm, friendly, merry', 'Moderate', True, 'Moderate', 'Moderate', 'Rare breed of spaniel known for their golden-liver coat and low-set body, originally bred for hunting.'),
|
110 |
+
('Dog', 'Tibetan_Mastiff', 'Large', '10-12 years', 'Independent, reserved, intelligent', 'High', False, 'Moderate', 'High', 'Ancient guardian breed known for their massive size and thick coat, Tibetan Mastiffs are independent and protective.'),
|
111 |
+
('Dog', 'Tibetan_Terrier', 'Medium', '12-15 years', 'Affectionate, sensitive, clever', 'High', True, 'Moderate', 'High', 'Not actually terriers, these dogs were bred in Tibet and are known for their profuse, long coat.'),
|
112 |
+
('Dog', 'Walker_Hound', 'Large', '12-13 years', 'Smart, brave, friendly', 'Moderate', True, 'High', 'Low', 'Also known as the Treeing Walker Coonhound, these dogs are excellent hunters with a distinctive bark. Developed in Kentucky from Virginia Hounds, they are renowned for their speed, endurance, and melodious voice.'),
|
113 |
+
('Dog', 'Weimaraner', 'Large', '10-13 years', 'Friendly, fearless, obedient', 'High', True, 'High', 'Low', 'Known as the "Gray Ghost," Weimaraners are athletic and intelligent dogs with a distinctive silver-gray coat.'),
|
114 |
+
('Dog', 'Welsh_Springer_Spaniel', 'Medium', '12-15 years', 'Active, loyal, affectionate', 'High', True, 'High', 'Moderate', 'Similar to English Springers but with a distinctive red and white coat, Welsh Springers are devoted and energetic.'),
|
115 |
+
('Dog', 'West_Highland_White_Terrier', 'Small', '12-16 years', 'Friendly, hardy, confident', 'Moderate', True, 'Moderate', 'High', 'Commonly known as "Westies," these white terriers are friendly and sturdy with a bright personality.'),
|
116 |
+
('Dog', 'Yorkshire_Terrier', 'Small', '13-16 years', 'Affectionate, sprightly, tomboyish', 'High', False, 'Moderate', 'High', 'Popular toy breed known for their long silky coat and feisty personality. Despite their small size, they maintain a brave terrier spirit and were originally bred as ratters in Yorkshire mills.'),
|
117 |
+
('Dog', 'Affenpinscher', 'Small', '12-15 years', 'Confident, amusing, stubborn', 'Moderate', False, 'Moderate', 'Moderate', 'Small terrier-like toys known as "monkey dogs" due to their distinctive facial appearance.'),
|
118 |
+
('Dog', 'Basenji', 'Small', '12-16 years', 'Independent, smart, poised', 'Moderate', False, 'High', 'Low', 'Ancient African breed known for their inability to bark, instead making a unique yodel-like sound. Called "the barkless dog," they are intelligent hunters with cat-like cleanliness and independent nature.'),
|
119 |
+
('Dog', 'Basset', 'Medium', '10-12 years', 'Patient, low-key, charming', 'Moderate', True, 'Low', 'Moderate', 'Short-legged, long-bodied hounds known for their excellent sense of smell and gentle dispositions. Second only to Bloodhounds in scenting ability, these French-origin dogs combine persistence with a sweet, patient nature.'),
|
120 |
+
('Dog', 'Beagle', 'Small', '12-15 years', 'Merry, friendly, curious', 'Moderate', True, 'High', 'Low', 'Small hound dogs known for their excellent sense of smell and friendly, outgoing personalities. Popular family pets and skilled scent hunters, famous for their melodious bay and pack mentality.'),
|
121 |
+
('Dog', 'Black-and-Tan_Coonhound', 'Large', '10-12 years', 'Even-tempered, easygoing, friendly', 'Moderate', True, 'High', 'Low', 'Large, powerful scent hounds known for their distinctive black and tan coloration and melodious bay.'),
|
122 |
+
('Dog', 'Bloodhound', 'Large', '10-12 years', 'Gentle, patient, stubborn', 'High', True, 'Moderate', 'Moderate', 'Known for their exceptional sense of smell, Bloodhounds are large, gentle dogs often used in tracking.'),
|
123 |
+
('Dog', 'Bluetick', 'Large', '11-12 years', 'Friendly, intelligent, active', 'Moderate', True, 'High', 'Low', 'Known for their mottled blue coat, Bluetick Coonhounds are skilled hunting dogs with a keen sense of smell and a melodious howl.'),
|
124 |
+
('Dog', 'Borzoi', 'Large', '10-12 years', 'Quiet, gentle, athletic', 'High', True, 'Moderate', 'High', 'Also known as Russian Wolfhounds, Borzois are elegant sighthounds known for their silky coat and graceful demeanor.'),
|
125 |
+
('Dog', 'Boxer', 'Large', '10-12 years', 'Fun-loving, bright, active', 'Moderate', True, 'High', 'Low', 'Playful and energetic, Boxers are known for their patient and protective nature with children. Originally developed in Germany as working dogs, they combine strength with a uniquely playful and clownish personality.'),
|
126 |
+
('Dog', 'Briard', 'Large', '10-12 years', 'Confident, smart, loyal', 'High', True, 'High', 'High', 'Large French herding dogs with a distinctive long, wavy coat, Briards are loyal and protective. Known as "hearts wrapped in fur," they served as WWI sentries and now excel as both working dogs and devoted family guardians.'),
|
127 |
+
('Dog', 'Bull_mastiff', 'Large', '8-10 years', 'Affectionate, loyal, quiet', 'Moderate', True, 'Moderate', 'Low', 'Large, powerful dogs originally bred to guard estates, Bullmastiffs are gentle giants with a calm demeanor.'),
|
128 |
+
('Dog', 'Cairn', 'Small', '13-15 years', 'Alert, cheerful, busy', 'Moderate', True, 'Moderate', 'Moderate', 'Small, rugged terriers known for their shaggy coat and lively personality. Originally bred to hunt in the Scottish Highlands, these hardy dogs are intelligent and make excellent watchdogs despite their small size.'),
|
129 |
+
('Dog', 'Chow', 'Medium', '8-12 years', 'Aloof, loyal, quiet', 'High', False, 'Low', 'High', 'Ancient Chinese breed known for their lion-like mane and blue-black tongues. Independent and dignified, they make excellent watchdogs but require early socialization.'),
|
130 |
+
('Dog', 'Clumber', 'Large', '10-12 years', 'Gentle, loyal, thoughtful', 'Moderate', True, 'Moderate', 'High', 'The largest of the spaniels, Clumbers are known for their distinctive white coat and calm demeanor. Developed in France and England, these dignified hunters combine power with a methodical hunting style and gentle nature.'),
|
131 |
+
('Dog', 'Cocker_Spaniel', 'Small', '10-14 years', 'Gentle, smart, happy', 'High', True, 'Moderate', 'High', 'Known for their long, silky ears and expressive eyes, Cockers are popular family dogs with a merry disposition.'),
|
132 |
+
('Dog', 'Collie', 'Large', '10-14 years', 'Devoted, graceful, proud', 'High', True, 'High', 'High', 'Made famous by "Lassie," Collies are intelligent herding dogs known for their loyalty and grace. Their remarkable intuition and gentle nature make them exceptional family guardians, especially with children.'),
|
133 |
+
('Dog', 'Curly-Coated_Retriever', 'Large', '10-12 years', 'Confident, independent, intelligent', 'Moderate', True, 'High', 'Low', 'Sporting dogs with a distinctive curly coat, known for their excellent swimming and retrieving abilities.'),
|
134 |
+
('Dog', 'Dhole', 'Medium', '10-13 years', 'Social, intelligent, athletic', 'High', False, 'High', 'Low', 'Also known as the Asiatic wild dog, Dholes are not typically kept as pets but are important in Asian ecosystems.'),
|
135 |
+
('Dog', 'Dingo', 'Medium', '10-13 years', 'Independent, intelligent, alert', 'High', False, 'High', 'Low', 'Native wild dogs of Australia, dingoes are not typically kept as pets and are important to the Australian ecosystem.'),
|
136 |
+
('Dog', 'Flat-Coated_Retriever', 'Large', '8-10 years', 'Optimistic, good-humored, outgoing', 'High', True, 'Very High', 'Moderate', 'Known for their shiny black or liver-colored coat, Flat-coated Retrievers are energetic and playful, excelling in both hunting and family life.'),
|
137 |
+
('Dog', 'Giant_Schnauzer', 'Large', '10-12 years', 'Loyal, intelligent, powerful', 'High', True, 'High', 'High', 'Large and powerful, Giant Schnauzers were originally bred as working dogs and require plenty of exercise.'),
|
138 |
+
('Dog', 'Golden_Retriever', 'Large', '10-12 years', 'Intelligent, friendly, devoted', 'High', True, 'High', 'High', 'Beautiful, golden-coated dogs known for their gentle nature and excellence in various roles. Popular as family companions, therapy dogs, and service animals, they excel in both work and companionship with their eager-to-please attitude.'),
|
139 |
+
('Dog', 'Groenendael', 'Large', '10-12 years', 'Intelligent, protective, loyal', 'High', True, 'High', 'High', 'The black variety of Belgian Shepherd, Groenendaels are intelligent working dogs with a long, black coat. Named after their village of origin, they excel in police work, herding, and as vigilant family guardians.'),
|
140 |
+
('Dog', 'Keeshond', 'Medium', '12-15 years', 'Friendly, lively, outgoing', 'Moderate', True, 'Moderate', 'High', 'Distinctive "spectacles" marking around their eyes, Keeshonds are fluffy, fox-like dogs known for their friendly and affectionate nature.'),
|
141 |
+
('Dog', 'Kelpie', 'Medium', '10-13 years', 'Intelligent, energetic, loyal', 'High', True, 'Very High', 'Low', 'Australian herding dogs known for their incredible work ethic and agility. Developed to work in harsh outback conditions, they are renowned for their ability to herd from above, often running across the backs of sheep in large flocks.'),
|
142 |
+
('Dog', 'Komondor', 'Large', '10-12 years', 'Steady, fearless, affectionate', 'High', True, 'Moderate', 'High', 'Large Hungarian sheepdogs known for their distinctive corded white coat, resembling dreadlocks. Their unique coat once helped them blend in with sheep flocks while protecting them from wolves.'),
|
143 |
+
('Dog', 'Kuvasz', 'Large', '10-12 years', 'Protective, loyal, patient', 'High', True, 'Moderate', 'High', 'Large, white guardian dogs from Hungary, Kuvaszok are protective of their families and independent. Once royal guards of Hungarian nobility, they combine impressive strength with natural protective instincts.'),
|
144 |
+
('Dog', 'Malamute', 'Large', '10-12 years', 'Affectionate, loyal, playful', 'High', True, 'Very High', 'High', 'Large, powerful sled dogs with thick coats, known for their strength and endurance. Originally bred by the Mahlemut tribe for hauling heavy loads in arctic conditions, they combine impressive power with a friendly, family-oriented nature.'),
|
145 |
+
('Dog', 'Malinois', 'Medium', '12-14 years', 'Confident, smart, hardworking', 'High', True, 'High', 'Moderate', 'One of four varieties of Belgian Shepherd, known for their intelligence and use in police and military work.'),
|
146 |
+
('Dog', 'Miniature_Pinscher', 'Small', '12-16 years', 'Fearless, energetic, alert', 'Moderate', False, 'Moderate', 'Low', 'Often called King of Toys, Miniature Pinschers are small, energetic dogs with a big personality. Despite their small size, these fearless dogs possess proud carriage and spirited animation.'),
|
147 |
+
('Dog', 'Miniature_Poodle', 'Small', '12-15 years', 'Intelligent, active, alert', 'High', True, 'Moderate', 'High', 'Smaller version of the Standard Poodle, known for their intelligence and hypoallergenic coat. Popular show dogs and companions, they retain their larger relatives high intelligence while being more adaptable to city living.'),
|
148 |
+
('Dog', 'Miniature_Schnauzer', 'Small', '12-15 years', 'Friendly, smart, obedient', 'Moderate', True, 'Moderate', 'High', 'The smallest of the Schnauzer breeds, known for their distinctive beard and eyebrows. Originally ratters and farm dogs, they combine intelligence with a spunky personality, making excellent watchdogs and family companions.'),
|
149 |
+
('Dog', 'Otterhound', 'Large', '10-13 years', 'Friendly, boisterous, even-tempered', 'High', True, 'High', 'High', 'Large, shaggy-coated hounds originally bred for hunting otters, now a rare breed. Known for their strong swimming ability and powerful nose, with less than 1000 remaining worldwide, making them rarer than giant pandas.'),
|
150 |
+
('Dog', 'Papillon', 'Small', '13-15 years', 'Happy, alert, friendly', 'Moderate', True, 'Moderate', 'Moderate', 'Small, elegant dogs known for their butterfly-like ears and lively personalities. Despite their delicate appearance, they are surprisingly athletic and intelligent, ranking among the top 10 smartest dog breeds. Also called the Continental Toy Spaniel.'),
|
151 |
+
('Dog', 'Pug', 'Small', '12-15 years', 'Charming, mischievous, loving', 'Moderate', True, 'Low', 'Moderate', 'Small, wrinkly-faced dogs known for their charming personality and comical expression. Once favored by Chinese emperors, these "multum in parvo" (much in little) dogs are excellent companions but need attention to their breathing and temperature regulation.'),
|
152 |
+
('Dog', 'Redbone', 'Large', '10-12 years', 'Even-tempered, amiable, eager to please', 'Moderate', True, 'High', 'Low', 'Known for their solid red coat, Redbone Coonhounds are athletic, warm-hearted dogs originally bred for hunting. Developed in the American South, they excel at tracking and treeing with remarkable stamina and a melodious voice.'),
|
153 |
+
('Dog', 'Schipperke', 'Small', '13-15 years', 'Confident, alert, curious', 'Moderate', True, 'Moderate', 'Moderate', 'Small, black dogs with a fox-like face, Schipperkes are known for their distinctive ruff and small, pointed ears. Originally Belgian barge dogs, these little captains earned their name as boat watchdogs and ratters.'),
|
154 |
+
('Dog', 'Silky_terrier', 'Small', '12-15 years', 'Friendly, quick, alert', 'Moderate', False, 'Moderate', 'High', 'Similar to Yorkshire Terriers but larger, Silky Terriers are playful and enjoy being part of family activities. Developed in Australia, they combine the refinement of toy dogs with the sturdy nature of working terriers.'),
|
155 |
+
('Dog', 'Soft-Coated_Wheaten_Terrier', 'Medium', '12-14 years', 'Happy, steady, self-confident', 'High', True, 'High', 'High', 'Known for their soft, wheat-colored coat and friendly demeanor, they make great family dogs. Developed in Ireland as farm dogs, they combined versatility in herding and hunting with a uniquely soft coat unlike other terriers.'),
|
156 |
+
('Dog', 'Standard_Poodle', 'Large', '10-18 years', 'Intelligent, active, dignified', 'High', True, 'High', 'High', 'Highly intelligent and elegant dogs, known for their hypoallergenic coat and versatility in various dog sports.'),
|
157 |
+
('Dog', 'Standard_Schnauzer', 'Medium', '13-16 years', 'Friendly, intelligent, obedient', 'High', True, 'High', 'High', 'The original Schnauzer breed, known for their distinctive beard and eyebrows and versatile working abilities.'),
|
158 |
+
('Dog', 'Toy_Poodle', 'Small', '12-18 years', 'Intelligent, lively, playful', 'High', True, 'Moderate', 'High', 'The smallest variety of Poodle, known for their intelligence, agility, and hypoallergenic coat. Despite their diminutive size, they retain the intelligence and athletic ability of their larger relatives.'),
|
159 |
+
('Dog', 'Toy_Terrier', 'Small', '12-16 years', 'Lively, bold, intelligent', 'Moderate', False, 'Moderate', 'Low', 'A general term for small terrier breeds, often referring to breeds like the English Toy Terrier or Toy Fox Terrier.'),
|
160 |
+
('Dog', 'Vizsla', 'Medium', '10-14 years', 'Affectionate, energetic, gentle', 'High', True, 'High', 'Low', 'Known for their golden-rust coat, Vizslas are versatile hunters and loving family companions. These Hungarian pointers are often called "velcro dogs" for their strong desire to stay close to their owners.'),
|
161 |
+
('Dog', 'Whippet', 'Medium', '12-15 years', 'Gentle, affectionate, quiet', 'Low', True, 'High', 'Low', 'Slender, athletic sighthounds known for their speed - capable of reaching 35mph. Despite high exercise needs, they are calm indoor companions and excellent apartment dogs.'),
|
162 |
+
('Dog', 'Wire-Haired_Fox_Terrier', 'Small', '12-15 years', 'Alert, confident, gregarious', 'High', True, 'High', 'High', 'Energetic and wire-coated, these terriers were originally bred for fox hunting. Their tough, dense coat and fearless nature made them ideal for flushing foxes from their dens, and they remain bold and spirited companions.'),
|
163 |
+
]
|
164 |
+
|
165 |
+
cursor.executemany('''
|
166 |
+
INSERT INTO AnimalCatalog (Species, Breed, Size_Category, Typical_Lifespan, Temperament, Care_Level, Good_With_Children, Exercise_Needs, Grooming_Needs, Brief_Description)
|
167 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
168 |
+
''', dog_data)
|
169 |
+
|
170 |
+
conn.commit()
|
171 |
+
cursor.close()
|
172 |
+
conn.close()
|
173 |
+
|
174 |
+
def get_dog_description(breed):
|
175 |
+
try:
|
176 |
+
conn = sqlite3.connect('animal_detector.db')
|
177 |
+
cursor = conn.cursor()
|
178 |
+
|
179 |
+
breed_name = breed.split('(')[0].strip()
|
180 |
+
|
181 |
+
cursor.execute("""
|
182 |
+
SELECT * FROM AnimalCatalog
|
183 |
+
WHERE Breed = ? OR Breed LIKE ? OR Breed LIKE ?
|
184 |
+
""", (breed_name, f"{breed_name}%", f"%{breed_name}"))
|
185 |
+
|
186 |
+
result = cursor.fetchone()
|
187 |
+
|
188 |
+
cursor.close()
|
189 |
+
conn.close()
|
190 |
+
|
191 |
+
if result:
|
192 |
+
# 標準化運動需求值
|
193 |
+
exercise_needs = result[8]
|
194 |
+
normalized_exercise = exercise_needs.strip().title()
|
195 |
+
if normalized_exercise not in ["Very High", "High", "Moderate", "Low"]:
|
196 |
+
normalized_exercise = "High" # 預設值
|
197 |
+
|
198 |
+
description = {
|
199 |
+
"Breed": result[2],
|
200 |
+
"Size": result[3],
|
201 |
+
"Lifespan": result[4],
|
202 |
+
"Temperament": result[5],
|
203 |
+
"Care Level": result[6],
|
204 |
+
"Good with Children": "Yes" if result[7] else "No",
|
205 |
+
"Exercise Needs": normalized_exercise,
|
206 |
+
"Grooming Needs": result[9],
|
207 |
+
"Description": result[10]
|
208 |
+
}
|
209 |
+
return description
|
210 |
+
else:
|
211 |
+
print(f"No data found for breed: {breed_name}")
|
212 |
+
return None
|
213 |
+
|
214 |
+
except Exception as e:
|
215 |
+
print(f"Error in get_dog_description: {str(e)}")
|
216 |
+
return None
|
217 |
+
|
218 |
+
insert_dog_data()
|
html_templates.py
ADDED
@@ -0,0 +1,600 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from typing import Dict, List, Union, Any, Optional, Callable
|
3 |
+
from urllib.parse import quote
|
4 |
+
|
5 |
+
def get_akc_breeds_link(breed: str) -> str:
|
6 |
+
"""Generate AKC breed page URL with intelligent name handling."""
|
7 |
+
breed_name = breed.lower()
|
8 |
+
breed_name = breed_name.replace('_', '-')
|
9 |
+
breed_name = breed_name.replace("'", '')
|
10 |
+
breed_name = breed_name.replace(" ", '-')
|
11 |
+
|
12 |
+
special_cases = {
|
13 |
+
'mexican-hairless': 'xoloitzcuintli',
|
14 |
+
'brabancon-griffon': 'brussels-griffon',
|
15 |
+
'bull-mastiff': 'bullmastiff',
|
16 |
+
'walker-hound': 'treeing-walker-coonhound'
|
17 |
+
}
|
18 |
+
|
19 |
+
breed_name = special_cases.get(breed_name, breed_name)
|
20 |
+
return f"https://www.akc.org/dog-breeds/{breed_name}/"
|
21 |
+
|
22 |
+
def get_color_scheme(is_single_dog: bool) -> Union[str, List[str]]:
|
23 |
+
"""Get color scheme for dog detection visualization."""
|
24 |
+
single_dog_color = '#34C759' # 清爽的綠色作為單狗顏色
|
25 |
+
color_list = [
|
26 |
+
'#FF5733', # 珊瑚紅
|
27 |
+
'#28A745', # 深綠色
|
28 |
+
'#3357FF', # 寶藍色
|
29 |
+
'#FF33F5', # 粉紫色
|
30 |
+
'#FFB733', # 橙黃色
|
31 |
+
'#33FFF5', # 青藍色
|
32 |
+
'#A233FF', # 紫色
|
33 |
+
'#FF3333', # 紅色
|
34 |
+
'#33FFB7', # 青綠色
|
35 |
+
'#FFE033' # 金黃色
|
36 |
+
]
|
37 |
+
return single_dog_color if is_single_dog else color_list
|
38 |
+
|
39 |
+
def format_warning_html(message: str) -> str:
|
40 |
+
"""Format warning messages in a consistent style."""
|
41 |
+
return f'''
|
42 |
+
<div class="dog-info-card">
|
43 |
+
<div class="breed-info">
|
44 |
+
<p class="warning-message">
|
45 |
+
<span class="icon">⚠️</span>
|
46 |
+
{message}
|
47 |
+
</p>
|
48 |
+
</div>
|
49 |
+
</div>
|
50 |
+
'''
|
51 |
+
|
52 |
+
|
53 |
+
def format_error_message(color: str, index: int) -> str:
|
54 |
+
"""Format error message when confidence is too low."""
|
55 |
+
return f'''
|
56 |
+
<div class="dog-info-card" style="border-left: 8px solid {color};">
|
57 |
+
<div class="dog-info-header" style="background-color: {color}10;">
|
58 |
+
<span class="dog-label" style="color: {color};">Dog {index}</span>
|
59 |
+
</div>
|
60 |
+
<div class="breed-info">
|
61 |
+
<div class="warning-message">
|
62 |
+
<span class="icon">⚠️</span>
|
63 |
+
The image is unclear or the breed is not in the dataset. Please upload a clearer image.
|
64 |
+
</div>
|
65 |
+
</div>
|
66 |
+
</div>
|
67 |
+
'''
|
68 |
+
|
69 |
+
def format_description_html(description: Dict[str, Any], breed: str) -> str:
|
70 |
+
"""Format basic breed description with tooltips."""
|
71 |
+
if not isinstance(description, dict):
|
72 |
+
return f"<p>{description}</p>"
|
73 |
+
|
74 |
+
fields_order = [
|
75 |
+
"Size", "Lifespan", "Temperament", "Exercise Needs",
|
76 |
+
"Grooming Needs", "Care Level", "Good with Children",
|
77 |
+
"Description"
|
78 |
+
]
|
79 |
+
|
80 |
+
html_parts = []
|
81 |
+
for field in fields_order:
|
82 |
+
if field in description:
|
83 |
+
value = description[field]
|
84 |
+
tooltip_html = format_tooltip(field, value)
|
85 |
+
html_parts.append(f'<li style="margin-bottom: 10px;">{tooltip_html}</li>')
|
86 |
+
|
87 |
+
# Add any remaining fields
|
88 |
+
for key, value in description.items():
|
89 |
+
if key not in fields_order and key != "Breed":
|
90 |
+
html_parts.append(f'<li style="margin-bottom: 10px;"><strong>{key}:</strong> {value}</li>')
|
91 |
+
|
92 |
+
return f'<ul style="list-style-type: none; padding-left: 0;">{" ".join(html_parts)}</ul>'
|
93 |
+
|
94 |
+
|
95 |
+
def format_tooltip(key: str, value: str) -> str:
|
96 |
+
"""Format tooltip with content for each field."""
|
97 |
+
tooltip_contents = {
|
98 |
+
"Size": {
|
99 |
+
"title": "Size Categories",
|
100 |
+
"items": [
|
101 |
+
"Small: Under 20 pounds",
|
102 |
+
"Medium: 20-60 pounds",
|
103 |
+
"Large: Over 60 pounds",
|
104 |
+
"Giant: Over 100 pounds",
|
105 |
+
"Varies: Depends on variety"
|
106 |
+
]
|
107 |
+
},
|
108 |
+
"Exercise Needs": {
|
109 |
+
"title": "Exercise Needs",
|
110 |
+
"items": [
|
111 |
+
"Low: Short walks and play sessions",
|
112 |
+
"Moderate: 1-2 hours of daily activity",
|
113 |
+
"High: Extensive exercise (2+ hours/day)",
|
114 |
+
"Very High: Constant activity and mental stimulation needed"
|
115 |
+
]
|
116 |
+
},
|
117 |
+
"Grooming Needs": {
|
118 |
+
"title": "Grooming Requirements",
|
119 |
+
"items": [
|
120 |
+
"Low: Basic brushing, occasional baths",
|
121 |
+
"Moderate: Weekly brushing, occasional grooming",
|
122 |
+
"High: Daily brushing, frequent professional grooming needed",
|
123 |
+
"Professional care recommended for all levels"
|
124 |
+
]
|
125 |
+
},
|
126 |
+
"Care Level": {
|
127 |
+
"title": "Care Level Explained",
|
128 |
+
"items": [
|
129 |
+
"Low: Basic care and attention needed",
|
130 |
+
"Moderate: Regular care and routine needed",
|
131 |
+
"High: Significant time and attention needed",
|
132 |
+
"Very High: Extensive care, training and attention required"
|
133 |
+
]
|
134 |
+
},
|
135 |
+
"Good with Children": {
|
136 |
+
"title": "Child Compatibility",
|
137 |
+
"items": [
|
138 |
+
"Yes: Excellent with kids, patient and gentle",
|
139 |
+
"Moderate: Good with older children",
|
140 |
+
"No: Better suited for adult households"
|
141 |
+
]
|
142 |
+
},
|
143 |
+
"Lifespan": {
|
144 |
+
"title": "Average Lifespan",
|
145 |
+
"items": [
|
146 |
+
"Short: 6-8 years",
|
147 |
+
"Average: 10-15 years",
|
148 |
+
"Long: 12-20 years",
|
149 |
+
"Varies by size: Larger breeds typically have shorter lifespans"
|
150 |
+
]
|
151 |
+
},
|
152 |
+
"Temperament": {
|
153 |
+
"title": "Temperament Guide",
|
154 |
+
"items": [
|
155 |
+
"Describes the dog's natural behavior and personality",
|
156 |
+
"Important for matching with owner's lifestyle",
|
157 |
+
"Can be influenced by training and socialization"
|
158 |
+
]
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
tooltip = tooltip_contents.get(key, {"title": key, "items": []})
|
163 |
+
tooltip_content = "<br>".join([f"• {item}" for item in tooltip["items"]])
|
164 |
+
|
165 |
+
return f'''
|
166 |
+
<span class="tooltip">
|
167 |
+
<strong>{key}:</strong>
|
168 |
+
<span class="tooltip-icon">ⓘ</span>
|
169 |
+
<span class="tooltip-text">
|
170 |
+
<strong>{tooltip["title"]}:</strong><br>
|
171 |
+
{tooltip_content}
|
172 |
+
</span>
|
173 |
+
</span> {value}
|
174 |
+
'''
|
175 |
+
|
176 |
+
def format_single_dog_result(breed: str, description: Dict[str, Any], color: str = "#34C759") -> str:
|
177 |
+
"""Format single dog detection result into HTML."""
|
178 |
+
return f'''
|
179 |
+
<div class="dog-info-card" style="border-left: 8px solid {color};">
|
180 |
+
<div class="dog-info-header" style="background-color: {color}10;">
|
181 |
+
<span class="dog-label" style="color: {color};">
|
182 |
+
<span class="icon">🐾</span> {breed}
|
183 |
+
</span>
|
184 |
+
</div>
|
185 |
+
<div class="breed-info">
|
186 |
+
<h2 class="section-title">
|
187 |
+
<span class="icon">📋</span> BASIC INFORMATION
|
188 |
+
</h2>
|
189 |
+
<div class="info-section">
|
190 |
+
<div class="info-item">
|
191 |
+
<span class="tooltip tooltip-left">
|
192 |
+
<span class="icon">📏</span>
|
193 |
+
<span class="label">Size:</span>
|
194 |
+
<span class="tooltip-icon">ⓘ</span>
|
195 |
+
<span class="tooltip-text">
|
196 |
+
<strong>Size Categories:</strong><br>
|
197 |
+
• Small: Under 20 pounds<br>
|
198 |
+
• Medium: 20-60 pounds<br>
|
199 |
+
• Large: Over 60 pounds<br>
|
200 |
+
• Giant: Over 100 pounds<br>
|
201 |
+
• Varies: Depends on variety
|
202 |
+
</span>
|
203 |
+
</span>
|
204 |
+
<span class="value">{description['Size']}</span>
|
205 |
+
</div>
|
206 |
+
<div class="info-item">
|
207 |
+
<span class="tooltip">
|
208 |
+
<span class="icon">⏳</span>
|
209 |
+
<span class="label">Lifespan:</span>
|
210 |
+
<span class="tooltip-icon">ⓘ</span>
|
211 |
+
<span class="tooltip-text">
|
212 |
+
<strong>Average Lifespan:</strong><br>
|
213 |
+
• Short: 6-8 years<br>
|
214 |
+
• Average: 10-15 years<br>
|
215 |
+
• Long: 12-20 years<br>
|
216 |
+
• Varies by size: Larger breeds typically have shorter lifespans
|
217 |
+
</span>
|
218 |
+
</span>
|
219 |
+
<span class="value">{description['Lifespan']}</span>
|
220 |
+
</div>
|
221 |
+
</div>
|
222 |
+
<h2 class="section-title">
|
223 |
+
<span class="icon">🐕</span> TEMPERAMENT & PERSONALITY
|
224 |
+
</h2>
|
225 |
+
<div class="temperament-section">
|
226 |
+
<span class="tooltip">
|
227 |
+
<span class="value">{description['Temperament']}</span>
|
228 |
+
<span class="tooltip-icon">ⓘ</span>
|
229 |
+
<span class="tooltip-text">
|
230 |
+
<strong>Temperament Guide:</strong><br>
|
231 |
+
• Describes the dog's natural behavior and personality<br>
|
232 |
+
• Important for matching with owner's lifestyle<br>
|
233 |
+
• Can be influenced by training and socialization
|
234 |
+
</span>
|
235 |
+
</span>
|
236 |
+
</div>
|
237 |
+
<h2 class="section-title">
|
238 |
+
<span class="icon">💪</span> CARE REQUIREMENTS
|
239 |
+
</h2>
|
240 |
+
<div class="care-section">
|
241 |
+
<div class="info-item">
|
242 |
+
<span class="tooltip tooltip-left">
|
243 |
+
<span class="icon">🏃</span>
|
244 |
+
<span class="label">Exercise:</span>
|
245 |
+
<span class="tooltip-icon">ⓘ</span>
|
246 |
+
<span class="tooltip-text">
|
247 |
+
<strong>Exercise Needs:</strong><br>
|
248 |
+
• Low: Short walks and play sessions<br>
|
249 |
+
• Moderate: 1-2 hours of daily activity<br>
|
250 |
+
• High: Extensive exercise (2+ hours/day)<br>
|
251 |
+
• Very High: Constant activity and mental stimulation needed
|
252 |
+
</span>
|
253 |
+
</span>
|
254 |
+
<span class="value">{description['Exercise Needs']}</span>
|
255 |
+
</div>
|
256 |
+
<div class="info-item">
|
257 |
+
<span class="tooltip">
|
258 |
+
<span class="icon">✂️</span>
|
259 |
+
<span class="label">Grooming:</span>
|
260 |
+
<span class="tooltip-icon">ⓘ</span>
|
261 |
+
<span class="tooltip-text">
|
262 |
+
<strong>Grooming Requirements:</strong><br>
|
263 |
+
• Low: Basic brushing, occasional baths<br>
|
264 |
+
• Moderate: Weekly brushing, occasional grooming<br>
|
265 |
+
• High: Daily brushing, frequent professional grooming needed<br>
|
266 |
+
• Professional care recommended for all levels
|
267 |
+
</span>
|
268 |
+
</span>
|
269 |
+
<span class="value">{description['Grooming Needs']}</span>
|
270 |
+
</div>
|
271 |
+
<div class="info-item">
|
272 |
+
<span class="tooltip">
|
273 |
+
<span class="icon">⭐</span>
|
274 |
+
<span class="label">Care Level:</span>
|
275 |
+
<span class="tooltip-icon">ⓘ</span>
|
276 |
+
<span class="tooltip-text">
|
277 |
+
<strong>Care Level Explained:</strong><br>
|
278 |
+
• Low: Basic care and attention needed<br>
|
279 |
+
• Moderate: Regular care and routine needed<br>
|
280 |
+
• High: Significant time and attention needed<br>
|
281 |
+
• Very High: Extensive care, training and attention required
|
282 |
+
</span>
|
283 |
+
</span>
|
284 |
+
<span class="value">{description['Care Level']}</span>
|
285 |
+
</div>
|
286 |
+
</div>
|
287 |
+
<h2 class="section-title">
|
288 |
+
<span class="icon">👨👩👧👦</span> FAMILY COMPATIBILITY
|
289 |
+
</h2>
|
290 |
+
<div class="family-section">
|
291 |
+
<div class="info-item">
|
292 |
+
<span class="tooltip">
|
293 |
+
<span class="icon"></span>
|
294 |
+
<span class="label">Good with Children:</span>
|
295 |
+
<span class="tooltip-icon">ⓘ</span>
|
296 |
+
<span class="tooltip-text">
|
297 |
+
<strong>Child Compatibility:</strong><br>
|
298 |
+
• Yes: Excellent with kids, patient and gentle<br>
|
299 |
+
• Moderate: Good with older children<br>
|
300 |
+
• No: Better suited for adult households
|
301 |
+
</span>
|
302 |
+
</span>
|
303 |
+
<span class="value">{description['Good with Children']}</span>
|
304 |
+
</div>
|
305 |
+
</div>
|
306 |
+
<h2 class="section-title">
|
307 |
+
<span class="icon">📝</span>
|
308 |
+
<span class="tooltip">
|
309 |
+
DESCRIPTION
|
310 |
+
<span class="tooltip-icon">ⓘ</span>
|
311 |
+
<span class="tooltip-text">
|
312 |
+
<strong>About This Description:</strong><br>
|
313 |
+
• Comprehensive breed overview<br>
|
314 |
+
• Personality and characteristics<br>
|
315 |
+
• Historical background<br>
|
316 |
+
• Typical behaviors and traits
|
317 |
+
</span>
|
318 |
+
</span>
|
319 |
+
</h2>
|
320 |
+
<div class="description-section">
|
321 |
+
<p>{description.get('Description', '')}</p>
|
322 |
+
</div>
|
323 |
+
<div class="action-section">
|
324 |
+
<a href="{get_akc_breeds_link(breed)}" target="_blank" class="akc-button">
|
325 |
+
<span class="icon">🌐</span>
|
326 |
+
Learn more about {breed} on AKC website
|
327 |
+
</a>
|
328 |
+
</div>
|
329 |
+
</div>
|
330 |
+
</div>
|
331 |
+
'''
|
332 |
+
|
333 |
+
def format_multiple_breeds_result(
|
334 |
+
topk_breeds: List[str],
|
335 |
+
relative_probs: List[str],
|
336 |
+
color: str,
|
337 |
+
index: int,
|
338 |
+
get_dog_description: Callable
|
339 |
+
) -> str:
|
340 |
+
"""Format multiple breed predictions into HTML with complete information."""
|
341 |
+
result = f'''
|
342 |
+
<div class="dog-info-card" style="border-left: 8px solid {color};">
|
343 |
+
<div class="dog-info-header" style="background-color: {color}10;">
|
344 |
+
<span class="dog-label" style="color: {color};">Dog {index+1}</span>
|
345 |
+
</div>
|
346 |
+
<div class="breed-info">
|
347 |
+
<div class="model-uncertainty-note">
|
348 |
+
<span class="icon">ℹ️</span>
|
349 |
+
Note: The model is showing some uncertainty in its predictions.
|
350 |
+
Here are the most likely breeds based on the available visual features.
|
351 |
+
</div>
|
352 |
+
<div class="breeds-list">
|
353 |
+
'''
|
354 |
+
|
355 |
+
for j, (breed, prob) in enumerate(zip(topk_breeds, relative_probs)):
|
356 |
+
description = get_dog_description(breed)
|
357 |
+
result += f'''
|
358 |
+
<div class="breed-option uncertainty-mode">
|
359 |
+
<div class="breed-header" style="background-color: {color}10;">
|
360 |
+
<span class="option-number">Option {j+1}</span>
|
361 |
+
<span class="breed-name">{breed}</span>
|
362 |
+
<span class="confidence-badge" style="background-color: {color}20; color: {color};">
|
363 |
+
Confidence: {prob}
|
364 |
+
</span>
|
365 |
+
</div>
|
366 |
+
<div class="breed-content">
|
367 |
+
<div class="breed-info">
|
368 |
+
<!-- BASIC INFORMATION -->
|
369 |
+
<h2 class="section-title">
|
370 |
+
<span class="icon">📋</span> BASIC INFORMATION
|
371 |
+
</h2>
|
372 |
+
<div class="info-section">
|
373 |
+
<div class="info-item">
|
374 |
+
<span class="tooltip tooltip-left">
|
375 |
+
<span class="icon">📏</span>
|
376 |
+
<span class="label">Size:</span>
|
377 |
+
<span class="tooltip-icon">ⓘ</span>
|
378 |
+
<span class="tooltip-text">
|
379 |
+
<strong>Size Categories:</strong><br>
|
380 |
+
• Small: Under 20 pounds<br>
|
381 |
+
• Medium: 20-60 pounds<br>
|
382 |
+
• Large: Over 60 pounds<br>
|
383 |
+
• Giant: Over 100 pounds<br>
|
384 |
+
• Varies: Depends on variety
|
385 |
+
</span>
|
386 |
+
</span>
|
387 |
+
<span class="value">{description['Size']}</span>
|
388 |
+
</div>
|
389 |
+
<div class="info-item">
|
390 |
+
<span class="tooltip">
|
391 |
+
<span class="icon">⏳</span>
|
392 |
+
<span class="label">Lifespan:</span>
|
393 |
+
<span class="tooltip-icon">ⓘ</span>
|
394 |
+
<span class="tooltip-text">
|
395 |
+
<strong>Average Lifespan:</strong><br>
|
396 |
+
• Short: 6-8 years<br>
|
397 |
+
• Average: 10-15 years<br>
|
398 |
+
• Long: 12-20 years<br>
|
399 |
+
• Varies by size: Larger breeds typically have shorter lifespans
|
400 |
+
</span>
|
401 |
+
</span>
|
402 |
+
<span class="value">{description['Lifespan']}</span>
|
403 |
+
</div>
|
404 |
+
</div>
|
405 |
+
<!-- TEMPERAMENT & PERSONALITY -->
|
406 |
+
<h2 class="section-title">
|
407 |
+
<span class="icon">🐕</span> TEMPERAMENT & PERSONALITY
|
408 |
+
</h2>
|
409 |
+
<div class="temperament-section">
|
410 |
+
<span class="tooltip">
|
411 |
+
<span class="value">{description['Temperament']}</span>
|
412 |
+
<span class="tooltip-icon">ⓘ</span>
|
413 |
+
<span class="tooltip-text">
|
414 |
+
<strong>Temperament Guide:</strong><br>
|
415 |
+
• Describes the dog's natural behavior and personality<br>
|
416 |
+
• Important for matching with owner's lifestyle<br>
|
417 |
+
• Can be influenced by training and socialization
|
418 |
+
</span>
|
419 |
+
</span>
|
420 |
+
</div>
|
421 |
+
<!-- CARE REQUIREMENTS -->
|
422 |
+
<h2 class="section-title">
|
423 |
+
<span class="icon">💪</span> CARE REQUIREMENTS
|
424 |
+
</h2>
|
425 |
+
<div class="care-section">
|
426 |
+
<div class="info-item">
|
427 |
+
<span class="tooltip tooltip-left">
|
428 |
+
<span class="icon">🏃</span>
|
429 |
+
<span class="label">Exercise:</span>
|
430 |
+
<span class="tooltip-icon">ⓘ</span>
|
431 |
+
<span class="tooltip-text">
|
432 |
+
<strong>Exercise Needs:</strong><br>
|
433 |
+
• Low: Short walks and play sessions<br>
|
434 |
+
• Moderate: 1-2 hours of daily activity<br>
|
435 |
+
• High: Extensive exercise (2+ hours/day)<br>
|
436 |
+
• Very High: Constant activity and mental stimulation needed
|
437 |
+
</span>
|
438 |
+
</span>
|
439 |
+
<span class="value">{description['Exercise Needs']}</span>
|
440 |
+
</div>
|
441 |
+
<div class="info-item">
|
442 |
+
<span class="tooltip">
|
443 |
+
<span class="icon">✂️</span>
|
444 |
+
<span class="label">Grooming:</span>
|
445 |
+
<span class="tooltip-icon">ⓘ</span>
|
446 |
+
<span class="tooltip-text">
|
447 |
+
<strong>Grooming Requirements:</strong><br>
|
448 |
+
• Low: Basic brushing, occasional baths<br>
|
449 |
+
• Moderate: Weekly brushing, occasional grooming<br>
|
450 |
+
• High: Daily brushing, frequent professional grooming needed<br>
|
451 |
+
• Professional care recommended for all levels
|
452 |
+
</span>
|
453 |
+
</span>
|
454 |
+
<span class="value">{description['Grooming Needs']}</span>
|
455 |
+
</div>
|
456 |
+
<div class="info-item">
|
457 |
+
<span class="tooltip">
|
458 |
+
<span class="icon">⭐</span>
|
459 |
+
<span class="label">Care Level:</span>
|
460 |
+
<span class="tooltip-icon">ⓘ</span>
|
461 |
+
<span class="tooltip-text">
|
462 |
+
<strong>Care Level Explained:</strong><br>
|
463 |
+
• Low: Basic care and attention needed<br>
|
464 |
+
• Moderate: Regular care and routine needed<br>
|
465 |
+
• High: Significant time and attention needed<br>
|
466 |
+
• Very High: Extensive care, training and attention required
|
467 |
+
</span>
|
468 |
+
</span>
|
469 |
+
<span class="value">{description['Care Level']}</span>
|
470 |
+
</div>
|
471 |
+
</div>
|
472 |
+
<!-- FAMILY COMPATIBILITY -->
|
473 |
+
<h2 class="section-title">
|
474 |
+
<span class="icon">👨👩👧👦</span> FAMILY COMPATIBILITY
|
475 |
+
</h2>
|
476 |
+
<div class="family-section">
|
477 |
+
<div class="info-item">
|
478 |
+
<span class="tooltip">
|
479 |
+
<span class="icon"></span>
|
480 |
+
<span class="label">Good with Children:</span>
|
481 |
+
<span class="tooltip-icon">ⓘ</span>
|
482 |
+
<span class="tooltip-text">
|
483 |
+
<strong>Child Compatibility:</strong><br>
|
484 |
+
• Yes: Excellent with kids, patient and gentle<br>
|
485 |
+
• Moderate: Good with older children<br>
|
486 |
+
• No: Better suited for adult households
|
487 |
+
</span>
|
488 |
+
</span>
|
489 |
+
<span class="value">{description['Good with Children']}</span>
|
490 |
+
</div>
|
491 |
+
</div>
|
492 |
+
<!-- DESCRIPTION -->
|
493 |
+
<h2 class="section-title">
|
494 |
+
<span class="icon">📝</span>
|
495 |
+
<span class="tooltip">
|
496 |
+
DESCRIPTION
|
497 |
+
<span class="tooltip-icon">ⓘ</span>
|
498 |
+
<span class="tooltip-text">
|
499 |
+
<strong>About This Description:</strong><br>
|
500 |
+
• Comprehensive breed overview<br>
|
501 |
+
• Personality and characteristics<br>
|
502 |
+
• Historical background<br>
|
503 |
+
• Typical behaviors and traits
|
504 |
+
</span>
|
505 |
+
</span>
|
506 |
+
</h2>
|
507 |
+
<div class="description-section">
|
508 |
+
<p>{description.get('Description', '')}</p>
|
509 |
+
</div>
|
510 |
+
<!-- ACTION SECTION -->
|
511 |
+
<div class="action-section">
|
512 |
+
<a href="{get_akc_breeds_link(breed)}" target="_blank" class="akc-button">
|
513 |
+
<span class="icon">🌐</span>
|
514 |
+
Learn more about {breed} on AKC website
|
515 |
+
</a>
|
516 |
+
</div>
|
517 |
+
</div>
|
518 |
+
</div>
|
519 |
+
</div>
|
520 |
+
'''
|
521 |
+
|
522 |
+
result += '</div></div></div>'
|
523 |
+
return result
|
524 |
+
|
525 |
+
|
526 |
+
def format_multi_dog_container(dogs_info: str) -> str:
|
527 |
+
"""Wrap multiple dog detection results in a container."""
|
528 |
+
return f"""
|
529 |
+
<div class="dog-info-card">
|
530 |
+
{dogs_info}
|
531 |
+
</div>
|
532 |
+
"""
|
533 |
+
|
534 |
+
def format_breed_details_html(description: Dict[str, Any], breed: str) -> str:
|
535 |
+
"""Format breed details for the show_details_html function."""
|
536 |
+
return f"""
|
537 |
+
<div class="dog-info">
|
538 |
+
<h2>{breed}</h2>
|
539 |
+
<div class="breed-details">
|
540 |
+
{format_description_html(description, breed)}
|
541 |
+
<div class="action-section">
|
542 |
+
<a href="{get_akc_breeds_link(breed)}" target="_blank" class="akc-button">
|
543 |
+
<span class="icon">🌐</span>
|
544 |
+
Learn more about {breed} on AKC website
|
545 |
+
</a>
|
546 |
+
</div>
|
547 |
+
</div>
|
548 |
+
</div>
|
549 |
+
"""
|
550 |
+
|
551 |
+
def format_comparison_result(breed1: str, breed2: str, comparison_data: Dict) -> str:
|
552 |
+
"""Format breed comparison results into HTML."""
|
553 |
+
return f"""
|
554 |
+
<div class="comparison-container">
|
555 |
+
<div class="comparison-header">
|
556 |
+
<h3>Comparison: {breed1} vs {breed2}</h3>
|
557 |
+
</div>
|
558 |
+
<div class="comparison-content">
|
559 |
+
<div class="breed-column">
|
560 |
+
<h4>{breed1}</h4>
|
561 |
+
{format_comparison_details(comparison_data[breed1])}
|
562 |
+
</div>
|
563 |
+
<div class="breed-column">
|
564 |
+
<h4>{breed2}</h4>
|
565 |
+
{format_comparison_details(comparison_data[breed2])}
|
566 |
+
</div>
|
567 |
+
</div>
|
568 |
+
</div>
|
569 |
+
"""
|
570 |
+
|
571 |
+
def format_comparison_details(breed_data: Dict) -> str:
|
572 |
+
"""Format individual breed details for comparison."""
|
573 |
+
original_data = breed_data.get('Original_Data', {})
|
574 |
+
return f"""
|
575 |
+
<div class="comparison-details">
|
576 |
+
<p><strong>Size:</strong> {original_data.get('Size', 'N/A')}</p>
|
577 |
+
<p><strong>Exercise Needs:</strong> {original_data.get('Exercise Needs', 'N/A')}</p>
|
578 |
+
<p><strong>Care Level:</strong> {original_data.get('Care Level', 'N/A')}</p>
|
579 |
+
<p><strong>Grooming Needs:</strong> {original_data.get('Grooming Needs', 'N/A')}</p>
|
580 |
+
<p><strong>Good with Children:</strong> {original_data.get('Good with Children', 'N/A')}</p>
|
581 |
+
<p><strong>Temperament:</strong> {original_data.get('Temperament', 'N/A')}</p>
|
582 |
+
</div>
|
583 |
+
"""
|
584 |
+
|
585 |
+
def format_header_html() -> str:
|
586 |
+
"""Format the application header HTML."""
|
587 |
+
return """
|
588 |
+
<header style='text-align: center; padding: 20px; margin-bottom: 20px;'>
|
589 |
+
<h1 style='font-size: 2.5em; margin-bottom: 10px; color: #2D3748;'>
|
590 |
+
🐾 PawMatch AI
|
591 |
+
</h1>
|
592 |
+
<h2 style='font-size: 1.2em; font-weight: normal; color: #4A5568; margin-top: 5px;'>
|
593 |
+
Your Smart Dog Breed Guide
|
594 |
+
</h2>
|
595 |
+
<div style='width: 50px; height: 3px; background: linear-gradient(90deg, #4299e1, #48bb78); margin: 15px auto;'></div>
|
596 |
+
<p style='color: #718096; font-size: 0.9em;'>
|
597 |
+
Powered by AI • Breed Recognition • Smart Matching • Companion Guide
|
598 |
+
</p>
|
599 |
+
</header>
|
600 |
+
"""
|
recommendation_html_format.py
ADDED
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from breed_health_info import breed_health_info, default_health_note
|
3 |
+
from breed_noise_info import breed_noise_info
|
4 |
+
from dog_database import get_dog_description
|
5 |
+
from scoring_calculation_system import calculate_compatibility_score
|
6 |
+
|
7 |
+
def format_recommendation_html(recommendations: List[Dict]) -> str:
|
8 |
+
"""將推薦結果格式化為HTML"""
|
9 |
+
html_content = "<div class='recommendations-container'>"
|
10 |
+
|
11 |
+
for rec in recommendations:
|
12 |
+
breed = rec['breed']
|
13 |
+
scores = rec['scores']
|
14 |
+
info = rec['info']
|
15 |
+
rank = rec.get('rank', 0)
|
16 |
+
final_score = rec.get('final_score', scores['overall'])
|
17 |
+
bonus_score = rec.get('bonus_score', 0)
|
18 |
+
|
19 |
+
health_info = breed_health_info.get(breed, {"health_notes": default_health_note})
|
20 |
+
noise_info = breed_noise_info.get(breed, {
|
21 |
+
"noise_notes": "Noise information not available",
|
22 |
+
"noise_level": "Unknown",
|
23 |
+
"source": "N/A"
|
24 |
+
})
|
25 |
+
|
26 |
+
# 解析噪音資訊
|
27 |
+
noise_notes = noise_info.get('noise_notes', '').split('\n')
|
28 |
+
noise_characteristics = []
|
29 |
+
barking_triggers = []
|
30 |
+
noise_level = ''
|
31 |
+
|
32 |
+
current_section = None
|
33 |
+
for line in noise_notes:
|
34 |
+
line = line.strip()
|
35 |
+
if 'Typical noise characteristics:' in line:
|
36 |
+
current_section = 'characteristics'
|
37 |
+
elif 'Noise level:' in line:
|
38 |
+
noise_level = line.replace('Noise level:', '').strip()
|
39 |
+
elif 'Barking triggers:' in line:
|
40 |
+
current_section = 'triggers'
|
41 |
+
elif line.startswith('•'):
|
42 |
+
if current_section == 'characteristics':
|
43 |
+
noise_characteristics.append(line[1:].strip())
|
44 |
+
elif current_section == 'triggers':
|
45 |
+
barking_triggers.append(line[1:].strip())
|
46 |
+
|
47 |
+
# 生成特徵和觸發因素的HTML
|
48 |
+
noise_characteristics_html = '\n'.join([f'<li>{item}</li>' for item in noise_characteristics])
|
49 |
+
barking_triggers_html = '\n'.join([f'<li>{item}</li>' for item in barking_triggers])
|
50 |
+
|
51 |
+
# 處理健康資訊
|
52 |
+
health_notes = health_info.get('health_notes', '').split('\n')
|
53 |
+
health_considerations = []
|
54 |
+
health_screenings = []
|
55 |
+
|
56 |
+
current_section = None
|
57 |
+
for line in health_notes:
|
58 |
+
line = line.strip()
|
59 |
+
if 'Common breed-specific health considerations' in line:
|
60 |
+
current_section = 'considerations'
|
61 |
+
elif 'Recommended health screenings:' in line:
|
62 |
+
current_section = 'screenings'
|
63 |
+
elif line.startswith('•'):
|
64 |
+
if current_section == 'considerations':
|
65 |
+
health_considerations.append(line[1:].strip())
|
66 |
+
elif current_section == 'screenings':
|
67 |
+
health_screenings.append(line[1:].strip())
|
68 |
+
|
69 |
+
health_considerations_html = '\n'.join([f'<li>{item}</li>' for item in health_considerations])
|
70 |
+
health_screenings_html = '\n'.join([f'<li>{item}</li>' for item in health_screenings])
|
71 |
+
|
72 |
+
# 獎勵原因計算
|
73 |
+
bonus_reasons = []
|
74 |
+
temperament = info.get('Temperament', '').lower()
|
75 |
+
if any(trait in temperament for trait in ['friendly', 'gentle', 'affectionate']):
|
76 |
+
bonus_reasons.append("Positive temperament traits")
|
77 |
+
if info.get('Good with Children') == 'Yes':
|
78 |
+
bonus_reasons.append("Excellent with children")
|
79 |
+
try:
|
80 |
+
lifespan = info.get('Lifespan', '10-12 years')
|
81 |
+
years = int(lifespan.split('-')[0])
|
82 |
+
if years > 12:
|
83 |
+
bonus_reasons.append("Above-average lifespan")
|
84 |
+
except:
|
85 |
+
pass
|
86 |
+
|
87 |
+
html_content += f"""
|
88 |
+
<div class="dog-info-card recommendation-card">
|
89 |
+
<div class="breed-info">
|
90 |
+
<h2 class="section-title">
|
91 |
+
<span class="icon">🏆</span> #{rank} {breed.replace('_', ' ')}
|
92 |
+
<span class="score-badge">
|
93 |
+
Overall Match: {final_score*100:.1f}%
|
94 |
+
</span>
|
95 |
+
</h2>
|
96 |
+
<div class="compatibility-scores">
|
97 |
+
<div class="score-item">
|
98 |
+
<span class="label">Space Compatibility:</span>
|
99 |
+
<div class="progress-bar">
|
100 |
+
<div class="progress" style="width: {scores['space']*100}%"></div>
|
101 |
+
</div>
|
102 |
+
<span class="percentage">{scores['space']*100:.1f}%</span>
|
103 |
+
</div>
|
104 |
+
<div class="score-item">
|
105 |
+
<span class="label">Exercise Match:</span>
|
106 |
+
<div class="progress-bar">
|
107 |
+
<div class="progress" style="width: {scores['exercise']*100}%"></div>
|
108 |
+
</div>
|
109 |
+
<span class="percentage">{scores['exercise']*100:.1f}%</span>
|
110 |
+
</div>
|
111 |
+
<div class="score-item">
|
112 |
+
<span class="label">Grooming Match:</span>
|
113 |
+
<div class="progress-bar">
|
114 |
+
<div class="progress" style="width: {scores['grooming']*100}%"></div>
|
115 |
+
</div>
|
116 |
+
<span class="percentage">{scores['grooming']*100:.1f}%</span>
|
117 |
+
</div>
|
118 |
+
<div class="score-item">
|
119 |
+
<span class="label">Experience Match:</span>
|
120 |
+
<div class="progress-bar">
|
121 |
+
<div class="progress" style="width: {scores['experience']*100}%"></div>
|
122 |
+
</div>
|
123 |
+
<span class="percentage">{scores['experience']*100:.1f}%</span>
|
124 |
+
</div>
|
125 |
+
<div class="score-item">
|
126 |
+
<span class="label">
|
127 |
+
Noise Compatibility:
|
128 |
+
<span class="tooltip">
|
129 |
+
<span class="tooltip-icon">ⓘ</span>
|
130 |
+
<span class="tooltip-text">
|
131 |
+
<strong>Noise Compatibility Score:</strong><br>
|
132 |
+
• Based on your noise tolerance preference<br>
|
133 |
+
• Considers breed's typical noise level<br>
|
134 |
+
• Accounts for living environment
|
135 |
+
</span>
|
136 |
+
</span>
|
137 |
+
</span>
|
138 |
+
<div class="progress-bar">
|
139 |
+
<div class="progress" style="width: {scores['noise']*100}%"></div>
|
140 |
+
</div>
|
141 |
+
<span class="percentage">{scores['noise']*100:.1f}%</span>
|
142 |
+
</div>
|
143 |
+
{f'''
|
144 |
+
<div class="score-item bonus-score">
|
145 |
+
<span class="label">
|
146 |
+
Breed Bonus:
|
147 |
+
<span class="tooltip">
|
148 |
+
<span class="tooltip-icon">ⓘ</span>
|
149 |
+
<span class="tooltip-text">
|
150 |
+
<strong>Breed Bonus Points:</strong><br>
|
151 |
+
• {('<br>• '.join(bonus_reasons)) if bonus_reasons else 'No additional bonus points'}<br>
|
152 |
+
<br>
|
153 |
+
<strong>Bonus Factors Include:</strong><br>
|
154 |
+
• Friendly temperament<br>
|
155 |
+
• Child compatibility<br>
|
156 |
+
• Longer lifespan<br>
|
157 |
+
• Living space adaptability
|
158 |
+
</span>
|
159 |
+
</span>
|
160 |
+
</span>
|
161 |
+
<div class="progress-bar">
|
162 |
+
<div class="progress" style="width: {bonus_score*100}%"></div>
|
163 |
+
</div>
|
164 |
+
<span class="percentage">{bonus_score*100:.1f}%</span>
|
165 |
+
</div>
|
166 |
+
''' if bonus_score > 0 else ''}
|
167 |
+
</div>
|
168 |
+
<div class="breed-details-section">
|
169 |
+
<h3 class="subsection-title">
|
170 |
+
<span class="icon">📋</span> Breed Details
|
171 |
+
</h3>
|
172 |
+
<div class="details-grid">
|
173 |
+
<div class="detail-item">
|
174 |
+
<span class="tooltip">
|
175 |
+
<span class="icon">📏</span>
|
176 |
+
<span class="label">Size:</span>
|
177 |
+
<span class="tooltip-icon">ⓘ</span>
|
178 |
+
<span class="tooltip-text">
|
179 |
+
<strong>Size Categories:</strong><br>
|
180 |
+
• Small: Under 20 pounds<br>
|
181 |
+
• Medium: 20-60 pounds<br>
|
182 |
+
• Large: Over 60 pounds
|
183 |
+
</span>
|
184 |
+
<span class="value">{info['Size']}</span>
|
185 |
+
</span>
|
186 |
+
</div>
|
187 |
+
<div class="detail-item">
|
188 |
+
<span class="tooltip">
|
189 |
+
<span class="icon">🏃</span>
|
190 |
+
<span class="label">Exercise Needs:</span>
|
191 |
+
<span class="tooltip-icon">ⓘ</span>
|
192 |
+
<span class="tooltip-text">
|
193 |
+
<strong>Exercise Needs:</strong><br>
|
194 |
+
• Low: Short walks<br>
|
195 |
+
• Moderate: 1-2 hours daily<br>
|
196 |
+
• High: 2+ hours daily<br>
|
197 |
+
• Very High: Constant activity
|
198 |
+
</span>
|
199 |
+
<span class="value">{info['Exercise Needs']}</span>
|
200 |
+
</span>
|
201 |
+
</div>
|
202 |
+
<div class="detail-item">
|
203 |
+
<span class="tooltip">
|
204 |
+
<span class="icon">👨👩👧👦</span>
|
205 |
+
<span class="label">Good with Children:</span>
|
206 |
+
<span class="tooltip-icon">ⓘ</span>
|
207 |
+
<span class="tooltip-text">
|
208 |
+
<strong>Child Compatibility:</strong><br>
|
209 |
+
• Yes: Excellent with kids<br>
|
210 |
+
• Moderate: Good with older children<br>
|
211 |
+
• No: Better for adult households
|
212 |
+
</span>
|
213 |
+
<span class="value">{info['Good with Children']}</span>
|
214 |
+
</span>
|
215 |
+
</div>
|
216 |
+
<div class="detail-item">
|
217 |
+
<span class="tooltip">
|
218 |
+
<span class="icon">⏳</span>
|
219 |
+
<span class="label">Lifespan:</span>
|
220 |
+
<span class="tooltip-icon">ⓘ</span>
|
221 |
+
<span class="tooltip-text">
|
222 |
+
<strong>Average Lifespan:</strong><br>
|
223 |
+
• Short: 6-8 years<br>
|
224 |
+
• Average: 10-15 years<br>
|
225 |
+
• Long: 12-20 years<br>
|
226 |
+
• Varies by size: Larger breeds typically have shorter lifespans
|
227 |
+
</span>
|
228 |
+
</span>
|
229 |
+
<span class="value">{info['Lifespan']}</span>
|
230 |
+
</div>
|
231 |
+
</div>
|
232 |
+
</div>
|
233 |
+
<div class="description-section">
|
234 |
+
<h3 class="subsection-title">
|
235 |
+
<span class="icon">📝</span> Description
|
236 |
+
</h3>
|
237 |
+
<p class="description-text">{info.get('Description', '')}</p>
|
238 |
+
</div>
|
239 |
+
<div class="noise-section">
|
240 |
+
<h3 class="section-header">
|
241 |
+
<span class="icon">🔊</span> Noise Behavior
|
242 |
+
</h3>
|
243 |
+
<div class="noise-info">
|
244 |
+
<div class="noise-details">
|
245 |
+
<h4 class="section-header">Typical noise characteristics:</h4>
|
246 |
+
<div class="characteristics-list">
|
247 |
+
<div class="list-item">Moderate to high barker</div>
|
248 |
+
<div class="list-item">Alert watch dog</div>
|
249 |
+
<div class="list-item">Attention-seeking barks</div>
|
250 |
+
<div class="list-item">Social vocalizations</div>
|
251 |
+
</div>
|
252 |
+
|
253 |
+
<div class="noise-level-display">
|
254 |
+
<h4 class="section-header">Noise level:</h4>
|
255 |
+
<div class="level-indicator">
|
256 |
+
<span class="level-text">Moderate-High</span>
|
257 |
+
<div class="level-bars">
|
258 |
+
<span class="bar"></span>
|
259 |
+
<span class="bar"></span>
|
260 |
+
<span class="bar"></span>
|
261 |
+
</div>
|
262 |
+
</div>
|
263 |
+
</div>
|
264 |
+
|
265 |
+
<h4 class="section-header">Barking triggers:</h4>
|
266 |
+
<div class="triggers-list">
|
267 |
+
<div class="list-item">Separation anxiety</div>
|
268 |
+
<div class="list-item">Attention needs</div>
|
269 |
+
<div class="list-item">Strange noises</div>
|
270 |
+
<div class="list-item">Excitement</div>
|
271 |
+
</div>
|
272 |
+
</div>
|
273 |
+
<div class="noise-disclaimer">
|
274 |
+
<p class="disclaimer-text source-text">Source: Compiled from various breed behavior resources, 2024</p>
|
275 |
+
<p class="disclaimer-text">Individual dogs may vary in their vocalization patterns.</p>
|
276 |
+
<p class="disclaimer-text">Training can significantly influence barking behavior.</p>
|
277 |
+
<p class="disclaimer-text">Environmental factors may affect noise levels.</p>
|
278 |
+
</div>
|
279 |
+
</div>
|
280 |
+
</div>
|
281 |
+
|
282 |
+
<div class="health-section">
|
283 |
+
<h3 class="section-header">
|
284 |
+
<span class="icon">🏥</span> Health Insights
|
285 |
+
<span class="tooltip">
|
286 |
+
<span class="tooltip-icon">ⓘ</span>
|
287 |
+
<span class="tooltip-text">
|
288 |
+
Health information is compiled from multiple sources including veterinary resources, breed guides, and international canine health databases.
|
289 |
+
Each dog is unique and may vary from these general guidelines.
|
290 |
+
</span>
|
291 |
+
</span>
|
292 |
+
</h3>
|
293 |
+
<div class="health-info">
|
294 |
+
<div class="health-details">
|
295 |
+
<div class="health-block">
|
296 |
+
<h4 class="section-header">Common breed-specific health considerations:</h4>
|
297 |
+
<div class="health-grid">
|
298 |
+
<div class="health-item">Patellar luxation</div>
|
299 |
+
<div class="health-item">Progressive retinal atrophy</div>
|
300 |
+
<div class="health-item">Von Willebrand's disease</div>
|
301 |
+
<div class="health-item">Open fontanel</div>
|
302 |
+
</div>
|
303 |
+
</div>
|
304 |
+
|
305 |
+
<div class="health-block">
|
306 |
+
<h4 class="section-header">Recommended health screenings:</h4>
|
307 |
+
<div class="health-grid">
|
308 |
+
<div class="health-item screening">Patella evaluation</div>
|
309 |
+
<div class="health-item screening">Eye examination</div>
|
310 |
+
<div class="health-item screening">Blood clotting tests</div>
|
311 |
+
<div class="health-item screening">Skull development monitoring</div>
|
312 |
+
</div>
|
313 |
+
</div>
|
314 |
+
</div>
|
315 |
+
<div class="health-disclaimer">
|
316 |
+
<p class="disclaimer-text source-text">Source: Compiled from various veterinary and breed information resources, 2024</p>
|
317 |
+
<p class="disclaimer-text">This information is for reference only and based on breed tendencies.</p>
|
318 |
+
<p class="disclaimer-text">Each dog is unique and may not develop any or all of these conditions.</p>
|
319 |
+
<p class="disclaimer-text">Always consult with qualified veterinarians for professional advice.</p>
|
320 |
+
</div>
|
321 |
+
</div>
|
322 |
+
</div>
|
323 |
+
|
324 |
+
<div class="action-section">
|
325 |
+
<a href="https://www.akc.org/dog-breeds/{breed.lower().replace('_', '-')}/"
|
326 |
+
target="_blank"
|
327 |
+
class="akc-button">
|
328 |
+
<span class="icon">🌐</span>
|
329 |
+
Learn more about {breed.replace('_', ' ')} on AKC website
|
330 |
+
</a>
|
331 |
+
</div>
|
332 |
+
</div>
|
333 |
+
</div>
|
334 |
+
"""
|
335 |
+
|
336 |
+
html_content += "</div>"
|
337 |
+
return html_content
|
338 |
+
|
339 |
+
def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 10) -> List[Dict]:
|
340 |
+
"""基於使用者偏好推薦狗品種,確保正確的分數排序"""
|
341 |
+
print("Starting get_breed_recommendations")
|
342 |
+
recommendations = []
|
343 |
+
seen_breeds = set()
|
344 |
+
|
345 |
+
try:
|
346 |
+
# 獲取所有品種
|
347 |
+
conn = sqlite3.connect('animal_detector.db')
|
348 |
+
cursor = conn.cursor()
|
349 |
+
cursor.execute("SELECT Breed FROM AnimalCatalog")
|
350 |
+
all_breeds = cursor.fetchall()
|
351 |
+
conn.close()
|
352 |
+
|
353 |
+
# 收集所有品種的分數
|
354 |
+
for breed_tuple in all_breeds:
|
355 |
+
breed = breed_tuple[0]
|
356 |
+
base_breed = breed.split('(')[0].strip()
|
357 |
+
|
358 |
+
if base_breed in seen_breeds:
|
359 |
+
continue
|
360 |
+
seen_breeds.add(base_breed)
|
361 |
+
|
362 |
+
# 獲取品種資訊
|
363 |
+
breed_info = get_dog_description(breed)
|
364 |
+
if not isinstance(breed_info, dict):
|
365 |
+
continue
|
366 |
+
|
367 |
+
# 獲取噪音資訊
|
368 |
+
noise_info = breed_noise_info.get(breed, {
|
369 |
+
"noise_notes": "Noise information not available",
|
370 |
+
"noise_level": "Unknown",
|
371 |
+
"source": "N/A"
|
372 |
+
})
|
373 |
+
|
374 |
+
# 將噪音資訊整合到品種資訊中
|
375 |
+
breed_info['noise_info'] = noise_info
|
376 |
+
|
377 |
+
# 計算基礎相容性分數
|
378 |
+
compatibility_scores = calculate_compatibility_score(breed_info, user_prefs)
|
379 |
+
|
380 |
+
# 計算品種特定加分
|
381 |
+
breed_bonus = 0.0
|
382 |
+
|
383 |
+
# 壽命加分
|
384 |
+
try:
|
385 |
+
lifespan = breed_info.get('Lifespan', '10-12 years')
|
386 |
+
years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
387 |
+
longevity_bonus = min(0.02, (max(years) - 10) * 0.005)
|
388 |
+
breed_bonus += longevity_bonus
|
389 |
+
except:
|
390 |
+
pass
|
391 |
+
|
392 |
+
# 性格特徵加分
|
393 |
+
temperament = breed_info.get('Temperament', '').lower()
|
394 |
+
positive_traits = ['friendly', 'gentle', 'affectionate', 'intelligent']
|
395 |
+
negative_traits = ['aggressive', 'stubborn', 'dominant']
|
396 |
+
|
397 |
+
breed_bonus += sum(0.01 for trait in positive_traits if trait in temperament)
|
398 |
+
breed_bonus -= sum(0.01 for trait in negative_traits if trait in temperament)
|
399 |
+
|
400 |
+
# 與孩童相容性加分
|
401 |
+
if user_prefs.has_children:
|
402 |
+
if breed_info.get('Good with Children') == 'Yes':
|
403 |
+
breed_bonus += 0.02
|
404 |
+
elif breed_info.get('Good with Children') == 'No':
|
405 |
+
breed_bonus -= 0.03
|
406 |
+
|
407 |
+
# 噪音相關加分
|
408 |
+
if user_prefs.noise_tolerance == 'low':
|
409 |
+
if noise_info['noise_level'].lower() == 'high':
|
410 |
+
breed_bonus -= 0.03
|
411 |
+
elif noise_info['noise_level'].lower() == 'low':
|
412 |
+
breed_bonus += 0.02
|
413 |
+
elif user_prefs.noise_tolerance == 'high':
|
414 |
+
if noise_info['noise_level'].lower() == 'high':
|
415 |
+
breed_bonus += 0.01
|
416 |
+
|
417 |
+
# 計算最終分數
|
418 |
+
breed_bonus = round(breed_bonus, 4)
|
419 |
+
final_score = round(compatibility_scores['overall'] + breed_bonus, 4)
|
420 |
+
|
421 |
+
recommendations.append({
|
422 |
+
'breed': breed,
|
423 |
+
'base_score': round(compatibility_scores['overall'], 4),
|
424 |
+
'bonus_score': round(breed_bonus, 4),
|
425 |
+
'final_score': final_score,
|
426 |
+
'scores': compatibility_scores,
|
427 |
+
'info': breed_info,
|
428 |
+
'noise_info': noise_info # 添加噪音資訊到推薦結果
|
429 |
+
})
|
430 |
+
# 嚴格按照 final_score 排序
|
431 |
+
recommendations.sort(key=lambda x: (round(-x['final_score'], 4), x['breed'] )) # 負號使其降序排列,並確保4位小數
|
432 |
+
|
433 |
+
# 選擇前N名並確保正確排序
|
434 |
+
final_recommendations = []
|
435 |
+
last_score = None
|
436 |
+
rank = 1
|
437 |
+
|
438 |
+
for rec in recommendations:
|
439 |
+
if len(final_recommendations) >= top_n:
|
440 |
+
break
|
441 |
+
|
442 |
+
current_score = rec['final_score']
|
443 |
+
|
444 |
+
# 確保分數遞減
|
445 |
+
if last_score is not None and current_score > last_score:
|
446 |
+
continue
|
447 |
+
|
448 |
+
# 添加排名資訊
|
449 |
+
rec['rank'] = rank
|
450 |
+
final_recommendations.append(rec)
|
451 |
+
|
452 |
+
last_score = current_score
|
453 |
+
rank += 1
|
454 |
+
|
455 |
+
# 驗證最終排序
|
456 |
+
for i in range(len(final_recommendations)-1):
|
457 |
+
current = final_recommendations[i]
|
458 |
+
next_rec = final_recommendations[i+1]
|
459 |
+
|
460 |
+
if current['final_score'] < next_rec['final_score']:
|
461 |
+
print(f"Warning: Sorting error detected!")
|
462 |
+
print(f"#{i+1} {current['breed']}: {current['final_score']}")
|
463 |
+
print(f"#{i+2} {next_rec['breed']}: {next_rec['final_score']}")
|
464 |
+
|
465 |
+
# 交換位置
|
466 |
+
final_recommendations[i], final_recommendations[i+1] = \
|
467 |
+
final_recommendations[i+1], final_recommendations[i]
|
468 |
+
|
469 |
+
# 打印最終結果以供驗證
|
470 |
+
print("\nFinal Rankings:")
|
471 |
+
for rec in final_recommendations:
|
472 |
+
print(f"#{rec['rank']} {rec['breed']}")
|
473 |
+
print(f"Base Score: {rec['base_score']:.4f}")
|
474 |
+
print(f"Bonus: {rec['bonus_score']:.4f}")
|
475 |
+
print(f"Final Score: {rec['final_score']:.4f}\n")
|
476 |
+
|
477 |
+
return final_recommendations
|
478 |
+
|
479 |
+
except Exception as e:
|
480 |
+
print(f"Error in get_breed_recommendations: {str(e)}")
|
481 |
+
print(f"Traceback: {traceback.format_exc()}")
|
482 |
+
return []
|
scoring_calculation_system.py
ADDED
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from breed_health_info import breed_health_info
|
3 |
+
from breed_noise_info import breed_noise_info
|
4 |
+
|
5 |
+
@dataclass
|
6 |
+
class UserPreferences:
|
7 |
+
"""使用者偏好設定的資料結構"""
|
8 |
+
living_space: str # "apartment", "house_small", "house_large"
|
9 |
+
exercise_time: int # minutes per day
|
10 |
+
grooming_commitment: str # "low", "medium", "high"
|
11 |
+
experience_level: str # "beginner", "intermediate", "advanced"
|
12 |
+
has_children: bool
|
13 |
+
noise_tolerance: str # "low", "medium", "high"
|
14 |
+
space_for_play: bool
|
15 |
+
other_pets: bool
|
16 |
+
climate: str # "cold", "moderate", "hot"
|
17 |
+
health_sensitivity: str = "medium" # 設置默認值
|
18 |
+
barking_acceptance: str = None
|
19 |
+
|
20 |
+
def __post_init__(self):
|
21 |
+
"""在初始化後運行,用於設置派生值"""
|
22 |
+
if self.barking_acceptance is None:
|
23 |
+
self.barking_acceptance = self.noise_tolerance
|
24 |
+
|
25 |
+
@staticmethod
|
26 |
+
def calculate_breed_bonus(breed_info: dict, user_prefs: 'UserPreferences') -> float:
|
27 |
+
"""計算品種額外加分"""
|
28 |
+
bonus = 0.0
|
29 |
+
|
30 |
+
# 壽命加分
|
31 |
+
try:
|
32 |
+
lifespan = breed_info.get('Lifespan', '10-12 years')
|
33 |
+
years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
34 |
+
longevity_bonus = min(0.05, (max(years) - 10) * 0.01)
|
35 |
+
bonus += longevity_bonus
|
36 |
+
except:
|
37 |
+
pass
|
38 |
+
|
39 |
+
# 性格特徵加分
|
40 |
+
temperament = breed_info.get('Temperament', '').lower()
|
41 |
+
if user_prefs.has_children:
|
42 |
+
if 'gentle' in temperament or 'patient' in temperament:
|
43 |
+
bonus += 0.03
|
44 |
+
|
45 |
+
# 適應性加分
|
46 |
+
if breed_info.get('Size') == "Small" and user_prefs.living_space == "apartment":
|
47 |
+
bonus += 0.02
|
48 |
+
|
49 |
+
return bonus
|
50 |
+
|
51 |
+
@staticmethod
|
52 |
+
def calculate_additional_factors(breed_info: dict, user_prefs: 'UserPreferences') -> dict:
|
53 |
+
"""計算額外的排序因素"""
|
54 |
+
factors = {
|
55 |
+
'versatility': 0.0,
|
56 |
+
'health_score': 0.0,
|
57 |
+
'adaptability': 0.0
|
58 |
+
}
|
59 |
+
|
60 |
+
# 計算多功能性分數
|
61 |
+
temperament = breed_info.get('Temperament', '').lower()
|
62 |
+
versatile_traits = ['intelligent', 'adaptable', 'versatile', 'trainable']
|
63 |
+
factors['versatility'] = sum(trait in temperament for trait in versatile_traits) / len(versatile_traits)
|
64 |
+
|
65 |
+
# 計算健康分數(基於預期壽命)
|
66 |
+
lifespan = breed_info.get('Lifespan', '10-12 years')
|
67 |
+
try:
|
68 |
+
years = [int(x) for x in lifespan.split('-')[0].split()[0:1]]
|
69 |
+
factors['health_score'] = min(1.0, max(years) / 15) # 標準化到0-1範圍
|
70 |
+
except:
|
71 |
+
factors['health_score'] = 0.5 # 預設值
|
72 |
+
|
73 |
+
# 計算適應性分數
|
74 |
+
size = breed_info.get('Size', 'Medium')
|
75 |
+
factors['adaptability'] = {
|
76 |
+
'Small': 0.9,
|
77 |
+
'Medium': 0.7,
|
78 |
+
'Large': 0.5,
|
79 |
+
'Giant': 0.3
|
80 |
+
}.get(size, 0.5)
|
81 |
+
|
82 |
+
return factors
|
83 |
+
|
84 |
+
|
85 |
+
def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences) -> dict:
|
86 |
+
"""計算品種與使用者條件的相容性分數"""
|
87 |
+
scores = {}
|
88 |
+
try:
|
89 |
+
# 1. 空間相容性計算
|
90 |
+
def calculate_space_score(size, living_space, has_yard):
|
91 |
+
base_scores = {
|
92 |
+
"Small": {"apartment": 0.95, "house_small": 1.0, "house_large": 0.90},
|
93 |
+
"Medium": {"apartment": 0.65, "house_small": 0.90, "house_large": 1.0},
|
94 |
+
"Large": {"apartment": 0.35, "house_small": 0.75, "house_large": 1.0},
|
95 |
+
"Giant": {"apartment": 0.15, "house_small": 0.55, "house_large": 1.0}
|
96 |
+
}
|
97 |
+
|
98 |
+
base_score = base_scores.get(size, base_scores["Medium"])[living_space]
|
99 |
+
adjustments = 0
|
100 |
+
|
101 |
+
# 特殊情況調整
|
102 |
+
if living_space == "apartment":
|
103 |
+
if size == "Small":
|
104 |
+
adjustments += 0.05
|
105 |
+
elif size in ["Large", "Giant"]:
|
106 |
+
adjustments -= 0.15
|
107 |
+
|
108 |
+
if has_yard and living_space in ["house_small", "house_large"]:
|
109 |
+
adjustments += 0.05
|
110 |
+
|
111 |
+
return min(1.0, max(0, base_score + adjustments))
|
112 |
+
|
113 |
+
# 2. 運動相容性計算
|
114 |
+
def calculate_exercise_score(breed_exercise_needs, user_exercise_time):
|
115 |
+
exercise_needs = {
|
116 |
+
'VERY HIGH': 120,
|
117 |
+
'HIGH': 90,
|
118 |
+
'MODERATE': 60,
|
119 |
+
'LOW': 30,
|
120 |
+
'VARIES': 60
|
121 |
+
}
|
122 |
+
|
123 |
+
breed_need = exercise_needs.get(breed_exercise_needs.strip().upper(), 60)
|
124 |
+
difference = abs(user_exercise_time - breed_need) / breed_need
|
125 |
+
|
126 |
+
if difference == 0:
|
127 |
+
return 1.0
|
128 |
+
elif difference <= 0.2:
|
129 |
+
return 0.95
|
130 |
+
elif difference <= 0.4:
|
131 |
+
return 0.85
|
132 |
+
elif difference <= 0.6:
|
133 |
+
return 0.70
|
134 |
+
elif difference <= 0.8:
|
135 |
+
return 0.50
|
136 |
+
else:
|
137 |
+
return 0.30
|
138 |
+
|
139 |
+
# 3. 美容需求計算
|
140 |
+
def calculate_grooming_score(breed_grooming_needs, user_commitment, breed_size):
|
141 |
+
base_scores = {
|
142 |
+
"High": {"low": 0.3, "medium": 0.7, "high": 1.0},
|
143 |
+
"Moderate": {"low": 0.5, "medium": 0.9, "high": 1.0},
|
144 |
+
"Low": {"low": 1.0, "medium": 0.95, "high": 0.9}
|
145 |
+
}
|
146 |
+
|
147 |
+
base_score = base_scores.get(breed_grooming_needs, base_scores["Moderate"])[user_commitment]
|
148 |
+
|
149 |
+
if breed_size == "Large" and user_commitment == "low":
|
150 |
+
base_score *= 0.80
|
151 |
+
elif breed_size == "Giant" and user_commitment == "low":
|
152 |
+
base_score *= 0.70
|
153 |
+
|
154 |
+
return base_score
|
155 |
+
|
156 |
+
# 4. 經驗等級計算
|
157 |
+
def calculate_experience_score(care_level, user_experience, temperament):
|
158 |
+
base_scores = {
|
159 |
+
"High": {"beginner": 0.3, "intermediate": 0.7, "advanced": 1.0},
|
160 |
+
"Moderate": {"beginner": 0.6, "intermediate": 0.9, "advanced": 1.0},
|
161 |
+
"Low": {"beginner": 0.9, "intermediate": 1.0, "advanced": 1.0}
|
162 |
+
}
|
163 |
+
|
164 |
+
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
165 |
+
|
166 |
+
temperament_lower = temperament.lower()
|
167 |
+
if user_experience == "beginner":
|
168 |
+
if any(trait in temperament_lower for trait in ['stubborn', 'independent', 'intelligent']):
|
169 |
+
score *= 0.80
|
170 |
+
if any(trait in temperament_lower for trait in ['easy', 'gentle', 'friendly']):
|
171 |
+
score *= 1.15
|
172 |
+
|
173 |
+
return min(1.0, score)
|
174 |
+
|
175 |
+
def calculate_health_score(breed_name: str) -> float:
|
176 |
+
if breed_name not in breed_health_info:
|
177 |
+
return 0.5
|
178 |
+
|
179 |
+
health_notes = breed_health_info[breed_name]['health_notes'].lower()
|
180 |
+
|
181 |
+
# 嚴重健康問題
|
182 |
+
severe_conditions = [
|
183 |
+
'cancer', 'cardiomyopathy', 'epilepsy', 'dysplasia',
|
184 |
+
'bloat', 'progressive', 'syndrome'
|
185 |
+
]
|
186 |
+
|
187 |
+
# 中等健康問題
|
188 |
+
moderate_conditions = [
|
189 |
+
'allergies', 'infections', 'thyroid', 'luxation',
|
190 |
+
'skin problems', 'ear'
|
191 |
+
]
|
192 |
+
|
193 |
+
severe_count = sum(1 for condition in severe_conditions if condition in health_notes)
|
194 |
+
moderate_count = sum(1 for condition in moderate_conditions if condition in health_notes)
|
195 |
+
|
196 |
+
health_score = 1.0
|
197 |
+
health_score -= (severe_count * 0.1)
|
198 |
+
health_score -= (moderate_count * 0.05)
|
199 |
+
|
200 |
+
# 特殊條件調整
|
201 |
+
if user_prefs.has_children:
|
202 |
+
if 'requires frequent' in health_notes or 'regular monitoring' in health_notes:
|
203 |
+
health_score *= 0.9
|
204 |
+
|
205 |
+
if user_prefs.experience_level == 'beginner':
|
206 |
+
if 'requires frequent' in health_notes or 'requires experienced' in health_notes:
|
207 |
+
health_score *= 0.8
|
208 |
+
|
209 |
+
return max(0.3, min(1.0, health_score))
|
210 |
+
|
211 |
+
def calculate_noise_score(breed_name: str, user_noise_tolerance: str) -> float:
|
212 |
+
if breed_name not in breed_noise_info:
|
213 |
+
return 0.5
|
214 |
+
|
215 |
+
noise_info = breed_noise_info[breed_name]
|
216 |
+
noise_level = noise_info['noise_level'].lower()
|
217 |
+
|
218 |
+
|
219 |
+
# 基礎噪音分數矩陣
|
220 |
+
noise_matrix = {
|
221 |
+
'low': {'low': 1.0, 'medium': 0.8, 'high': 0.6},
|
222 |
+
'medium': {'low': 0.7, 'medium': 1.0, 'high': 0.8},
|
223 |
+
'high': {'low': 0.4, 'medium': 0.7, 'high': 1.0}
|
224 |
+
}
|
225 |
+
|
226 |
+
# 從噪音矩陣獲取基礎分數
|
227 |
+
base_score = noise_matrix.get(noise_level, {'low': 0.7, 'medium': 0.7, 'high': 0.7})[user_noise_tolerance]
|
228 |
+
|
229 |
+
# 特殊情況調整
|
230 |
+
special_adjustments = 0
|
231 |
+
if user_prefs.has_children and noise_level == 'high':
|
232 |
+
special_adjustments -= 0.1
|
233 |
+
if user_prefs.living_space == 'apartment':
|
234 |
+
if noise_level == 'high':
|
235 |
+
special_adjustments -= 0.15
|
236 |
+
elif noise_level == 'medium':
|
237 |
+
special_adjustments -= 0.05
|
238 |
+
|
239 |
+
final_score = base_score + special_adjustments
|
240 |
+
return max(0.3, min(1.0, final_score))
|
241 |
+
|
242 |
+
# 計算所有基礎分數
|
243 |
+
scores = {
|
244 |
+
'space': calculate_space_score(breed_info['Size'], user_prefs.living_space, user_prefs.space_for_play),
|
245 |
+
'exercise': calculate_exercise_score(breed_info.get('Exercise Needs', 'Moderate'), user_prefs.exercise_time),
|
246 |
+
'grooming': calculate_grooming_score(breed_info.get('Grooming Needs', 'Moderate'), user_prefs.grooming_commitment.lower(), breed_info['Size']),
|
247 |
+
'experience': calculate_experience_score(breed_info.get('Care Level', 'Moderate'), user_prefs.experience_level, breed_info.get('Temperament', '')),
|
248 |
+
'health': calculate_health_score(breed_info.get('Breed', '')),
|
249 |
+
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
250 |
+
}
|
251 |
+
|
252 |
+
# 更新權重配置
|
253 |
+
weights = {
|
254 |
+
'space': 0.20,
|
255 |
+
'exercise': 0.20,
|
256 |
+
'grooming': 0.15,
|
257 |
+
'experience': 0.15,
|
258 |
+
'health': 0.15,
|
259 |
+
'noise': 0.15
|
260 |
+
}
|
261 |
+
|
262 |
+
# 基礎分數計算
|
263 |
+
base_score = sum(score * weights[category]
|
264 |
+
for category, score in scores.items()
|
265 |
+
if category != 'overall')
|
266 |
+
|
267 |
+
# 額外調整
|
268 |
+
adjustments = 0
|
269 |
+
|
270 |
+
# 1. 適應性加分
|
271 |
+
if breed_info.get('Adaptability', 'Medium') == 'High':
|
272 |
+
adjustments += 0.02
|
273 |
+
|
274 |
+
# 2. 氣候相容性
|
275 |
+
if user_prefs.climate in breed_info.get('Suitable Climate', '').split(','):
|
276 |
+
adjustments += 0.02
|
277 |
+
|
278 |
+
# 3. 其他寵物相容性
|
279 |
+
if user_prefs.other_pets and breed_info.get('Good with Other Pets') == 'Yes':
|
280 |
+
adjustments += 0.02
|
281 |
+
|
282 |
+
final_score = min(1.0, max(0, base_score + adjustments))
|
283 |
+
scores['overall'] = round(final_score, 4)
|
284 |
+
|
285 |
+
# 四捨五入所有分數
|
286 |
+
for key in scores:
|
287 |
+
scores[key] = round(scores[key], 4)
|
288 |
+
|
289 |
+
return scores
|
290 |
+
|
291 |
+
except Exception as e:
|
292 |
+
print(f"Error in calculate_compatibility_score: {str(e)}")
|
293 |
+
return {k: 0.5 for k in ['space', 'exercise', 'grooming', 'experience', 'health', 'noise', 'overall']}
|
styles.py
ADDED
@@ -0,0 +1,1238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
def get_css_styles():
|
3 |
+
return """
|
4 |
+
.dog-info-card {
|
5 |
+
margin: 0 0 20px 0;
|
6 |
+
padding: 0;
|
7 |
+
border-radius: 12px;
|
8 |
+
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
9 |
+
overflow: hidden;
|
10 |
+
transition: all 0.3s ease;
|
11 |
+
background: white;
|
12 |
+
border: 1px solid #e1e4e8;
|
13 |
+
position: relative;
|
14 |
+
}
|
15 |
+
|
16 |
+
.dog-info-card:hover {
|
17 |
+
box-shadow: 0 4px 16px rgba(0,0,0,0.12);
|
18 |
+
}
|
19 |
+
|
20 |
+
.dog-info-card:before {
|
21 |
+
content: '';
|
22 |
+
position: absolute;
|
23 |
+
left: 0;
|
24 |
+
top: 0;
|
25 |
+
bottom: 0;
|
26 |
+
width: 8px;
|
27 |
+
background-color: inherit;
|
28 |
+
}
|
29 |
+
|
30 |
+
.dog-info-header {
|
31 |
+
padding: 24px 28px; /* 增加內距 */
|
32 |
+
margin: 0;
|
33 |
+
font-size: 22px;
|
34 |
+
font-weight: bold;
|
35 |
+
border-bottom: 1px solid #e1e4e8;
|
36 |
+
}
|
37 |
+
|
38 |
+
.dog-info-header {
|
39 |
+
background-color: transparent;
|
40 |
+
}
|
41 |
+
|
42 |
+
.colored-border {
|
43 |
+
position: absolute;
|
44 |
+
left: 0;
|
45 |
+
top: 0;
|
46 |
+
bottom: 0;
|
47 |
+
width: 8px;
|
48 |
+
}
|
49 |
+
|
50 |
+
.dog-info-header {
|
51 |
+
border-left-width: 8px;
|
52 |
+
border-left-style: solid;
|
53 |
+
}
|
54 |
+
|
55 |
+
.breed-info {
|
56 |
+
padding: 28px; /* 增加整體內距 */
|
57 |
+
line-height: 1.6;
|
58 |
+
font-size: 1rem;
|
59 |
+
border: none;
|
60 |
+
}
|
61 |
+
|
62 |
+
.section-title {
|
63 |
+
font-size: 1.2em !important;
|
64 |
+
font-weight: 700;
|
65 |
+
color: #2c3e50;
|
66 |
+
margin: 32px 0 20px 0;
|
67 |
+
padding: 12px 0;
|
68 |
+
border-bottom: 2px solid #e1e4e8;
|
69 |
+
text-transform: uppercase;
|
70 |
+
letter-spacing: 0.5px;
|
71 |
+
display: flex;
|
72 |
+
align-items: center;
|
73 |
+
gap: 8px;
|
74 |
+
position: relative;
|
75 |
+
}
|
76 |
+
|
77 |
+
.section-header {
|
78 |
+
color: #2c3e50;
|
79 |
+
font-size: 1.15rem;
|
80 |
+
font-weight: 600;
|
81 |
+
margin: 20px 0 12px 0;
|
82 |
+
display: flex;
|
83 |
+
align-items: center;
|
84 |
+
gap: 8px;
|
85 |
+
}
|
86 |
+
|
87 |
+
.icon {
|
88 |
+
font-size: 1.2em;
|
89 |
+
display: inline-flex;
|
90 |
+
align-items: center;
|
91 |
+
justify-content: center;
|
92 |
+
}
|
93 |
+
|
94 |
+
.info-section, .care-section, .family-section {
|
95 |
+
display: flex;
|
96 |
+
flex-wrap: wrap;
|
97 |
+
gap: 16px;
|
98 |
+
margin-bottom: 28px; /* 增加底部間距 */
|
99 |
+
padding: 20px; /* 增加內距 */
|
100 |
+
background: #f8f9fa;
|
101 |
+
border-radius: 12px;
|
102 |
+
border: 1px solid #e1e4e8; /* 添加邊框 */
|
103 |
+
}
|
104 |
+
|
105 |
+
.info-item {
|
106 |
+
background: white; /* 改為白色背景 */
|
107 |
+
padding: 14px 18px; /* 增加內距 */
|
108 |
+
border-radius: 8px;
|
109 |
+
display: flex;
|
110 |
+
align-items: center;
|
111 |
+
gap: 10px;
|
112 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
113 |
+
border: 1px solid #e1e4e8;
|
114 |
+
flex: 1 1 auto;
|
115 |
+
min-width: 200px;
|
116 |
+
}
|
117 |
+
|
118 |
+
.label {
|
119 |
+
color: #666;
|
120 |
+
font-weight: 600;
|
121 |
+
font-size: 1.1rem;
|
122 |
+
}
|
123 |
+
|
124 |
+
.value {
|
125 |
+
color: #2c3e50;
|
126 |
+
font-weight: 500;
|
127 |
+
font-size: 1.1rem;
|
128 |
+
}
|
129 |
+
|
130 |
+
.temperament-section {
|
131 |
+
background: #f8f9fa;
|
132 |
+
padding: 20px; /* 增加內距 */
|
133 |
+
border-radius: 12px;
|
134 |
+
margin-bottom: 28px; /* 增加間距 */
|
135 |
+
color: #444;
|
136 |
+
border: 1px solid #e1e4e8; /* 添加邊框 */
|
137 |
+
}
|
138 |
+
|
139 |
+
.description-section {
|
140 |
+
background: #f8f9fa;
|
141 |
+
padding: 24px; /* 增加內距 */
|
142 |
+
border-radius: 12px;
|
143 |
+
margin: 28px 0; /* 增加上下間距 */
|
144 |
+
line-height: 1.8;
|
145 |
+
color: #444;
|
146 |
+
border: 1px solid #e1e4e8; /* 添加邊框 */
|
147 |
+
fontsize: 1.1rem;
|
148 |
+
}
|
149 |
+
.description-section p {
|
150 |
+
margin: 0;
|
151 |
+
padding: 0;
|
152 |
+
text-align: justify; /* 文字兩端對齊 */
|
153 |
+
word-wrap: break-word; /* 確保長單字會換行 */
|
154 |
+
white-space: pre-line; /* 保留換行但合併空白 */
|
155 |
+
max-width: 100%; /* 確保不會超出容器 */
|
156 |
+
}
|
157 |
+
|
158 |
+
.action-section {
|
159 |
+
margin-top: 24px;
|
160 |
+
text-align: center;
|
161 |
+
}
|
162 |
+
|
163 |
+
.akc-button,
|
164 |
+
.breed-section .akc-link,
|
165 |
+
.breed-option .akc-link {
|
166 |
+
display: inline-flex;
|
167 |
+
align-items: center;
|
168 |
+
padding: 14px 28px;
|
169 |
+
background: linear-gradient(145deg, #00509E, #003F7F);
|
170 |
+
color: white;
|
171 |
+
border-radius: 12px; /* 增加圓角 */
|
172 |
+
text-decoration: none;
|
173 |
+
gap: 12px; /* 增加圖標和文字間距 */
|
174 |
+
transition: all 0.3s ease;
|
175 |
+
font-weight: 600;
|
176 |
+
font-size: 1.1em;
|
177 |
+
box-shadow:
|
178 |
+
0 2px 4px rgba(0,0,0,0.1),
|
179 |
+
inset 0 1px 1px rgba(255,255,255,0.1);
|
180 |
+
border: 1px solid rgba(255,255,255,0.1);
|
181 |
+
}
|
182 |
+
|
183 |
+
.akc-button:hover,
|
184 |
+
.breed-section .akc-link:hover,
|
185 |
+
.breed-option .akc-link:hover {
|
186 |
+
background: linear-gradient(145deg, #003F7F, #00509E);
|
187 |
+
transform: translateY(-2px);
|
188 |
+
color: white;
|
189 |
+
box-shadow:
|
190 |
+
0 6px 12px rgba(0,0,0,0.2),
|
191 |
+
inset 0 1px 1px rgba(255,255,255,0.2);
|
192 |
+
border: 1px solid rgba(255,255,255,0.2);
|
193 |
+
}
|
194 |
+
.icon {
|
195 |
+
font-size: 1.3em;
|
196 |
+
filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2));
|
197 |
+
}
|
198 |
+
|
199 |
+
.warning-message {
|
200 |
+
display: flex;
|
201 |
+
align-items: center;
|
202 |
+
gap: 8px;
|
203 |
+
color: #ff3b30;
|
204 |
+
font-weight: 500;
|
205 |
+
margin: 0;
|
206 |
+
padding: 16px;
|
207 |
+
background: #fff5f5;
|
208 |
+
border-radius: 8px;
|
209 |
+
}
|
210 |
+
|
211 |
+
.model-uncertainty-note {
|
212 |
+
display: flex;
|
213 |
+
align-items: center;
|
214 |
+
gap: 12px;
|
215 |
+
padding: 16px;
|
216 |
+
background-color: #f8f9fa;
|
217 |
+
margin-bottom: 20px;
|
218 |
+
color: #495057;
|
219 |
+
border-radius: 4px;
|
220 |
+
}
|
221 |
+
|
222 |
+
.breeds-list {
|
223 |
+
display: flex;
|
224 |
+
flex-direction: column;
|
225 |
+
gap: 20px;
|
226 |
+
}
|
227 |
+
|
228 |
+
.breed-option {
|
229 |
+
background: white;
|
230 |
+
border: 1px solid #e1e4e8;
|
231 |
+
border-radius: 8px;
|
232 |
+
overflow: hidden;
|
233 |
+
}
|
234 |
+
|
235 |
+
.breed-header {
|
236 |
+
display: flex;
|
237 |
+
align-items: center;
|
238 |
+
padding: 16px;
|
239 |
+
background: #f8f9fa;
|
240 |
+
gap: 12px;
|
241 |
+
border-bottom: 1px solid #e1e4e8;
|
242 |
+
}
|
243 |
+
|
244 |
+
.option-number {
|
245 |
+
font-weight: 600;
|
246 |
+
color: #666;
|
247 |
+
padding: 4px 8px;
|
248 |
+
background: #e1e4e8;
|
249 |
+
border-radius: 4px;
|
250 |
+
}
|
251 |
+
|
252 |
+
.breed-name {
|
253 |
+
font-size: 1.2em !important; # 從 1.5em 改為 1.2em
|
254 |
+
font-weight: bold;
|
255 |
+
color: #2c3e50;
|
256 |
+
flex-grow: 1;
|
257 |
+
}
|
258 |
+
|
259 |
+
.confidence-badge {
|
260 |
+
padding: 4px 12px;
|
261 |
+
border-radius: 20px;
|
262 |
+
font-size: 0.9em;
|
263 |
+
font-weight: 500;
|
264 |
+
}
|
265 |
+
|
266 |
+
.breed-content {
|
267 |
+
padding: 20px;
|
268 |
+
}
|
269 |
+
.breed-content li {
|
270 |
+
margin-bottom: 8px;
|
271 |
+
display: flex;
|
272 |
+
align-items: flex-start; /* 改為頂部對齊 */
|
273 |
+
gap: 8px;
|
274 |
+
flex-wrap: wrap; /* 允許內容換行 */
|
275 |
+
}
|
276 |
+
.breed-content li strong {
|
277 |
+
flex: 0 0 auto; /* 不讓標題縮放 */
|
278 |
+
min-width: 100px; /* 給標題一個固定最小寬度 */
|
279 |
+
}
|
280 |
+
|
281 |
+
ul {
|
282 |
+
padding-left: 0;
|
283 |
+
margin: 0;
|
284 |
+
list-style-type: none;
|
285 |
+
}
|
286 |
+
|
287 |
+
li {
|
288 |
+
margin-bottom: 8px;
|
289 |
+
display: flex;
|
290 |
+
align-items: center;
|
291 |
+
gap: 8px;
|
292 |
+
}
|
293 |
+
|
294 |
+
.action-section {
|
295 |
+
margin-top: 20px;
|
296 |
+
padding: 15px;
|
297 |
+
text-align: center;
|
298 |
+
border-top: 1px solid #dee2e6;
|
299 |
+
}
|
300 |
+
|
301 |
+
.akc-button {
|
302 |
+
display: inline-block;
|
303 |
+
padding: 12px 24px;
|
304 |
+
background-color: #007bff;
|
305 |
+
color: white !important;
|
306 |
+
text-decoration: none;
|
307 |
+
border-radius: 5px;
|
308 |
+
font-weight: 500;
|
309 |
+
transition: background-color 0.3s;
|
310 |
+
}
|
311 |
+
|
312 |
+
.akc-button:hover {
|
313 |
+
background-color: #0056b3;
|
314 |
+
text-decoration: none;
|
315 |
+
}
|
316 |
+
|
317 |
+
.akc-button .icon {
|
318 |
+
margin-right: 8px;
|
319 |
+
}
|
320 |
+
|
321 |
+
.akc-link {
|
322 |
+
color: white;
|
323 |
+
text-decoration: none;
|
324 |
+
font-weight: 600;
|
325 |
+
font-size: 1.1em;
|
326 |
+
transition: all 0.3s ease;
|
327 |
+
}
|
328 |
+
|
329 |
+
.akc-link:hover {
|
330 |
+
text-decoration: underline;
|
331 |
+
color: #D3E3F0;
|
332 |
+
}
|
333 |
+
.tooltip {
|
334 |
+
position: relative;
|
335 |
+
display: inline-flex;
|
336 |
+
align-items: center;
|
337 |
+
gap: 4px;
|
338 |
+
cursor: help;
|
339 |
+
}
|
340 |
+
.tooltip .tooltip-icon {
|
341 |
+
font-size: 14px;
|
342 |
+
color: #666;
|
343 |
+
}
|
344 |
+
.tooltip .tooltip-text {
|
345 |
+
visibility: hidden;
|
346 |
+
width: 250px;
|
347 |
+
background-color: rgba(44, 62, 80, 0.95);
|
348 |
+
color: white;
|
349 |
+
text-align: left;
|
350 |
+
border-radius: 8px;
|
351 |
+
padding: 8px 10px;
|
352 |
+
position: absolute;
|
353 |
+
z-index: 100;
|
354 |
+
bottom: 150%;
|
355 |
+
left: 50%;
|
356 |
+
transform: translateX(-50%);
|
357 |
+
opacity: 0;
|
358 |
+
transition: all 0.3s ease;
|
359 |
+
font-size: 14px;
|
360 |
+
line-height: 1.3;
|
361 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
362 |
+
border: 1px solid rgba(255, 255, 255, 0.1)
|
363 |
+
margin-bottom: 10px;
|
364 |
+
}
|
365 |
+
.tooltip.tooltip-left .tooltip-text {
|
366 |
+
left: 0;
|
367 |
+
transform: translateX(0);
|
368 |
+
}
|
369 |
+
.tooltip.tooltip-right .tooltip-text {
|
370 |
+
left: auto;
|
371 |
+
right: 0;
|
372 |
+
transform: translateX(0);
|
373 |
+
}
|
374 |
+
.tooltip-text strong {
|
375 |
+
color: white !important;
|
376 |
+
background-color: transparent !important;
|
377 |
+
display: block; /* 讓標題獨立一行 */
|
378 |
+
margin-bottom: 2px; /* 增加標題下方間距 */
|
379 |
+
padding-bottom: 2px; /* 加入小間距 */
|
380 |
+
border-bottom: 1px solid rgba(255,255,255,0.2);
|
381 |
+
}
|
382 |
+
.tooltip-text {
|
383 |
+
font-size: 13px; /* 稍微縮小字體 */
|
384 |
+
}
|
385 |
+
|
386 |
+
/* 調整列表符號和文字的間距 */
|
387 |
+
.tooltip-text ul {
|
388 |
+
margin: 0;
|
389 |
+
padding-left: 15px; /* 減少列表符號的縮進 */
|
390 |
+
}
|
391 |
+
|
392 |
+
.tooltip-text li {
|
393 |
+
margin-bottom: 1px; /* 減少列表項目間的間距 */
|
394 |
+
}
|
395 |
+
.tooltip-text br {
|
396 |
+
line-height: 1.2; /* 減少行距 */
|
397 |
+
}
|
398 |
+
|
399 |
+
.tooltip .tooltip-text::after {
|
400 |
+
content: "";
|
401 |
+
position: absolute;
|
402 |
+
top: 100%;
|
403 |
+
left: 20%; /* 調整箭頭位置 */
|
404 |
+
margin-left: -5px;
|
405 |
+
border-width: 5px;
|
406 |
+
border-style: solid;
|
407 |
+
border-color: rgba(44, 62, 80, 0.95) transparent transparent transparent;
|
408 |
+
}
|
409 |
+
.tooltip-left .tooltip-text::after {
|
410 |
+
left: 20%;
|
411 |
+
}
|
412 |
+
|
413 |
+
/* 右側箭頭 */
|
414 |
+
.tooltip-right .tooltip-text::after {
|
415 |
+
left: 80%;
|
416 |
+
}
|
417 |
+
.tooltip:hover .tooltip-text {
|
418 |
+
visibility: visible;
|
419 |
+
opacity: 1;
|
420 |
+
}
|
421 |
+
.tooltip .tooltip-text::after {
|
422 |
+
content: "";
|
423 |
+
position: absolute;
|
424 |
+
top: 100%;
|
425 |
+
left: 50%;
|
426 |
+
transform: translateX(-50%);
|
427 |
+
border-width: 8px;
|
428 |
+
border-style: solid;
|
429 |
+
border-color: rgba(44, 62, 80, 0.95) transparent transparent transparent;
|
430 |
+
}
|
431 |
+
.uncertainty-mode .tooltip .tooltip-text {
|
432 |
+
position: absolute;
|
433 |
+
left: 100%;
|
434 |
+
bottom: auto;
|
435 |
+
top: 50%;
|
436 |
+
transform: translateY(-50%);
|
437 |
+
margin-left: 10px;
|
438 |
+
z-index: 1000; /* 確保提示框在最上層 */
|
439 |
+
}
|
440 |
+
|
441 |
+
.uncertainty-mode .tooltip .tooltip-text::after {
|
442 |
+
content: "";
|
443 |
+
position: absolute;
|
444 |
+
top: 50%;
|
445 |
+
right: 100%;
|
446 |
+
transform: translateY(-50%);
|
447 |
+
border-width: 5px;
|
448 |
+
border-style: solid;
|
449 |
+
border-color: transparent rgba(44, 62, 80, 0.95) transparent transparent;
|
450 |
+
}
|
451 |
+
.uncertainty-mode .breed-content {
|
452 |
+
font-size: 1rem !important; /* 增加字體大小 */
|
453 |
+
}
|
454 |
+
.description-section,
|
455 |
+
.description-section p,
|
456 |
+
.temperament-section,
|
457 |
+
.temperament-section .value,
|
458 |
+
.info-item,
|
459 |
+
.info-item .value,
|
460 |
+
.breed-content {
|
461 |
+
font-size: 1rem !important; /* 使用 !important 確保覆蓋其他樣式 */
|
462 |
+
}
|
463 |
+
|
464 |
+
.recommendation-card {
|
465 |
+
margin-bottom: 40px;
|
466 |
+
}
|
467 |
+
|
468 |
+
.compatibility-scores {
|
469 |
+
background: #f8f9fa;
|
470 |
+
padding: 24px;
|
471 |
+
border-radius: 12px;
|
472 |
+
margin: 20px 0;
|
473 |
+
}
|
474 |
+
|
475 |
+
.score-item {
|
476 |
+
margin: 15px 0;
|
477 |
+
}
|
478 |
+
|
479 |
+
.progress-bar {
|
480 |
+
height: 12px;
|
481 |
+
background-color: #e9ecef;
|
482 |
+
border-radius: 6px;
|
483 |
+
overflow: hidden;
|
484 |
+
margin: 8px 0;
|
485 |
+
}
|
486 |
+
|
487 |
+
.progress {
|
488 |
+
height: 100%;
|
489 |
+
background: linear-gradient(90deg, #34C759, #30B350);
|
490 |
+
border-radius: 6px;
|
491 |
+
transition: width 0.6s ease;
|
492 |
+
}
|
493 |
+
|
494 |
+
.percentage {
|
495 |
+
float: right;
|
496 |
+
color: #34C759;
|
497 |
+
font-weight: 600;
|
498 |
+
}
|
499 |
+
|
500 |
+
.breed-details-section {
|
501 |
+
margin: 30px 0;
|
502 |
+
}
|
503 |
+
|
504 |
+
.subsection-title {
|
505 |
+
font-size: 1.2em;
|
506 |
+
color: #2c3e50;
|
507 |
+
margin-bottom: 20px;
|
508 |
+
display: flex;
|
509 |
+
align-items: center;
|
510 |
+
gap: 8px;
|
511 |
+
}
|
512 |
+
|
513 |
+
.details-grid {
|
514 |
+
display: grid;
|
515 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
516 |
+
gap: 20px;
|
517 |
+
background: #f8f9fa;
|
518 |
+
padding: 20px;
|
519 |
+
border-radius: 12px;
|
520 |
+
border: 1px solid #e1e4e8;
|
521 |
+
}
|
522 |
+
|
523 |
+
.detail-item {
|
524 |
+
background: white;
|
525 |
+
padding: 15px;
|
526 |
+
border-radius: 8px;
|
527 |
+
border: 1px solid #e1e4e8;
|
528 |
+
}
|
529 |
+
|
530 |
+
.description-text {
|
531 |
+
line-height: 1.8;
|
532 |
+
color: #444;
|
533 |
+
margin: 0;
|
534 |
+
padding: 24px 30px; /* 調整內部間距,從 20px 改為 24px 30px */
|
535 |
+
background: #f8f9fa;
|
536 |
+
border-radius: 12px;
|
537 |
+
border: 1px solid #e1e4e8;
|
538 |
+
text-align: justify; /* 添加文字對齊 */
|
539 |
+
word-wrap: break-word; /* 確保長文字會換行 */
|
540 |
+
word-spacing: 1px; /* 加入字間距 */
|
541 |
+
}
|
542 |
+
|
543 |
+
/* 工具提示改進 */
|
544 |
+
.tooltip {
|
545 |
+
position: relative;
|
546 |
+
display: inline-flex;
|
547 |
+
align-items: center;
|
548 |
+
gap: 4px;
|
549 |
+
cursor: help;
|
550 |
+
padding: 5px 0;
|
551 |
+
}
|
552 |
+
|
553 |
+
.tooltip .tooltip-text {
|
554 |
+
visibility: hidden;
|
555 |
+
width: 280px;
|
556 |
+
background-color: rgba(44, 62, 80, 0.95);
|
557 |
+
color: white;
|
558 |
+
text-align: left;
|
559 |
+
border-radius: 8px;
|
560 |
+
padding: 12px 15px;
|
561 |
+
position: absolute;
|
562 |
+
z-index: 1000;
|
563 |
+
bottom: calc(100% + 15px);
|
564 |
+
left: 50%;
|
565 |
+
transform: translateX(-50%);
|
566 |
+
opacity: 0;
|
567 |
+
transition: all 0.3s ease;
|
568 |
+
font-size: 14px;
|
569 |
+
line-height: 1.4;
|
570 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
571 |
+
white-space: normal;
|
572 |
+
}
|
573 |
+
|
574 |
+
.tooltip:hover .tooltip-text {
|
575 |
+
visibility: visible;
|
576 |
+
opacity: 1;
|
577 |
+
}
|
578 |
+
|
579 |
+
.score-badge {
|
580 |
+
background-color: #34C759;
|
581 |
+
color: white;
|
582 |
+
padding: 6px 12px;
|
583 |
+
border-radius: 20px;
|
584 |
+
font-size: 0.9em;
|
585 |
+
margin-left: 10px;
|
586 |
+
font-weight: 500;
|
587 |
+
box-shadow: 0 2px 4px rgba(52, 199, 89, 0.2);
|
588 |
+
}
|
589 |
+
|
590 |
+
.bonus-score .tooltip-text {
|
591 |
+
width: 250px;
|
592 |
+
line-height: 1.4;
|
593 |
+
padding: 10px;
|
594 |
+
}
|
595 |
+
|
596 |
+
.bonus-score .progress {
|
597 |
+
background: linear-gradient(90deg, #48bb78, #68d391);
|
598 |
+
}
|
599 |
+
|
600 |
+
.health-section {
|
601 |
+
margin: 25px 0;
|
602 |
+
padding: 24px;
|
603 |
+
background-color: #f8f9fb;
|
604 |
+
border-radius: 12px;
|
605 |
+
border: 1px solid #e1e4e8;
|
606 |
+
}
|
607 |
+
|
608 |
+
.health-section .subsection-title {
|
609 |
+
font-size: 1.3em;
|
610 |
+
font-weight: 600;
|
611 |
+
margin-bottom: 20px;
|
612 |
+
display: flex;
|
613 |
+
align-items: center;
|
614 |
+
gap: 8px;
|
615 |
+
color: #2c3e50;
|
616 |
+
}
|
617 |
+
|
618 |
+
.health-info {
|
619 |
+
background-color: white;
|
620 |
+
padding: 24px;
|
621 |
+
border-radius: 8px;
|
622 |
+
margin: 15px 0;
|
623 |
+
border: 1px solid #e1e4e8;
|
624 |
+
}
|
625 |
+
|
626 |
+
.health-details {
|
627 |
+
font-size: 1.1rem;
|
628 |
+
line-height: 1.6;
|
629 |
+
}
|
630 |
+
|
631 |
+
.health-details h4 {
|
632 |
+
color: #2c3e50;
|
633 |
+
font-size: 1.15rem;
|
634 |
+
font-weight: 600;
|
635 |
+
margin: 20px 0 15px 0;
|
636 |
+
}
|
637 |
+
|
638 |
+
.health-details h4:first-child {
|
639 |
+
margin-top: 0;
|
640 |
+
}
|
641 |
+
|
642 |
+
.health-details ul {
|
643 |
+
list-style-type: none;
|
644 |
+
padding-left: 0;
|
645 |
+
margin: 0 0 25px 0;
|
646 |
+
}
|
647 |
+
|
648 |
+
.health-details ul li {
|
649 |
+
margin-bottom: 12px;
|
650 |
+
padding-left: 20px;
|
651 |
+
position: relative;
|
652 |
+
}
|
653 |
+
|
654 |
+
.health-details ul li:before {
|
655 |
+
content: "•";
|
656 |
+
position: absolute;
|
657 |
+
left: 0;
|
658 |
+
color: #2c3e50;
|
659 |
+
}
|
660 |
+
|
661 |
+
.health-item:before {
|
662 |
+
content: "•";
|
663 |
+
color: #dc3545;
|
664 |
+
font-weight: bold;
|
665 |
+
}
|
666 |
+
|
667 |
+
.health-item.screening:before {
|
668 |
+
color: #28a745;
|
669 |
+
}
|
670 |
+
|
671 |
+
/* 區塊間距 */
|
672 |
+
.health-block, .noise-block {
|
673 |
+
margin-bottom: 24px;
|
674 |
+
}
|
675 |
+
|
676 |
+
.health-disclaimer {
|
677 |
+
margin-top: 20px;
|
678 |
+
padding-top: 20px;
|
679 |
+
border-top: 1px solid #e1e4e8;
|
680 |
+
}
|
681 |
+
|
682 |
+
.health-disclaimer p {
|
683 |
+
margin: 6px 0;
|
684 |
+
padding-left: 20px;
|
685 |
+
position: relative;
|
686 |
+
color: #888; /* 統一設定灰色 */
|
687 |
+
font-size: 0.95rem;
|
688 |
+
line-height: 1.5;
|
689 |
+
font-style: italic;
|
690 |
+
}
|
691 |
+
|
692 |
+
.health-disclaimer p:before {
|
693 |
+
content: "›";
|
694 |
+
position: absolute;
|
695 |
+
left: 0;
|
696 |
+
color: #999;
|
697 |
+
font-style: normal;
|
698 |
+
font-weight: 500;
|
699 |
+
}
|
700 |
+
|
701 |
+
.health-disclaimer p:first-child {
|
702 |
+
font-style: normal; /* 取消斜體 */
|
703 |
+
font-weight: 500; /* 加粗 */
|
704 |
+
color: #666; /* 稍深的灰色 */
|
705 |
+
}
|
706 |
+
|
707 |
+
.health-disclaimer p span,
|
708 |
+
.health-disclaimer p strong,
|
709 |
+
.health-disclaimer p em {
|
710 |
+
color: inherit;
|
711 |
+
}
|
712 |
+
|
713 |
+
.health-list li:before {
|
714 |
+
content: "•";
|
715 |
+
color: #dc3545;
|
716 |
+
}
|
717 |
+
|
718 |
+
.history-container {
|
719 |
+
max-width: 800px;
|
720 |
+
margin: 0 auto;
|
721 |
+
padding: 20px;
|
722 |
+
}
|
723 |
+
|
724 |
+
.history-entry {
|
725 |
+
background-color: #f8f9fa;
|
726 |
+
border-radius: 8px;
|
727 |
+
padding: 15px;
|
728 |
+
margin-bottom: 20px;
|
729 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
730 |
+
}
|
731 |
+
|
732 |
+
.history-header {
|
733 |
+
display: flex;
|
734 |
+
justify-content: space-between;
|
735 |
+
align-items: center;
|
736 |
+
margin-bottom: 10px;
|
737 |
+
padding-bottom: 10px;
|
738 |
+
border-bottom: 1px solid #eee;
|
739 |
+
}
|
740 |
+
|
741 |
+
.timestamp {
|
742 |
+
color: #666;
|
743 |
+
font-size: 0.9em;
|
744 |
+
}
|
745 |
+
|
746 |
+
.delete-btn {
|
747 |
+
background: none;
|
748 |
+
border: none;
|
749 |
+
cursor: pointer;
|
750 |
+
font-size: 1.2em;
|
751 |
+
padding: 5px;
|
752 |
+
}
|
753 |
+
|
754 |
+
.delete-btn:hover {
|
755 |
+
color: #dc3545;
|
756 |
+
}
|
757 |
+
|
758 |
+
.search-params ul {
|
759 |
+
list-style: none;
|
760 |
+
padding-left: 20px;
|
761 |
+
}
|
762 |
+
|
763 |
+
.search-params li {
|
764 |
+
margin: 5px 0;
|
765 |
+
color: #555;
|
766 |
+
}
|
767 |
+
|
768 |
+
.top-results ol {
|
769 |
+
padding-left: 25px;
|
770 |
+
}
|
771 |
+
|
772 |
+
.top-results li {
|
773 |
+
margin: 5px 0;
|
774 |
+
color: #333;
|
775 |
+
}
|
776 |
+
|
777 |
+
.breed-item {
|
778 |
+
display: flex;
|
779 |
+
justify-content: space-between;
|
780 |
+
align-items: center;
|
781 |
+
padding: 12px 16px;
|
782 |
+
margin: 8px 0;
|
783 |
+
background-color: white;
|
784 |
+
border-radius: 6px;
|
785 |
+
border: 1px solid #e1e4e8;
|
786 |
+
transition: all 0.2s ease;
|
787 |
+
}
|
788 |
+
|
789 |
+
.breed-item:hover {
|
790 |
+
transform: translateX(5px);
|
791 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
792 |
+
}
|
793 |
+
|
794 |
+
.breed-rank {
|
795 |
+
font-weight: 600;
|
796 |
+
color: #666;
|
797 |
+
margin-right: 12px;
|
798 |
+
min-width: 30px;
|
799 |
+
}
|
800 |
+
|
801 |
+
.breed-name {
|
802 |
+
flex: 1;
|
803 |
+
font-weight: 500;
|
804 |
+
color: #2c3e50;
|
805 |
+
padding: 0 12px;
|
806 |
+
}
|
807 |
+
|
808 |
+
.breed-score {
|
809 |
+
font-weight: 600;
|
810 |
+
color: #34C759;
|
811 |
+
padding: 4px 8px;
|
812 |
+
border-radius: 20px;
|
813 |
+
background-color: rgba(52, 199, 89, 0.1);
|
814 |
+
min-width: 70px;
|
815 |
+
text-align: center;
|
816 |
+
}
|
817 |
+
|
818 |
+
.history-entry {
|
819 |
+
background-color: #f8f9fa;
|
820 |
+
border-radius: 12px;
|
821 |
+
padding: 20px;
|
822 |
+
margin-bottom: 25px;
|
823 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
824 |
+
border: 1px solid #e1e4e8;
|
825 |
+
}
|
826 |
+
|
827 |
+
.history-header {
|
828 |
+
margin-bottom: 15px;
|
829 |
+
padding-bottom: 12px;
|
830 |
+
border-bottom: 1px solid #e1e4e8;
|
831 |
+
}
|
832 |
+
|
833 |
+
.history-header .timestamp {
|
834 |
+
color: #666;
|
835 |
+
font-size: 0.9em;
|
836 |
+
display: flex;
|
837 |
+
align-items: center;
|
838 |
+
gap: 6px;
|
839 |
+
}
|
840 |
+
|
841 |
+
h4 {
|
842 |
+
color: #2c3e50;
|
843 |
+
font-size: 1.15rem;
|
844 |
+
font-weight: 600;
|
845 |
+
margin: 20px 0 12px 0;
|
846 |
+
}
|
847 |
+
|
848 |
+
.params-list ul {
|
849 |
+
list-style: none;
|
850 |
+
padding-left: 0;
|
851 |
+
margin: 10px 0;
|
852 |
+
}
|
853 |
+
|
854 |
+
.params-list li {
|
855 |
+
margin: 8px 0;
|
856 |
+
color: #4a5568;
|
857 |
+
display: flex;
|
858 |
+
align-items: center;
|
859 |
+
}
|
860 |
+
|
861 |
+
.empty-history {
|
862 |
+
text-align: center;
|
863 |
+
padding: 40px 20px;
|
864 |
+
color: #666;
|
865 |
+
font-size: 1.1em;
|
866 |
+
background-color: #f8f9fa;
|
867 |
+
border-radius: 12px;
|
868 |
+
border: 1px dashed #e1e4e8;
|
869 |
+
margin: 20px 0;
|
870 |
+
}
|
871 |
+
|
872 |
+
.noise-section {
|
873 |
+
margin: 25px 0;
|
874 |
+
padding: 24px;
|
875 |
+
background-color: #f8f9fb;
|
876 |
+
border-radius: 12px;
|
877 |
+
border: 1px solid #e1e4e8;
|
878 |
+
}
|
879 |
+
|
880 |
+
.noise-info {
|
881 |
+
background-color: white;
|
882 |
+
padding: 24px;
|
883 |
+
border-radius: 8px;
|
884 |
+
margin: 15px 0;
|
885 |
+
border: 1px solid #e1e4e8;
|
886 |
+
}
|
887 |
+
|
888 |
+
.noise-details {
|
889 |
+
font-size: 1.1rem;
|
890 |
+
line-height: 1.6;
|
891 |
+
}
|
892 |
+
|
893 |
+
.noise-level {
|
894 |
+
margin-bottom: 20px;
|
895 |
+
padding: 10px 15px;
|
896 |
+
background: #f8f9fa;
|
897 |
+
border-radius: 6px;
|
898 |
+
font-weight: 500;
|
899 |
+
}
|
900 |
+
|
901 |
+
.noise-level-block {
|
902 |
+
background: #f8f9fa;
|
903 |
+
padding: 20px;
|
904 |
+
border-radius: 8px;
|
905 |
+
margin: 20px 0;
|
906 |
+
}
|
907 |
+
|
908 |
+
.noise-level-display {
|
909 |
+
background: #f8f9fa;
|
910 |
+
padding: 16px;
|
911 |
+
border-radius: 8px;
|
912 |
+
margin: 16px 0;
|
913 |
+
}
|
914 |
+
|
915 |
+
.level-indicator {
|
916 |
+
background: white;
|
917 |
+
padding: 12px 16px;
|
918 |
+
border-radius: 8px;
|
919 |
+
border: 1px solid #e1e4e8;
|
920 |
+
display: flex;
|
921 |
+
align-items: center;
|
922 |
+
justify-content: space-between;
|
923 |
+
}
|
924 |
+
|
925 |
+
.level-text {
|
926 |
+
font-weight: 500;
|
927 |
+
color: #2c3e50;
|
928 |
+
}
|
929 |
+
|
930 |
+
.level-bars {
|
931 |
+
display: flex;
|
932 |
+
gap: 4px;
|
933 |
+
}
|
934 |
+
|
935 |
+
.level-bars .bar {
|
936 |
+
width: 4px;
|
937 |
+
height: 16px;
|
938 |
+
background: #e9ecef;
|
939 |
+
border-radius: 2px;
|
940 |
+
}
|
941 |
+
|
942 |
+
.level-indicator.low .bar:nth-child(1) {
|
943 |
+
background: #4CAF50;
|
944 |
+
}
|
945 |
+
|
946 |
+
.level-indicator.medium .bar:nth-child(1),
|
947 |
+
.level-indicator.medium .bar:nth-child(2) {
|
948 |
+
background: #FFA726;
|
949 |
+
}
|
950 |
+
|
951 |
+
.level-indicator.high .bar {
|
952 |
+
background: #EF5350;
|
953 |
+
}
|
954 |
+
|
955 |
+
.feature-list, .health-list, .screening-list {
|
956 |
+
list-style: none;
|
957 |
+
padding: 0;
|
958 |
+
margin: 16px 0;
|
959 |
+
display: grid;
|
960 |
+
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
961 |
+
gap: 12px;
|
962 |
+
}
|
963 |
+
|
964 |
+
.feature-list li, .health-list li, .screening-list li {
|
965 |
+
background: white;
|
966 |
+
padding: 12px 16px;
|
967 |
+
border-radius: 6px;
|
968 |
+
border: 1px solid #e1e4e8;
|
969 |
+
display: flex;
|
970 |
+
align-items: center;
|
971 |
+
gap: 8px;
|
972 |
+
font-size: 0.95rem;
|
973 |
+
}
|
974 |
+
|
975 |
+
.feature-list li:before {
|
976 |
+
content: "•";
|
977 |
+
color: #2c3e50;
|
978 |
+
}
|
979 |
+
|
980 |
+
.noise-notes {
|
981 |
+
font-family: inherit;
|
982 |
+
white-space: pre-wrap;
|
983 |
+
margin: 15px 0;
|
984 |
+
padding: 0;
|
985 |
+
background: transparent;
|
986 |
+
border: none;
|
987 |
+
font-size: 1.1rem;
|
988 |
+
line-height: 1.6;
|
989 |
+
color: #333;
|
990 |
+
}
|
991 |
+
|
992 |
+
.characteristics-block, .health-considerations, .health-screenings {
|
993 |
+
margin-bottom: 24px;
|
994 |
+
}
|
995 |
+
|
996 |
+
.characteristics-block h4, .health-considerations h4, .health-screenings h4 {
|
997 |
+
color: #2c3e50;
|
998 |
+
font-size: 1.1em;
|
999 |
+
font-weight: 600;
|
1000 |
+
margin-bottom: 12px;
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
.characteristics-list,
|
1004 |
+
.triggers-list,
|
1005 |
+
.health-considerations-list,
|
1006 |
+
.health-screenings-list {
|
1007 |
+
display: grid;
|
1008 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
1009 |
+
gap: 12px;
|
1010 |
+
margin: 16px 0;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
.noise-details, .health-details {
|
1014 |
+
font-size: 1.1rem;
|
1015 |
+
line-height: 1.6;
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
.noise-details ul, .health-details ul {
|
1019 |
+
list-style: none;
|
1020 |
+
padding-left: 0;
|
1021 |
+
margin: 0 0 20px 0;
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
.noise-details li, .health-details li {
|
1025 |
+
padding-left: 20px;
|
1026 |
+
position: relative;
|
1027 |
+
margin-bottom: 10px;
|
1028 |
+
line-height: 1.5;
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
.noise-details li:before, .health-details li:before {
|
1032 |
+
content: "•";
|
1033 |
+
position: absolute;
|
1034 |
+
left: 0;
|
1035 |
+
color: #666;
|
1036 |
+
}
|
1037 |
+
|
1038 |
+
.noise-section, .health-section {
|
1039 |
+
margin: 25px 0;
|
1040 |
+
padding: 24px;
|
1041 |
+
background-color: #f8f9fb;
|
1042 |
+
border-radius: 12px;
|
1043 |
+
border: 1px solid #e1e4e8;
|
1044 |
+
}
|
1045 |
+
|
1046 |
+
.noise-info, .health-info {
|
1047 |
+
background-color: white;
|
1048 |
+
padding: 24px;
|
1049 |
+
border-radius: 8px;
|
1050 |
+
margin: 15px 0;
|
1051 |
+
border: 1px solid #e1e4e8;
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
.breed-info .description-tooltip {
|
1055 |
+
position: relative;
|
1056 |
+
display: inline-flex;
|
1057 |
+
align-items: center;
|
1058 |
+
gap: 4px;
|
1059 |
+
cursor: help;
|
1060 |
+
}
|
1061 |
+
|
1062 |
+
.description-tooltip .tooltip-icon {
|
1063 |
+
font-size: 14px;
|
1064 |
+
color: #666;
|
1065 |
+
margin-left: 4px;
|
1066 |
+
cursor: help;
|
1067 |
+
}
|
1068 |
+
|
1069 |
+
.description-tooltip .tooltip-text {
|
1070 |
+
visibility: hidden;
|
1071 |
+
width: 280px;
|
1072 |
+
background-color: rgba(44, 62, 80, 0.95);
|
1073 |
+
color: white;
|
1074 |
+
text-align: left;
|
1075 |
+
border-radius: 8px;
|
1076 |
+
padding: 12px 15px;
|
1077 |
+
position: absolute;
|
1078 |
+
z-index: 1000;
|
1079 |
+
bottom: calc(100% + 15px);
|
1080 |
+
left: 50%;
|
1081 |
+
transform: translateX(-50%);
|
1082 |
+
opacity: 0;
|
1083 |
+
transition: all 0.3s ease;
|
1084 |
+
font-size: 14px;
|
1085 |
+
line-height: 1.4;
|
1086 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
1087 |
+
white-space: normal;
|
1088 |
+
}
|
1089 |
+
|
1090 |
+
.description-tooltip:hover .tooltip-text {
|
1091 |
+
visibility: visible;
|
1092 |
+
opacity: 1;
|
1093 |
+
}
|
1094 |
+
|
1095 |
+
.description-tooltip .tooltip-text::after {
|
1096 |
+
content: "";
|
1097 |
+
position: absolute;
|
1098 |
+
top: 100%;
|
1099 |
+
left: 50%;
|
1100 |
+
transform: translateX(-50%);
|
1101 |
+
border-width: 8px;
|
1102 |
+
border-style: solid;
|
1103 |
+
border-color: rgba(44, 62, 80, 0.95) transparent transparent transparent;
|
1104 |
+
}
|
1105 |
+
|
1106 |
+
.description-header {
|
1107 |
+
display: flex;
|
1108 |
+
align-items: center;
|
1109 |
+
gap: 8px;
|
1110 |
+
margin-bottom: 10px;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
.description-header h3 {
|
1114 |
+
margin: 0;
|
1115 |
+
font-size: 1.2em;
|
1116 |
+
color: #2c3e50;
|
1117 |
+
}
|
1118 |
+
|
1119 |
+
.screening-list li:before {
|
1120 |
+
content: "•";
|
1121 |
+
color: #28a745;
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
.noise-disclaimer, .health-disclaimer {
|
1125 |
+
margin-top: 20px;
|
1126 |
+
padding-top: 20px;
|
1127 |
+
border-top: 1px solid #e1e4e8;
|
1128 |
+
color: #666;
|
1129 |
+
}
|
1130 |
+
|
1131 |
+
.noise-disclaimer p, .health-disclaimer p {
|
1132 |
+
margin: 8px 0;
|
1133 |
+
padding-left: 20px;
|
1134 |
+
position: relative;
|
1135 |
+
}
|
1136 |
+
|
1137 |
+
.noise-disclaimer p:before, .health-disclaimer p:before {
|
1138 |
+
content: "›";
|
1139 |
+
position: absolute;
|
1140 |
+
left: 0;
|
1141 |
+
color: #999;
|
1142 |
+
}
|
1143 |
+
|
1144 |
+
.disclaimer-text {
|
1145 |
+
margin: 8px 0;
|
1146 |
+
padding-left: 20px;
|
1147 |
+
position: relative;
|
1148 |
+
font-size: 0.95rem;
|
1149 |
+
line-height: 1.5;
|
1150 |
+
font-style: italic;
|
1151 |
+
color: #888;
|
1152 |
+
}
|
1153 |
+
|
1154 |
+
.disclaimer-text:before {
|
1155 |
+
content: "›";
|
1156 |
+
position: absolute;
|
1157 |
+
left: 0;
|
1158 |
+
color: #999;
|
1159 |
+
font-style: normal;
|
1160 |
+
font-weight: 500;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
.list-item {
|
1164 |
+
background: white;
|
1165 |
+
padding: 12px 16px;
|
1166 |
+
border-radius: 8px;
|
1167 |
+
border: 1px solid #e1e4e8;
|
1168 |
+
display: flex;
|
1169 |
+
align-items: center;
|
1170 |
+
gap: 8px;
|
1171 |
+
margin: 4px 0;
|
1172 |
+
font-size: 0.95rem;
|
1173 |
+
color: #2c3e50;
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
.source-text {
|
1177 |
+
font-style: normal !important;
|
1178 |
+
font-weight: 500 !important;
|
1179 |
+
color: #666 !important;
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
.health-grid, .noise-grid {
|
1183 |
+
display: grid;
|
1184 |
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
1185 |
+
gap: 12px;
|
1186 |
+
margin: 16px 0;
|
1187 |
+
}
|
1188 |
+
|
1189 |
+
.health-item, .noise-item {
|
1190 |
+
background: white;
|
1191 |
+
padding: 12px 16px;
|
1192 |
+
border-radius: 8px;
|
1193 |
+
border: 1px solid #e1e4e8;
|
1194 |
+
display: flex;
|
1195 |
+
align-items: center;
|
1196 |
+
gap: 8px;
|
1197 |
+
transition: all 0.2s ease;
|
1198 |
+
}
|
1199 |
+
|
1200 |
+
.health-item:hover, .noise-item:hover {
|
1201 |
+
transform: translateY(-1px);
|
1202 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
1203 |
+
}
|
1204 |
+
|
1205 |
+
@media (max-width: 768px) {
|
1206 |
+
/* 在小螢幕上改為單列顯示 */
|
1207 |
+
.health-grid, .noise-grid {
|
1208 |
+
grid-template-columns: 1fr;
|
1209 |
+
}
|
1210 |
+
|
1211 |
+
/* 減少內邊距 */
|
1212 |
+
.health-section, .noise-section {
|
1213 |
+
padding: 16px;
|
1214 |
+
}
|
1215 |
+
|
1216 |
+
/* 調整字體大小 */
|
1217 |
+
.section-header {
|
1218 |
+
font-size: 1rem;
|
1219 |
+
}
|
1220 |
+
|
1221 |
+
/* 調整項目內邊距 */
|
1222 |
+
.health-item, .noise-item {
|
1223 |
+
padding: 10px 14px;
|
1224 |
+
}
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
/* 較小的手機螢幕 */
|
1228 |
+
@media (max-width: 480px) {
|
1229 |
+
.health-grid, .noise-grid {
|
1230 |
+
gap: 8px;
|
1231 |
+
}
|
1232 |
+
|
1233 |
+
.health-item, .noise-item {
|
1234 |
+
padding: 8px 12px;
|
1235 |
+
font-size: 0.9rem;
|
1236 |
+
}
|
1237 |
+
}
|
1238 |
+
"""
|