DawnC commited on
Commit
7d577f9
1 Parent(s): 052b7e7

Delete html_templates.py

Browse files
Files changed (1) hide show
  1. html_templates.py +0 -600
html_templates.py DELETED
@@ -1,600 +0,0 @@
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
- """