Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse filesupdate button visualization, hint information
- breed_recommendation.py +1 -252
breed_recommendation.py
CHANGED
|
@@ -326,255 +326,4 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 326 |
'noise_tolerance': noise_tolerance,
|
| 327 |
'get_recommendations_btn': get_recommendations_btn,
|
| 328 |
'recommendation_output': recommendation_output,
|
| 329 |
-
}
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
# def create_recommendation_tab(UserPreferences, get_breed_recommendations, format_recommendation_html, history_component):
|
| 334 |
-
|
| 335 |
-
# with gr.TabItem("Breed Recommendation"):
|
| 336 |
-
# with gr.Tabs():
|
| 337 |
-
# with gr.Tab("Find by Criteria"):
|
| 338 |
-
# gr.HTML("""
|
| 339 |
-
# <div style='
|
| 340 |
-
# text-align: center;
|
| 341 |
-
# position: relative;
|
| 342 |
-
# padding: 20px 0;
|
| 343 |
-
# margin: 15px 0;
|
| 344 |
-
# background: linear-gradient(to right, rgba(66, 153, 225, 0.1), rgba(72, 187, 120, 0.1));
|
| 345 |
-
# border-radius: 10px;
|
| 346 |
-
# '>
|
| 347 |
-
# <!-- BETA 標籤 -->
|
| 348 |
-
# <div style='
|
| 349 |
-
# position: absolute;
|
| 350 |
-
# top: 10px;
|
| 351 |
-
# right: 20px;
|
| 352 |
-
# background: linear-gradient(90deg, #4299e1, #48bb78);
|
| 353 |
-
# color: white;
|
| 354 |
-
# padding: 4px 12px;
|
| 355 |
-
# border-radius: 15px;
|
| 356 |
-
# font-size: 0.85em;
|
| 357 |
-
# font-weight: 600;
|
| 358 |
-
# letter-spacing: 1px;
|
| 359 |
-
# box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 360 |
-
# '>BETA</div>
|
| 361 |
-
|
| 362 |
-
# <!-- 主標題 -->
|
| 363 |
-
# <p style='
|
| 364 |
-
# font-size: 1.2em;
|
| 365 |
-
# margin: 0;
|
| 366 |
-
# padding: 0 20px;
|
| 367 |
-
# line-height: 1.5;
|
| 368 |
-
# background: linear-gradient(90deg, #4299e1, #48bb78);
|
| 369 |
-
# -webkit-background-clip: text;
|
| 370 |
-
# -webkit-text-fill-color: transparent;
|
| 371 |
-
# font-weight: 600;
|
| 372 |
-
# '>
|
| 373 |
-
# Tell us about your lifestyle, and we'll recommend the perfect dog breeds for you!
|
| 374 |
-
# </p>
|
| 375 |
-
|
| 376 |
-
# <!-- 提示訊息 -->
|
| 377 |
-
# <div style='
|
| 378 |
-
# margin-top: 15px;
|
| 379 |
-
# padding: 10px 20px;
|
| 380 |
-
# background: linear-gradient(to right, rgba(66, 153, 225, 0.15), rgba(72, 187, 120, 0.15));
|
| 381 |
-
# border-radius: 8px;
|
| 382 |
-
# font-size: 0.9em;
|
| 383 |
-
# color: #2D3748;
|
| 384 |
-
# display: flex;
|
| 385 |
-
# align-items: center;
|
| 386 |
-
# justify-content: center;
|
| 387 |
-
# gap: 8px;
|
| 388 |
-
# '>
|
| 389 |
-
# <span style="font-size: 1.2em;">🔬</span>
|
| 390 |
-
# <span style="
|
| 391 |
-
# letter-spacing: 0.3px;
|
| 392 |
-
# line-height: 1.4;
|
| 393 |
-
# "><strong>Beta Feature:</strong> Our matching algorithm is continuously improving. Results are for reference only.</span>
|
| 394 |
-
# </div>
|
| 395 |
-
# </div>
|
| 396 |
-
# """)
|
| 397 |
-
|
| 398 |
-
# with gr.Row():
|
| 399 |
-
# with gr.Column():
|
| 400 |
-
# living_space = gr.Radio(
|
| 401 |
-
# choices=["apartment", "house_small", "house_large"],
|
| 402 |
-
# label="What type of living space do you have?",
|
| 403 |
-
# info="Choose your current living situation",
|
| 404 |
-
# value="apartment"
|
| 405 |
-
# )
|
| 406 |
-
|
| 407 |
-
# yard_access = gr.Radio(
|
| 408 |
-
# choices=["no_yard", "shared_yard", "private_yard"],
|
| 409 |
-
# label="Yard Access Type",
|
| 410 |
-
# info="Available outdoor space",
|
| 411 |
-
# value="no_yard"
|
| 412 |
-
# )
|
| 413 |
-
|
| 414 |
-
# exercise_time = gr.Slider(
|
| 415 |
-
# minimum=0,
|
| 416 |
-
# maximum=180,
|
| 417 |
-
# value=60,
|
| 418 |
-
# label="Daily exercise time (minutes)",
|
| 419 |
-
# info="Consider walks, play time, and training"
|
| 420 |
-
# )
|
| 421 |
-
|
| 422 |
-
# exercise_type = gr.Radio(
|
| 423 |
-
# choices=["light_walks", "moderate_activity", "active_training"],
|
| 424 |
-
# label="Exercise Style",
|
| 425 |
-
# info="What kind of activities do you prefer?",
|
| 426 |
-
# value="moderate_activity"
|
| 427 |
-
# )
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
# grooming_commitment = gr.Radio(
|
| 431 |
-
# choices=["low", "medium", "high"],
|
| 432 |
-
# label="Grooming commitment level",
|
| 433 |
-
# info="Low: monthly, Medium: weekly, High: daily",
|
| 434 |
-
# value="medium"
|
| 435 |
-
# )
|
| 436 |
-
|
| 437 |
-
# with gr.Column():
|
| 438 |
-
# size_preference = gr.Radio(
|
| 439 |
-
# choices=["no_preference", "small", "medium", "large", "giant"],
|
| 440 |
-
# label="Preference Dog Size",
|
| 441 |
-
# info="Select your preferred dog size - this will strongly filter the recommendations",
|
| 442 |
-
# value = "no_preference"
|
| 443 |
-
# )
|
| 444 |
-
# experience_level = gr.Radio(
|
| 445 |
-
# choices=["beginner", "intermediate", "advanced"],
|
| 446 |
-
# label="Dog ownership experience",
|
| 447 |
-
# info="Be honest - this helps find the right match",
|
| 448 |
-
# value="beginner"
|
| 449 |
-
# )
|
| 450 |
-
|
| 451 |
-
# time_availability = gr.Radio(
|
| 452 |
-
# choices=["limited", "moderate", "flexible"],
|
| 453 |
-
# label="Time Availability",
|
| 454 |
-
# info="Time available for dog care daily",
|
| 455 |
-
# value="moderate"
|
| 456 |
-
# )
|
| 457 |
-
|
| 458 |
-
# has_children = gr.Checkbox(
|
| 459 |
-
# label="Have children at home",
|
| 460 |
-
# info="Helps recommend child-friendly breeds"
|
| 461 |
-
# )
|
| 462 |
-
|
| 463 |
-
# children_age = gr.Radio(
|
| 464 |
-
# choices=["toddler", "school_age", "teenager"],
|
| 465 |
-
# label="Children's Age Group",
|
| 466 |
-
# info="Helps match with age-appropriate breeds",
|
| 467 |
-
# visible=False # 默認隱藏,只在has_children=True時顯示
|
| 468 |
-
# )
|
| 469 |
-
|
| 470 |
-
# noise_tolerance = gr.Radio(
|
| 471 |
-
# choices=["low", "medium", "high"],
|
| 472 |
-
# label="Noise tolerance level",
|
| 473 |
-
# info="Some breeds are more vocal than others",
|
| 474 |
-
# value="medium"
|
| 475 |
-
# )
|
| 476 |
-
|
| 477 |
-
# def update_children_age_visibility(has_children):
|
| 478 |
-
# return gr.update(visible=has_children)
|
| 479 |
-
|
| 480 |
-
# has_children.change(
|
| 481 |
-
# fn=update_children_age_visibility,
|
| 482 |
-
# inputs=has_children,
|
| 483 |
-
# outputs=children_age
|
| 484 |
-
# )
|
| 485 |
-
|
| 486 |
-
# get_recommendations_btn = gr.Button("Find My Perfect Match! 🔍", variant="primary")
|
| 487 |
-
|
| 488 |
-
# recommendation_output = gr.HTML(
|
| 489 |
-
# label="Breed Recommendations",
|
| 490 |
-
# visible=True, # 確保可見性
|
| 491 |
-
# elem_id="recommendation-output"
|
| 492 |
-
# )
|
| 493 |
-
|
| 494 |
-
# def on_find_match_click(*args):
|
| 495 |
-
# try:
|
| 496 |
-
# user_prefs = UserPreferences(
|
| 497 |
-
# living_space=args[0],
|
| 498 |
-
# yard_access=args[1],
|
| 499 |
-
# exercise_time=args[2],
|
| 500 |
-
# exercise_type=args[3],
|
| 501 |
-
# grooming_commitment=args[4],
|
| 502 |
-
# size_preference=args[5],
|
| 503 |
-
# experience_level=args[6],
|
| 504 |
-
# time_availability=args[7],
|
| 505 |
-
# has_children=args[8],
|
| 506 |
-
# children_age=args[9] if args[8] else None,
|
| 507 |
-
# noise_tolerance=args[10],
|
| 508 |
-
# space_for_play=True if args[0] != "apartment" else False,
|
| 509 |
-
# other_pets=False,
|
| 510 |
-
# climate="moderate",
|
| 511 |
-
# health_sensitivity="medium",
|
| 512 |
-
# barking_acceptance=args[10]
|
| 513 |
-
# )
|
| 514 |
-
|
| 515 |
-
# recommendations = get_breed_recommendations(user_prefs, top_n=15)
|
| 516 |
-
|
| 517 |
-
# history_results = [{
|
| 518 |
-
# 'breed': rec['breed'],
|
| 519 |
-
# 'rank': rec['rank'],
|
| 520 |
-
# 'overall_score': rec['final_score'],
|
| 521 |
-
# 'base_score': rec['base_score'],
|
| 522 |
-
# 'bonus_score': rec['bonus_score'],
|
| 523 |
-
# 'scores': rec['scores']
|
| 524 |
-
# } for rec in recommendations]
|
| 525 |
-
|
| 526 |
-
# history_component.save_search(
|
| 527 |
-
# user_preferences={
|
| 528 |
-
# 'living_space': args[0],
|
| 529 |
-
# 'yard_access': args[1],
|
| 530 |
-
# 'exercise_time': args[2],
|
| 531 |
-
# 'exercise_type': args[3],
|
| 532 |
-
# 'grooming_commitment': args[4],
|
| 533 |
-
# 'size_preference': args[5],
|
| 534 |
-
# 'experience_level': args[6],
|
| 535 |
-
# 'time_availability': args[7],
|
| 536 |
-
# 'has_children': args[8],
|
| 537 |
-
# 'children_age': args[9] if args[8] else None,
|
| 538 |
-
# 'noise_tolerance': args[10],
|
| 539 |
-
# 'search_type': 'Criteria'
|
| 540 |
-
# },
|
| 541 |
-
# results=history_results
|
| 542 |
-
# )
|
| 543 |
-
|
| 544 |
-
# return format_recommendation_html(recommendations, is_description_search=False)
|
| 545 |
-
|
| 546 |
-
# except Exception as e:
|
| 547 |
-
# print(f"Error in find match: {str(e)}")
|
| 548 |
-
# import traceback
|
| 549 |
-
# print(traceback.format_exc())
|
| 550 |
-
# return "Error getting recommendations"
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
# get_recommendations_btn.click(
|
| 554 |
-
# fn=on_find_match_click,
|
| 555 |
-
# inputs=[
|
| 556 |
-
# living_space,
|
| 557 |
-
# yard_access,
|
| 558 |
-
# exercise_time,
|
| 559 |
-
# exercise_type,
|
| 560 |
-
# grooming_commitment,
|
| 561 |
-
# size_preference,
|
| 562 |
-
# experience_level,
|
| 563 |
-
# time_availability,
|
| 564 |
-
# has_children,
|
| 565 |
-
# children_age,
|
| 566 |
-
# noise_tolerance
|
| 567 |
-
# ],
|
| 568 |
-
# outputs=recommendation_output
|
| 569 |
-
# )
|
| 570 |
-
|
| 571 |
-
# return {
|
| 572 |
-
# 'living_space': living_space,
|
| 573 |
-
# 'exercise_time': exercise_time,
|
| 574 |
-
# 'grooming_commitment': grooming_commitment,
|
| 575 |
-
# 'experience_level': experience_level,
|
| 576 |
-
# 'has_children': has_children,
|
| 577 |
-
# 'noise_tolerance': noise_tolerance,
|
| 578 |
-
# 'get_recommendations_btn': get_recommendations_btn,
|
| 579 |
-
# 'recommendation_output': recommendation_output,
|
| 580 |
-
# }
|
|
|
|
| 326 |
'noise_tolerance': noise_tolerance,
|
| 327 |
'get_recommendations_btn': get_recommendations_btn,
|
| 328 |
'recommendation_output': recommendation_output,
|
| 329 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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