Spaces:
Running
on
Zero
Running
on
Zero
Update breed_recommendation.py
Browse files- breed_recommendation.py +44 -4
breed_recommendation.py
CHANGED
|
@@ -37,7 +37,7 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 37 |
</div>
|
| 38 |
""")
|
| 39 |
|
| 40 |
-
|
| 41 |
with gr.Column():
|
| 42 |
living_space = gr.Radio(
|
| 43 |
choices=["apartment", "house_small", "house_large"],
|
|
@@ -46,6 +46,13 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 46 |
value="apartment"
|
| 47 |
)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
exercise_time = gr.Slider(
|
| 50 |
minimum=0,
|
| 51 |
maximum=180,
|
|
@@ -54,6 +61,14 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 54 |
info="Consider walks, play time, and training"
|
| 55 |
)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
grooming_commitment = gr.Radio(
|
| 58 |
choices=["low", "medium", "high"],
|
| 59 |
label="Grooming commitment level",
|
|
@@ -69,17 +84,40 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 69 |
value="beginner"
|
| 70 |
)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
has_children = gr.Checkbox(
|
| 73 |
label="Have children at home",
|
| 74 |
info="Helps recommend child-friendly breeds"
|
| 75 |
)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
noise_tolerance = gr.Radio(
|
| 78 |
choices=["low", "medium", "high"],
|
| 79 |
label="Noise tolerance level",
|
| 80 |
info="Some breeds are more vocal than others",
|
| 81 |
value="medium"
|
| 82 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
get_recommendations_btn = gr.Button("Find My Perfect Match! 🔍", variant="primary")
|
| 85 |
recommendation_output = gr.HTML(label="Breed Recommendations")
|
|
@@ -97,11 +135,12 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 97 |
experience_level=args[3],
|
| 98 |
has_children=args[4],
|
| 99 |
noise_tolerance=args[5],
|
|
|
|
| 100 |
space_for_play=True if args[0] != "apartment" else False,
|
| 101 |
other_pets=False,
|
| 102 |
climate="moderate",
|
| 103 |
-
health_sensitivity="medium",
|
| 104 |
-
barking_acceptance=args[5]
|
| 105 |
)
|
| 106 |
|
| 107 |
recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
|
@@ -452,7 +491,8 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
|
|
| 452 |
grooming_commitment,
|
| 453 |
experience_level,
|
| 454 |
has_children,
|
| 455 |
-
noise_tolerance
|
|
|
|
| 456 |
],
|
| 457 |
outputs=recommendation_output
|
| 458 |
)
|
|
|
|
| 37 |
</div>
|
| 38 |
""")
|
| 39 |
|
| 40 |
+
with gr.Row():
|
| 41 |
with gr.Column():
|
| 42 |
living_space = gr.Radio(
|
| 43 |
choices=["apartment", "house_small", "house_large"],
|
|
|
|
| 46 |
value="apartment"
|
| 47 |
)
|
| 48 |
|
| 49 |
+
yard_access = gr.Radio(
|
| 50 |
+
choices=["no_yard", "shared_yard", "private_yard"],
|
| 51 |
+
label="Yard Access Type",
|
| 52 |
+
info="Available outdoor space",
|
| 53 |
+
value="no_yard"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
exercise_time = gr.Slider(
|
| 57 |
minimum=0,
|
| 58 |
maximum=180,
|
|
|
|
| 61 |
info="Consider walks, play time, and training"
|
| 62 |
)
|
| 63 |
|
| 64 |
+
exercise_type = gr.Radio(
|
| 65 |
+
choices=["light_walks", "moderate_activity", "active_training"],
|
| 66 |
+
label="Exercise Style",
|
| 67 |
+
info="What kind of activities do you prefer?",
|
| 68 |
+
value="moderate_activity"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
grooming_commitment = gr.Radio(
|
| 73 |
choices=["low", "medium", "high"],
|
| 74 |
label="Grooming commitment level",
|
|
|
|
| 84 |
value="beginner"
|
| 85 |
)
|
| 86 |
|
| 87 |
+
time_availability = gr.Radio(
|
| 88 |
+
choices=["limited", "moderate", "flexible"],
|
| 89 |
+
label="Time Availability",
|
| 90 |
+
info="Time available for dog care daily",
|
| 91 |
+
value="moderate"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
has_children = gr.Checkbox(
|
| 95 |
label="Have children at home",
|
| 96 |
info="Helps recommend child-friendly breeds"
|
| 97 |
)
|
| 98 |
|
| 99 |
+
children_age = gr.Radio(
|
| 100 |
+
choices=["toddler", "school_age", "teenager"],
|
| 101 |
+
label="Children's Age Group",
|
| 102 |
+
info="Helps match with age-appropriate breeds",
|
| 103 |
+
visible=False # 默認隱藏,只在has_children=True時顯示
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
noise_tolerance = gr.Radio(
|
| 107 |
choices=["low", "medium", "high"],
|
| 108 |
label="Noise tolerance level",
|
| 109 |
info="Some breeds are more vocal than others",
|
| 110 |
value="medium"
|
| 111 |
)
|
| 112 |
+
|
| 113 |
+
def update_children_age_visibility(has_children):
|
| 114 |
+
return gr.update(visible=has_children)
|
| 115 |
+
|
| 116 |
+
has_children.change(
|
| 117 |
+
fn=update_children_age_visibility,
|
| 118 |
+
inputs=has_children,
|
| 119 |
+
outputs=children_age
|
| 120 |
+
)
|
| 121 |
|
| 122 |
get_recommendations_btn = gr.Button("Find My Perfect Match! 🔍", variant="primary")
|
| 123 |
recommendation_output = gr.HTML(label="Breed Recommendations")
|
|
|
|
| 135 |
experience_level=args[3],
|
| 136 |
has_children=args[4],
|
| 137 |
noise_tolerance=args[5],
|
| 138 |
+
children_age=args[6] if args[4] else None,
|
| 139 |
space_for_play=True if args[0] != "apartment" else False,
|
| 140 |
other_pets=False,
|
| 141 |
climate="moderate",
|
| 142 |
+
health_sensitivity="medium",
|
| 143 |
+
barking_acceptance=args[5]
|
| 144 |
)
|
| 145 |
|
| 146 |
recommendations = get_breed_recommendations(user_prefs, top_n=10)
|
|
|
|
| 491 |
grooming_commitment,
|
| 492 |
experience_level,
|
| 493 |
has_children,
|
| 494 |
+
noise_tolerance,
|
| 495 |
+
children_age
|
| 496 |
],
|
| 497 |
outputs=recommendation_output
|
| 498 |
)
|