Spaces:
Running
on
Zero
Running
on
Zero
Update description_search_ui.py
Browse files- description_search_ui.py +153 -160
description_search_ui.py
CHANGED
|
@@ -1,157 +1,157 @@
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
#
|
| 135 |
-
|
| 136 |
|
| 137 |
-
#
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
|
| 144 |
-
#
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
-
#
|
| 152 |
-
|
| 153 |
|
| 154 |
-
|
| 155 |
|
| 156 |
|
| 157 |
def create_description_search_tab() -> gr.Column:
|
|
@@ -218,6 +218,7 @@ def create_description_search_tab() -> gr.Column:
|
|
| 218 |
</div>
|
| 219 |
"""
|
| 220 |
|
|
|
|
| 221 |
css = """
|
| 222 |
<style>
|
| 223 |
.breed-search-container {
|
|
@@ -226,24 +227,28 @@ def create_description_search_tab() -> gr.Column:
|
|
| 226 |
padding: 24px;
|
| 227 |
margin-bottom: 20px;
|
| 228 |
}
|
|
|
|
| 229 |
.guide-title {
|
| 230 |
font-size: 1.8rem;
|
| 231 |
color: #2c3e50;
|
| 232 |
margin-bottom: 20px;
|
| 233 |
text-align: center;
|
| 234 |
}
|
|
|
|
| 235 |
.intro-text {
|
| 236 |
color: #666;
|
| 237 |
text-align: center;
|
| 238 |
margin-bottom: 24px;
|
| 239 |
font-size: 1.1rem;
|
| 240 |
}
|
|
|
|
| 241 |
.criteria-grid {
|
| 242 |
display: grid;
|
| 243 |
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 244 |
gap: 20px;
|
| 245 |
margin-bottom: 24px;
|
| 246 |
}
|
|
|
|
| 247 |
.criteria-item {
|
| 248 |
display: flex;
|
| 249 |
align-items: flex-start;
|
|
@@ -252,20 +257,24 @@ def create_description_search_tab() -> gr.Column:
|
|
| 252 |
border-radius: 8px;
|
| 253 |
transition: all 0.3s ease;
|
| 254 |
}
|
|
|
|
| 255 |
.criteria-item:hover {
|
| 256 |
transform: translateY(-2px);
|
| 257 |
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
| 258 |
}
|
|
|
|
| 259 |
.criteria-item .icon {
|
| 260 |
font-size: 24px;
|
| 261 |
margin-right: 12px;
|
| 262 |
margin-top: 3px;
|
| 263 |
}
|
|
|
|
| 264 |
.criteria-content h3 {
|
| 265 |
font-size: 1.1rem;
|
| 266 |
color: #2c3e50;
|
| 267 |
margin: 0 0 4px 0;
|
| 268 |
}
|
|
|
|
| 269 |
.criteria-content p {
|
| 270 |
color: #666;
|
| 271 |
margin: 0;
|
|
@@ -275,49 +284,33 @@ def create_description_search_tab() -> gr.Column:
|
|
| 275 |
"""
|
| 276 |
|
| 277 |
with gr.Column():
|
|
|
|
| 278 |
gr.HTML(css + guide_html)
|
| 279 |
|
|
|
|
| 280 |
description_input = gr.Textbox(
|
| 281 |
label="",
|
| 282 |
-
placeholder="Example: I'm looking for a medium-sized, friendly dog...",
|
| 283 |
lines=5
|
| 284 |
)
|
| 285 |
|
|
|
|
| 286 |
search_button = gr.Button(
|
| 287 |
"Find My Perfect Match! 🔍",
|
| 288 |
variant="primary",
|
| 289 |
size="lg"
|
| 290 |
)
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
-
|
|
|
|
| 298 |
|
| 299 |
-
|
| 300 |
-
return {
|
| 301 |
-
processing_message: gr.update(visible=True),
|
| 302 |
-
result_output: gr.update(visible=False),
|
| 303 |
-
description_input: gr.update(interactive=False)
|
| 304 |
-
}
|
| 305 |
-
|
| 306 |
-
def on_search_complete(output):
|
| 307 |
-
return {
|
| 308 |
-
processing_message: gr.update(visible=False),
|
| 309 |
-
result_output: gr.update(visible=True, value=output),
|
| 310 |
-
description_input: gr.update(interactive=True)
|
| 311 |
-
}
|
| 312 |
|
| 313 |
-
search_button.click(
|
| 314 |
-
fn=on_search_start,
|
| 315 |
-
inputs=[description_input],
|
| 316 |
-
outputs=[processing_message, result_output, description_input]
|
| 317 |
-
).success(
|
| 318 |
-
fn=lambda x: x,
|
| 319 |
-
inputs=[description_input],
|
| 320 |
-
outputs=[description_input]
|
| 321 |
-
)
|
| 322 |
-
|
| 323 |
-
return description_input, search_button, result_output, processing_message
|
|
|
|
| 1 |
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
def create_description_search_tab() -> gr.Column:
|
| 5 |
+
"""創建描述搜索頁面的UI組件"""
|
| 6 |
+
guide_html = """
|
| 7 |
+
<div class="breed-search-container">
|
| 8 |
+
<div class="description-guide">
|
| 9 |
+
<h2 class="guide-title">🐾 Describe Your Ideal Dog</h2>
|
| 10 |
|
| 11 |
+
<div class="guide-content">
|
| 12 |
+
<p class="intro-text">Help us find your perfect companion! Please consider including the following details:</p>
|
| 13 |
|
| 14 |
+
<div class="criteria-grid">
|
| 15 |
+
<div class="criteria-item">
|
| 16 |
+
<span class="icon">📏</span>
|
| 17 |
+
<div class="criteria-content">
|
| 18 |
+
<h3>Size Preference</h3>
|
| 19 |
+
<p>Small • Medium • Large</p>
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
|
| 23 |
+
<div class="criteria-item">
|
| 24 |
+
<span class="icon">🏃</span>
|
| 25 |
+
<div class="criteria-content">
|
| 26 |
+
<h3>Activity Level</h3>
|
| 27 |
+
<p>Low • Moderate • High • Very Active</p>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
|
| 31 |
+
<div class="criteria-item">
|
| 32 |
+
<span class="icon">🏠</span>
|
| 33 |
+
<div class="criteria-content">
|
| 34 |
+
<h3>Living Environment</h3>
|
| 35 |
+
<p>Apartment • House • Yard Space</p>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
|
| 39 |
+
<div class="criteria-item">
|
| 40 |
+
<span class="icon">👨👩👧👦</span>
|
| 41 |
+
<div class="criteria-content">
|
| 42 |
+
<h3>Family Situation</h3>
|
| 43 |
+
<p>Children • Other Pets • Single Adult</p>
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
|
| 47 |
+
<div class="criteria-item">
|
| 48 |
+
<span class="icon">✂️</span>
|
| 49 |
+
<div class="criteria-content">
|
| 50 |
+
<h3>Grooming Commitment</h3>
|
| 51 |
+
<p>Low • Medium • High Maintenance</p>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
|
| 55 |
+
<div class="criteria-item">
|
| 56 |
+
<span class="icon">🎭</span>
|
| 57 |
+
<div class="criteria-content">
|
| 58 |
+
<h3>Desired Personality</h3>
|
| 59 |
+
<p>Friendly • Independent • Intelligent • Calm</p>
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
"""
|
| 67 |
|
| 68 |
+
# 添加CSS樣式
|
| 69 |
+
css = """
|
| 70 |
+
<style>
|
| 71 |
+
.breed-search-container {
|
| 72 |
+
background: white;
|
| 73 |
+
border-radius: 12px;
|
| 74 |
+
padding: 24px;
|
| 75 |
+
margin-bottom: 20px;
|
| 76 |
+
}
|
| 77 |
|
| 78 |
+
.guide-title {
|
| 79 |
+
font-size: 1.8rem;
|
| 80 |
+
color: #2c3e50;
|
| 81 |
+
margin-bottom: 20px;
|
| 82 |
+
text-align: center;
|
| 83 |
+
}
|
| 84 |
|
| 85 |
+
.intro-text {
|
| 86 |
+
color: #666;
|
| 87 |
+
text-align: center;
|
| 88 |
+
margin-bottom: 24px;
|
| 89 |
+
font-size: 1.1rem;
|
| 90 |
+
}
|
| 91 |
|
| 92 |
+
.criteria-grid {
|
| 93 |
+
display: grid;
|
| 94 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 95 |
+
gap: 20px;
|
| 96 |
+
margin-bottom: 24px;
|
| 97 |
+
}
|
| 98 |
|
| 99 |
+
.criteria-item {
|
| 100 |
+
display: flex;
|
| 101 |
+
align-items: flex-start;
|
| 102 |
+
padding: 16px;
|
| 103 |
+
background: #f8fafc;
|
| 104 |
+
border-radius: 8px;
|
| 105 |
+
transition: all 0.3s ease;
|
| 106 |
+
}
|
| 107 |
|
| 108 |
+
.criteria-item:hover {
|
| 109 |
+
transform: translateY(-2px);
|
| 110 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
| 111 |
+
}
|
| 112 |
|
| 113 |
+
.criteria-item .icon {
|
| 114 |
+
font-size: 24px;
|
| 115 |
+
margin-right: 12px;
|
| 116 |
+
margin-top: 3px;
|
| 117 |
+
}
|
| 118 |
|
| 119 |
+
.criteria-content h3 {
|
| 120 |
+
font-size: 1.1rem;
|
| 121 |
+
color: #2c3e50;
|
| 122 |
+
margin: 0 0 4px 0;
|
| 123 |
+
}
|
| 124 |
|
| 125 |
+
.criteria-content p {
|
| 126 |
+
color: #666;
|
| 127 |
+
margin: 0;
|
| 128 |
+
font-size: 0.95rem;
|
| 129 |
+
}
|
| 130 |
+
</style>
|
| 131 |
+
"""
|
| 132 |
|
| 133 |
+
with gr.Column():
|
| 134 |
+
# 顯示指南和樣式
|
| 135 |
+
gr.HTML(css + guide_html)
|
| 136 |
|
| 137 |
+
# 描述輸入區
|
| 138 |
+
description_input = gr.Textbox(
|
| 139 |
+
label="",
|
| 140 |
+
placeholder="Example: I'm looking for a medium-sized, friendly dog that's good with kids. I live in an apartment and can provide moderate exercise. Looking for an intelligent breed that's easy to train...",
|
| 141 |
+
lines=5
|
| 142 |
+
)
|
| 143 |
|
| 144 |
+
# 搜索按鈕(使用 Gradio 默認顏色)
|
| 145 |
+
search_button = gr.Button(
|
| 146 |
+
"Find My Perfect Match! 🔍",
|
| 147 |
+
variant="primary",
|
| 148 |
+
size="lg"
|
| 149 |
+
)
|
| 150 |
|
| 151 |
+
# 結果顯示區域
|
| 152 |
+
result_output = gr.HTML(label="Breed Recommendations")
|
| 153 |
|
| 154 |
+
return description_input, search_button, result_output
|
| 155 |
|
| 156 |
|
| 157 |
def create_description_search_tab() -> gr.Column:
|
|
|
|
| 218 |
</div>
|
| 219 |
"""
|
| 220 |
|
| 221 |
+
# 添加CSS樣式
|
| 222 |
css = """
|
| 223 |
<style>
|
| 224 |
.breed-search-container {
|
|
|
|
| 227 |
padding: 24px;
|
| 228 |
margin-bottom: 20px;
|
| 229 |
}
|
| 230 |
+
|
| 231 |
.guide-title {
|
| 232 |
font-size: 1.8rem;
|
| 233 |
color: #2c3e50;
|
| 234 |
margin-bottom: 20px;
|
| 235 |
text-align: center;
|
| 236 |
}
|
| 237 |
+
|
| 238 |
.intro-text {
|
| 239 |
color: #666;
|
| 240 |
text-align: center;
|
| 241 |
margin-bottom: 24px;
|
| 242 |
font-size: 1.1rem;
|
| 243 |
}
|
| 244 |
+
|
| 245 |
.criteria-grid {
|
| 246 |
display: grid;
|
| 247 |
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 248 |
gap: 20px;
|
| 249 |
margin-bottom: 24px;
|
| 250 |
}
|
| 251 |
+
|
| 252 |
.criteria-item {
|
| 253 |
display: flex;
|
| 254 |
align-items: flex-start;
|
|
|
|
| 257 |
border-radius: 8px;
|
| 258 |
transition: all 0.3s ease;
|
| 259 |
}
|
| 260 |
+
|
| 261 |
.criteria-item:hover {
|
| 262 |
transform: translateY(-2px);
|
| 263 |
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
| 264 |
}
|
| 265 |
+
|
| 266 |
.criteria-item .icon {
|
| 267 |
font-size: 24px;
|
| 268 |
margin-right: 12px;
|
| 269 |
margin-top: 3px;
|
| 270 |
}
|
| 271 |
+
|
| 272 |
.criteria-content h3 {
|
| 273 |
font-size: 1.1rem;
|
| 274 |
color: #2c3e50;
|
| 275 |
margin: 0 0 4px 0;
|
| 276 |
}
|
| 277 |
+
|
| 278 |
.criteria-content p {
|
| 279 |
color: #666;
|
| 280 |
margin: 0;
|
|
|
|
| 284 |
"""
|
| 285 |
|
| 286 |
with gr.Column():
|
| 287 |
+
# 顯示指南和樣式
|
| 288 |
gr.HTML(css + guide_html)
|
| 289 |
|
| 290 |
+
# 描述輸入區
|
| 291 |
description_input = gr.Textbox(
|
| 292 |
label="",
|
| 293 |
+
placeholder="Example: I'm looking for a medium-sized, friendly dog that's good with kids...",
|
| 294 |
lines=5
|
| 295 |
)
|
| 296 |
|
| 297 |
+
# 搜索按鈕
|
| 298 |
search_button = gr.Button(
|
| 299 |
"Find My Perfect Match! 🔍",
|
| 300 |
variant="primary",
|
| 301 |
size="lg"
|
| 302 |
)
|
| 303 |
|
| 304 |
+
# 加載消息(新增)
|
| 305 |
+
loading_msg = gr.HTML("""
|
| 306 |
+
<div style='text-align: center; color: #666;'>
|
| 307 |
+
<p><b>Finding your perfect match...</b></p>
|
| 308 |
+
<p>Please wait 15-20 seconds while we analyze your preferences.</p>
|
| 309 |
+
</div>
|
| 310 |
+
""", visible=False)
|
| 311 |
|
| 312 |
+
# 結果顯示區域
|
| 313 |
+
result_output = gr.HTML(label="Breed Recommendations")
|
| 314 |
|
| 315 |
+
return description_input, search_button, result_output, loading_msg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|