Spaces:
Running
Running
add expandable results
Browse files
app.py
CHANGED
|
@@ -31,10 +31,13 @@ def search_kbli(text: str):
|
|
| 31 |
|
| 32 |
response = supabase.rpc(
|
| 33 |
"search_kbli",
|
| 34 |
-
{"query_embedding": embedding, "match_count":
|
| 35 |
).execute()
|
| 36 |
|
| 37 |
results = response.data if response.data else []
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
html = """
|
| 40 |
<style>
|
|
@@ -57,44 +60,66 @@ def search_kbli(text: str):
|
|
| 57 |
color: #4b5563;
|
| 58 |
margin-top: 4px;
|
| 59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
@media (prefers-color-scheme: dark) {
|
| 62 |
-
.kbli-item {
|
| 63 |
-
|
| 64 |
-
}
|
| 65 |
-
.kbli-
|
| 66 |
-
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
}
|
| 71 |
-
.kbli-desc {
|
| 72 |
-
color: #d1d5db;
|
| 73 |
-
}
|
| 74 |
-
.kbli-item:hover .kbli-title {
|
| 75 |
-
color: #93c5fd;
|
| 76 |
-
}
|
| 77 |
-
.kbli-item:hover .kbli-desc {
|
| 78 |
-
color: #e5e7eb;
|
| 79 |
-
}
|
| 80 |
}
|
| 81 |
</style>
|
| 82 |
<div>
|
| 83 |
"""
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
| 85 |
html += f"""
|
| 86 |
<div class="kbli-item">
|
| 87 |
<p class="kbli-title">{r['kode']} – {r['judul']}</p>
|
| 88 |
<p class="kbli-desc">{r['deskripsi']}</p>
|
| 89 |
</div>
|
| 90 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
html += "</div>"
|
| 92 |
return html
|
| 93 |
|
| 94 |
with gr.Blocks(css="""
|
| 95 |
.title {font-size: 22px; font-weight: 700; color: #111827; margin-bottom: 4px;}
|
| 96 |
.desc {font-size: 14px; color: #6b7280; margin-bottom: 16px;}
|
| 97 |
-
.
|
|
|
|
|
|
|
|
|
|
| 98 |
border-radius: 6px;
|
| 99 |
}
|
| 100 |
|
|
@@ -122,8 +147,8 @@ with gr.Blocks(css="""
|
|
| 122 |
inp1 = gr.Textbox(label="Masukkan teks")
|
| 123 |
|
| 124 |
with gr.Row(elem_classes="btn-row"):
|
| 125 |
-
btn_clear1 = gr.Button("Clear",
|
| 126 |
-
btn_submit1 = gr.Button("Submit",
|
| 127 |
|
| 128 |
with gr.Column(scale=1):
|
| 129 |
out1 = gr.JSON(label="Embedding Vector")
|
|
@@ -136,8 +161,8 @@ with gr.Blocks(css="""
|
|
| 136 |
inp2 = gr.Textbox(label="Masukkan teks")
|
| 137 |
|
| 138 |
with gr.Row(elem_classes="btn-row-search"):
|
| 139 |
-
btn_clear2 = gr.Button("Clear",
|
| 140 |
-
btn_submit2 = gr.Button("Submit",
|
| 141 |
|
| 142 |
out2 = gr.HTML(label="Hasil Pencarian Semantic")
|
| 143 |
|
|
|
|
| 31 |
|
| 32 |
response = supabase.rpc(
|
| 33 |
"search_kbli",
|
| 34 |
+
{"query_embedding": embedding, "match_count": 25}
|
| 35 |
).execute()
|
| 36 |
|
| 37 |
results = response.data if response.data else []
|
| 38 |
+
|
| 39 |
+
if not results:
|
| 40 |
+
return "<p>Tidak ditemukan hasil.</p>"
|
| 41 |
|
| 42 |
html = """
|
| 43 |
<style>
|
|
|
|
| 60 |
color: #4b5563;
|
| 61 |
margin-top: 4px;
|
| 62 |
}
|
| 63 |
+
details {
|
| 64 |
+
margin-top: 16px;
|
| 65 |
+
border: 1px solid #ddd;
|
| 66 |
+
border-radius: 6px;
|
| 67 |
+
padding: 8px;
|
| 68 |
+
}
|
| 69 |
+
details summary {
|
| 70 |
+
cursor: pointer;
|
| 71 |
+
font-weight: 600;
|
| 72 |
+
color: #2563eb;
|
| 73 |
+
}
|
| 74 |
|
| 75 |
@media (prefers-color-scheme: dark) {
|
| 76 |
+
.kbli-item { border: 1px solid #374151; }
|
| 77 |
+
.kbli-item:hover { background: #1f2937; }
|
| 78 |
+
.kbli-title { color: #f3f4f6; }
|
| 79 |
+
.kbli-desc { color: #d1d5db; }
|
| 80 |
+
.kbli-item:hover .kbli-title { color: #93c5fd; }
|
| 81 |
+
.kbli-item:hover .kbli-desc { color: #e5e7eb; }
|
| 82 |
+
details { border: 1px solid #374151; }
|
| 83 |
+
details summary { color: #60a5fa; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
| 85 |
</style>
|
| 86 |
<div>
|
| 87 |
"""
|
| 88 |
+
|
| 89 |
+
# Top 10 == // for r in results
|
| 90 |
+
top_10 = results[:10]
|
| 91 |
+
for r in top_10:
|
| 92 |
html += f"""
|
| 93 |
<div class="kbli-item">
|
| 94 |
<p class="kbli-title">{r['kode']} – {r['judul']}</p>
|
| 95 |
<p class="kbli-desc">{r['deskripsi']}</p>
|
| 96 |
</div>
|
| 97 |
"""
|
| 98 |
+
|
| 99 |
+
# Expandable for
|
| 100 |
+
others = results[10:]
|
| 101 |
+
if others:
|
| 102 |
+
html += "<details><summary>Lihat hasil lainnya</summary><div style='margin-top:10px;'>"
|
| 103 |
+
for r in others:
|
| 104 |
+
html += f"""
|
| 105 |
+
<div class="kbli-item">
|
| 106 |
+
<p class="kbli-title">{r['kode']} – {r['judul']}</p>
|
| 107 |
+
<p class="kbli-desc">{r['deskripsi']}</p>
|
| 108 |
+
</div>
|
| 109 |
+
"""
|
| 110 |
+
html += "</div></details>"
|
| 111 |
+
# End
|
| 112 |
+
|
| 113 |
html += "</div>"
|
| 114 |
return html
|
| 115 |
|
| 116 |
with gr.Blocks(css="""
|
| 117 |
.title {font-size: 22px; font-weight: 700; color: #111827; margin-bottom: 4px;}
|
| 118 |
.desc {font-size: 14px; color: #6b7280; margin-bottom: 16px;}
|
| 119 |
+
button.gr-button {
|
| 120 |
+
border-radius: 6px;
|
| 121 |
+
}
|
| 122 |
+
button.gr-button-primary, button.gr-button-secondary {
|
| 123 |
border-radius: 6px;
|
| 124 |
}
|
| 125 |
|
|
|
|
| 147 |
inp1 = gr.Textbox(label="Masukkan teks")
|
| 148 |
|
| 149 |
with gr.Row(elem_classes="btn-row"):
|
| 150 |
+
btn_clear1 = gr.Button("Clear", variant="secondary")
|
| 151 |
+
btn_submit1 = gr.Button("Submit", variant="primary")
|
| 152 |
|
| 153 |
with gr.Column(scale=1):
|
| 154 |
out1 = gr.JSON(label="Embedding Vector")
|
|
|
|
| 161 |
inp2 = gr.Textbox(label="Masukkan teks")
|
| 162 |
|
| 163 |
with gr.Row(elem_classes="btn-row-search"):
|
| 164 |
+
btn_clear2 = gr.Button("Clear", variant="secondary")
|
| 165 |
+
btn_submit2 = gr.Button("Submit", variant="primary")
|
| 166 |
|
| 167 |
out2 = gr.HTML(label="Hasil Pencarian Semantic")
|
| 168 |
|