Spaces:
Running
Running
add ui when search
Browse files
app.py
CHANGED
|
@@ -95,6 +95,8 @@ latest_query_result = {"query": "", "result": "", "raw_query": "", "time": ""}
|
|
| 95 |
|
| 96 |
# Search Function
|
| 97 |
def search_product(query):
|
|
|
|
|
|
|
| 98 |
start_time = time.time()
|
| 99 |
latest_query_result["raw_query"] = query
|
| 100 |
|
|
@@ -110,9 +112,9 @@ def search_product(query):
|
|
| 110 |
limit=50
|
| 111 |
).points
|
| 112 |
except Exception as e:
|
| 113 |
-
|
|
|
|
| 114 |
|
| 115 |
-
# ✅ Rerank Top 10
|
| 116 |
if len(result) > 0:
|
| 117 |
topk = 10
|
| 118 |
docs = [r.payload.get("name", "") for r in result[:topk]]
|
|
@@ -158,7 +160,6 @@ def search_product(query):
|
|
| 158 |
|
| 159 |
if not found:
|
| 160 |
html_output += '<div style="text-align: center; font-size: 18px; color: #a00; padding: 30px;">❌ ไม่พบสินค้าที่เกี่ยวข้องกับคำค้นนี้</div>'
|
| 161 |
-
return html_output
|
| 162 |
|
| 163 |
latest_query_result.update({
|
| 164 |
"query": corrected_query,
|
|
@@ -166,7 +167,7 @@ def search_product(query):
|
|
| 166 |
"time": elapsed,
|
| 167 |
})
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
# Feedback Function
|
| 172 |
def log_feedback(feedback):
|
|
@@ -191,6 +192,7 @@ with gr.Blocks() as demo:
|
|
| 191 |
|
| 192 |
query_input = gr.Textbox(label="พิมพ์คำค้นหา")
|
| 193 |
result_output = gr.HTML(label="📋 ผลลัพธ์")
|
|
|
|
| 194 |
|
| 195 |
with gr.Row():
|
| 196 |
match_btn = gr.Button("✅ ตรง")
|
|
@@ -198,7 +200,11 @@ with gr.Blocks() as demo:
|
|
| 198 |
|
| 199 |
feedback_status = gr.Textbox(label="📬 สถานะ Feedback")
|
| 200 |
|
| 201 |
-
query_input.submit(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
match_btn.click(fn=lambda: log_feedback("match"), outputs=feedback_status)
|
| 203 |
not_match_btn.click(fn=lambda: log_feedback("not_match"), outputs=feedback_status)
|
| 204 |
|
|
|
|
| 95 |
|
| 96 |
# Search Function
|
| 97 |
def search_product(query):
|
| 98 |
+
yield gr.update(value="🔄 กำลังค้นหา..."), ""
|
| 99 |
+
|
| 100 |
start_time = time.time()
|
| 101 |
latest_query_result["raw_query"] = query
|
| 102 |
|
|
|
|
| 112 |
limit=50
|
| 113 |
).points
|
| 114 |
except Exception as e:
|
| 115 |
+
yield gr.update(value="❌ Qdrant error"), f"<p>❌ Qdrant error: {str(e)}</p>"
|
| 116 |
+
return
|
| 117 |
|
|
|
|
| 118 |
if len(result) > 0:
|
| 119 |
topk = 10
|
| 120 |
docs = [r.payload.get("name", "") for r in result[:topk]]
|
|
|
|
| 160 |
|
| 161 |
if not found:
|
| 162 |
html_output += '<div style="text-align: center; font-size: 18px; color: #a00; padding: 30px;">❌ ไม่พบสินค้าที่เกี่ยวข้องกับคำค้นนี้</div>'
|
|
|
|
| 163 |
|
| 164 |
latest_query_result.update({
|
| 165 |
"query": corrected_query,
|
|
|
|
| 167 |
"time": elapsed,
|
| 168 |
})
|
| 169 |
|
| 170 |
+
yield gr.update(value="✅ ค้นหาเสร็จแล้ว!"), html_output
|
| 171 |
|
| 172 |
# Feedback Function
|
| 173 |
def log_feedback(feedback):
|
|
|
|
| 192 |
|
| 193 |
query_input = gr.Textbox(label="พิมพ์คำค้นหา")
|
| 194 |
result_output = gr.HTML(label="📋 ผลลัพธ์")
|
| 195 |
+
status_output = gr.Textbox(label="🕒 สถานะ", interactive=False)
|
| 196 |
|
| 197 |
with gr.Row():
|
| 198 |
match_btn = gr.Button("✅ ตรง")
|
|
|
|
| 200 |
|
| 201 |
feedback_status = gr.Textbox(label="📬 สถานะ Feedback")
|
| 202 |
|
| 203 |
+
query_input.submit(
|
| 204 |
+
search_product,
|
| 205 |
+
inputs=[query_input],
|
| 206 |
+
outputs=[status_output, result_output]
|
| 207 |
+
)
|
| 208 |
match_btn.click(fn=lambda: log_feedback("match"), outputs=feedback_status)
|
| 209 |
not_match_btn.click(fn=lambda: log_feedback("not_match"), outputs=feedback_status)
|
| 210 |
|