ljlmike commited on
Commit
8156ea8
·
1 Parent(s): 6227f69
Files changed (1) hide show
  1. app.py +44 -11
app.py CHANGED
@@ -108,8 +108,16 @@ table{width:100%;border-collapse:collapse;font-size:0.9rem;}
108
  th,td{border:1px solid #ddd;padding:6px;vertical-align:top;}
109
  th{background:#f5f5f5;font-weight:600;}
110
  code{background:#f8f8f8;border:1px solid #eee;border-radius:4px;padding:2px 4px;}
 
 
 
 
 
 
 
111
  """
112
 
 
113
  with gr.Blocks(title="Lean Finder Retrieval", css=CUSTOM_CSS) as demo:
114
  gr.Markdown("# Lean Finder – Retrieval Demo\n"
115
  "Choose **Normal** for standard retrieval or **Arena** to compare and vote.")
@@ -120,14 +128,23 @@ with gr.Blocks(title="Lean Finder Retrieval", css=CUSTOM_CSS) as demo:
120
  run_btn = gr.Button("Retrieve")
121
  results_html= gr.HTML()
122
 
123
- # voting widgets
124
- with gr.Row():
125
- vote_radio = gr.Radio(
126
  ["Lean Finder better", "LeanSearch better", "Tie", "Both are bad"],
127
- label="Which result is better?", visible=False
 
 
128
  )
129
- submit_btn = gr.Button("Submit vote", visible=False)
130
- vote_status = gr.Textbox(label="", interactive=False, max_lines=1, visible=False)
 
 
 
 
 
 
 
 
131
 
132
  # internal state: stored per browser session
133
  st_query = gr.State("")
@@ -138,27 +155,29 @@ with gr.Blocks(title="Lean Finder Retrieval", css=CUSTOM_CSS) as demo:
138
  def retrieve(query: str, k: int, mode: str):
139
  query = query.strip()
140
  if not query:
141
- hide = gr.update(visible=False)
142
  return "<p>Please enter a query.</p>", query, {}, [], hide, hide, hide
143
 
144
  lf_json = _call_endpoint({"inputs": query, "top_k": k}).get("results", [])
145
  lf_html = _render_leanfinder(lf_json)
146
 
147
  if mode == "Normal":
148
- hide = gr.update(visible=False)
149
  return lf_html, query, lf_json, [], hide, hide, hide
150
 
151
  ls_json = _call_leansearch(query, k)
152
  ls_html = _render_leansearch(ls_json)
153
-
154
  page = (
155
  "<div style='display:flex; gap:0.5rem;'>"
156
  f"<div style='flex:1 1 0;'>{lf_html}</div>"
157
  f"<div style='flex:1 1 0;'>{ls_html}</div>"
158
  "</div>"
159
  )
160
- show = gr.update(visible=True, value=None)
161
- return page, query, lf_json, ls_json, show, show, show
 
 
 
162
 
163
  run_btn.click(
164
  retrieve,
@@ -166,6 +185,20 @@ with gr.Blocks(title="Lean Finder Retrieval", css=CUSTOM_CSS) as demo:
166
  outputs=[results_html, st_query, st_lf_js, st_ls_js, vote_radio, submit_btn, vote_status],
167
  )
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  submit_btn.click(
170
  _save_vote,
171
  inputs=[vote_radio, st_query, st_lf_js, st_ls_js],
 
108
  th,td{border:1px solid #ddd;padding:6px;vertical-align:top;}
109
  th{background:#f5f5f5;font-weight:600;}
110
  code{background:#f8f8f8;border:1px solid #eee;border-radius:4px;padding:2px 4px;}
111
+
112
+ #vote_area{margin-top:1rem;align-items:center;gap:1rem;flex-wrap:wrap;}
113
+ #vote_radio .gr-radio{display:flex;gap:0.75rem;}
114
+ #vote_radio label{padding:4px 12px;border:1px solid #ccc;border-radius:8px;cursor:pointer;user-select:none;transition:all .15s ease;}
115
+ #vote_radio input[type="radio"]:checked + label{background:#0066ff;color:#fff;border-color:#0066ff;}
116
+ #submit_btn button{padding:0.6rem 1.4rem;font-weight:600;font-size:1rem;border-radius:8px;}
117
+ #vote_status textarea{border:none;background:#fafafa;color:#333;font-weight:600;}
118
  """
119
 
120
+
121
  with gr.Blocks(title="Lean Finder Retrieval", css=CUSTOM_CSS) as demo:
122
  gr.Markdown("# Lean Finder – Retrieval Demo\n"
123
  "Choose **Normal** for standard retrieval or **Arena** to compare and vote.")
 
128
  run_btn = gr.Button("Retrieve")
129
  results_html= gr.HTML()
130
 
131
+ with gr.Row(elem_id="vote_area"):
132
+ vote_radio = gr.Radio(
 
133
  ["Lean Finder better", "LeanSearch better", "Tie", "Both are bad"],
134
+ label="Which result is better?",
135
+ visible=False,
136
+ elem_id="vote_radio"
137
  )
138
+ submit_btn = gr.Button(
139
+ "Submit vote",
140
+ visible=False,
141
+ elem_id="submit_btn",
142
+ variant="primary"
143
+ )
144
+ vote_status = gr.Textbox(
145
+ "", interactive=False, visible=False,
146
+ elem_id="vote_status", max_lines=1
147
+ )
148
 
149
  # internal state: stored per browser session
150
  st_query = gr.State("")
 
155
  def retrieve(query: str, k: int, mode: str):
156
  query = query.strip()
157
  if not query:
158
+ hide = gr.update(visible=False, value="")
159
  return "<p>Please enter a query.</p>", query, {}, [], hide, hide, hide
160
 
161
  lf_json = _call_endpoint({"inputs": query, "top_k": k}).get("results", [])
162
  lf_html = _render_leanfinder(lf_json)
163
 
164
  if mode == "Normal":
165
+ hide = gr.update(visible=False, value="")
166
  return lf_html, query, lf_json, [], hide, hide, hide
167
 
168
  ls_json = _call_leansearch(query, k)
169
  ls_html = _render_leansearch(ls_json)
 
170
  page = (
171
  "<div style='display:flex; gap:0.5rem;'>"
172
  f"<div style='flex:1 1 0;'>{lf_html}</div>"
173
  f"<div style='flex:1 1 0;'>{ls_html}</div>"
174
  "</div>"
175
  )
176
+ show_radio = gr.update(visible=True, value=None)
177
+ hide_status = gr.update(visible=False, value="")
178
+ show_btn = gr.update(visible=True)
179
+ return page, query, lf_json, ls_json, show_radio, show_btn, hide_status
180
+
181
 
182
  run_btn.click(
183
  retrieve,
 
185
  outputs=[results_html, st_query, st_lf_js, st_ls_js, vote_radio, submit_btn, vote_status],
186
  )
187
 
188
+ def _reset_ui_on_mode_change(mode):
189
+ return (
190
+ "",
191
+ gr.update(visible=False, value=None),
192
+ gr.update(visible=False),
193
+ gr.update(visible=False, value=""),
194
+ )
195
+
196
+ mode_sel.change(
197
+ _reset_ui_on_mode_change,
198
+ inputs=mode_sel,
199
+ outputs=[results_html, vote_radio, submit_btn, vote_status],
200
+ )
201
+
202
  submit_btn.click(
203
  _save_vote,
204
  inputs=[vote_radio, st_query, st_lf_js, st_ls_js],