Spaces:
Running
on
Zero
Running
on
Zero
Update description_search_ui.py
Browse files- description_search_ui.py +199 -14
description_search_ui.py
CHANGED
@@ -1,7 +1,160 @@
|
|
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">
|
@@ -65,7 +218,6 @@ def create_description_search_tab() -> gr.Column:
|
|
65 |
</div>
|
66 |
"""
|
67 |
|
68 |
-
# 添加CSS樣式
|
69 |
css = """
|
70 |
<style>
|
71 |
.breed-search-container {
|
@@ -74,28 +226,24 @@ def create_description_search_tab() -> gr.Column:
|
|
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;
|
@@ -104,24 +252,20 @@ def create_description_search_tab() -> gr.Column:
|
|
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;
|
@@ -141,14 +285,55 @@ def create_description_search_tab() -> gr.Column:
|
|
141 |
lines=5
|
142 |
)
|
143 |
|
144 |
-
#
|
145 |
search_button = gr.Button(
|
146 |
"Find My Perfect Match! 🔍",
|
147 |
variant="primary",
|
148 |
size="lg"
|
149 |
)
|
150 |
-
|
151 |
-
#
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
return description_input, search_button, result_output
|
|
|
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():
|
158 |
"""創建描述搜索頁面的UI組件"""
|
159 |
guide_html = """
|
160 |
<div class="breed-search-container">
|
|
|
218 |
</div>
|
219 |
"""
|
220 |
|
|
|
221 |
css = """
|
222 |
<style>
|
223 |
.breed-search-container {
|
|
|
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 |
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;
|
|
|
285 |
lines=5
|
286 |
)
|
287 |
|
288 |
+
# 搜索按鈕
|
289 |
search_button = gr.Button(
|
290 |
"Find My Perfect Match! 🔍",
|
291 |
variant="primary",
|
292 |
size="lg"
|
293 |
)
|
294 |
+
|
295 |
+
# 加載狀態和結果區域
|
296 |
+
with gr.Column() as output_area:
|
297 |
+
result_output = gr.HTML(label="Breed Recommendations")
|
298 |
+
loading_status = gr.HTML(visible=False, value="""
|
299 |
+
<div style="text-align: center; padding: 2rem;">
|
300 |
+
<div style="display: inline-block; width: 40px; height: 40px; border: 4px solid #f3f3f3;
|
301 |
+
border-top: 4px solid #3498db; border-radius: 50%; margin-bottom: 1rem;
|
302 |
+
animation: spin 1s linear infinite;">
|
303 |
+
</div>
|
304 |
+
<style>
|
305 |
+
@keyframes spin {
|
306 |
+
0% { transform: rotate(0deg); }
|
307 |
+
100% { transform: rotate(360deg); }
|
308 |
+
}
|
309 |
+
</style>
|
310 |
+
<p style="color: #666; margin: 10px 0;">Finding your perfect match...</p>
|
311 |
+
<p style="color: #888; font-size: 0.9em;">This usually takes 15-20 seconds</p>
|
312 |
+
<div style="color: #888; font-size: 0.9em; margin-top: 10px;">
|
313 |
+
<p>✓ Analyzing preferences</p>
|
314 |
+
<p>✓ Calculating compatibility</p>
|
315 |
+
<p>⋯ Finding best matches</p>
|
316 |
+
</div>
|
317 |
+
</div>
|
318 |
+
""")
|
319 |
+
|
320 |
+
def on_button_click():
|
321 |
+
return gr.update(visible=True), gr.update(visible=False)
|
322 |
+
|
323 |
+
# 點擊按鈕時顯示加載狀態
|
324 |
+
search_button.click(
|
325 |
+
fn=on_button_click,
|
326 |
+
inputs=[],
|
327 |
+
outputs=[loading_status, result_output],
|
328 |
+
queue=False
|
329 |
+
).then(
|
330 |
+
fn=on_description_search,
|
331 |
+
inputs=[description_input],
|
332 |
+
outputs=[result_output]
|
333 |
+
).then(
|
334 |
+
fn=lambda: (gr.update(visible=False), gr.update(visible=True)),
|
335 |
+
inputs=[],
|
336 |
+
outputs=[loading_status, result_output]
|
337 |
+
)
|
338 |
|
339 |
return description_input, search_button, result_output
|