Skip to content

Commit 002c474

Browse files
committed
add option to hide force search checkbox
1 parent e3f0e82 commit 002c474

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

script.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
var generate_button = document.getElementById("Generate");
22
generate_button.insertAdjacentHTML("afterend", '<div style="position:relative;"> <label style="color:#9ca3af;white-space:nowrap;position:absolute;right:0px;"><input type="checkbox" id="force-search" name="accept"> Force web search </label> </div>');
3-
generate_button.style.setProperty("position", "relative");
4-
generate_button.style.setProperty("top", "10px");
5-
generate_button.style.setProperty("margin-left", "-10px");
63

74
var stop_button = document.getElementById("stop");
8-
stop_button.style.setProperty("position", "relative");
9-
stop_button.style.setProperty("top", "10px");
10-
stop_button.style.setProperty("margin-left", "-10px");
11-
125
var chat_input = document.getElementById("chat-input");
13-
chat_input.style.marginBottom = "5px";
146

15-
var checkbox = document.getElementById("force-search");
7+
function set_margins(generate_button, stop_button, chat_input, reset=false) {
8+
if (reset) {
9+
generate_button.style.setProperty("position", "");
10+
generate_button.style.setProperty("top", "");
11+
generate_button.style.setProperty("margin-left", "");
12+
13+
stop_button.style.setProperty("position", "");
14+
stop_button.style.setProperty("top", "");
15+
stop_button.style.setProperty("margin-left", "");
16+
17+
chat_input.style.marginBottom = "";
18+
}
19+
else {
20+
generate_button.style.setProperty("position", "relative");
21+
generate_button.style.setProperty("top", "10px");
22+
generate_button.style.setProperty("margin-left", "-10px");
23+
24+
stop_button.style.setProperty("position", "relative");
25+
stop_button.style.setProperty("top", "10px");
26+
stop_button.style.setProperty("margin-left", "-10px");
27+
28+
chat_input.style.marginBottom = "5px";
29+
}
30+
}
31+
set_margins(generate_button, stop_button, chat_input);
32+
33+
var force_search_checkbox = document.getElementById("force-search");
1634
var gradio_force_search_checkbox = document.getElementById("Force-search-checkbox").children[1].firstChild;
17-
checkbox.addEventListener('change', function() {
35+
force_search_checkbox.addEventListener('change', function() {
1836
if (this.checked) {
1937
if (!gradio_force_search_checkbox.checked) {
2038
gradio_force_search_checkbox.click();
@@ -24,4 +42,18 @@ checkbox.addEventListener('change', function() {
2442
gradio_force_search_checkbox.click();
2543
}
2644
}
27-
});
45+
});
46+
47+
var gradio_show_force_search_box = document.getElementById("show-force-search-box").children[1].firstChild;
48+
gradio_show_force_search_box.addEventListener('change', function() {
49+
if (this.checked) {
50+
force_search_checkbox.parentElement.parentElement.style.display = '';
51+
set_margins(generate_button, stop_button, chat_input);
52+
} else {
53+
force_search_checkbox.parentElement.parentElement.style.display = 'none';
54+
set_margins(generate_button, stop_button, chat_input, true);
55+
}
56+
});
57+
58+
const event = new Event("change");
59+
gradio_show_force_search_box.dispatchEvent(event);

script.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"chunking method": "character-based",
4949
"chunker breakpoint_threshold_amount": 30,
5050
"simple search": False,
51-
"client timeout": 10
51+
"client timeout": 10,
52+
"show force search checkbox": True
5253
}
5354
custom_system_message_filename = None
5455
extension_path = os.path.dirname(os.path.abspath(__file__))
@@ -256,6 +257,8 @@ def update_default_custom_system_message(check: bool):
256257
label='Display search results in chat')
257258
show_url_content = gr.Checkbox(value=lambda: params['display extracted URL content in chat'],
258259
label='Display extracted URL content in chat')
260+
show_force_search = gr.Checkbox(value=lambda: params['show force search checkbox'],
261+
label='Show force search checkbox', elem_id="show-force-search-box")
259262
gr.Markdown(value='---')
260263
with gr.Row():
261264
with gr.Column():
@@ -373,6 +376,7 @@ def update_default_custom_system_message(check: bool):
373376
show_results.change(lambda x: params.update({"display search results in chat": x}), show_results, None)
374377
show_url_content.change(lambda x: params.update({"display extracted URL content in chat": x}), show_url_content,
375378
None)
379+
show_force_search.change(lambda x: params.update({"show force search checkbox": x}), show_force_search, None)
376380
searxng_url.change(lambda x: params.update({"searxng url": x}), searxng_url, None)
377381

378382
delete_button.click(

0 commit comments

Comments
 (0)