Spaces:
Running
Running
Kang Suhyun
suhyun.kang
commited on
[#20] Add scroll functionality to response textboxes (#41)
Browse filesWhen a response length exceeds a certain length, the text box does not scroll to bottom to show the remaining text.
There are two ways to fix this:
1. Display the scroll bar and let the user scroll to the bottom. When it reaches the bottom, the scroll bar will automatically scroll to the bottom.
2. Automatically scroll to the bottom when the response text is generated.
This PR implements the second option since it's cumbersome to scroll to the bottom manually.
When the response text is generated, `element.scrollTop = element.scrollHeight` is triggered to scroll to the bottom of the text box.
It's not the most efficient way to do this, but it's the simplest way to do it.
Co-authored-by: suhyun.kang <[email protected]>
app.py
CHANGED
@@ -63,6 +63,15 @@ def vote(vote_button, response_a, response_b, model_a_name, model_b_name,
|
|
63 |
raise gr.Error("Please select a response type.")
|
64 |
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
with gr.Blocks(title="Arena") as app:
|
67 |
with gr.Row():
|
68 |
category_radio = gr.Radio(
|
@@ -101,8 +110,21 @@ with gr.Blocks(title="Arena") as app:
|
|
101 |
|
102 |
with gr.Group():
|
103 |
with gr.Row():
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
with gr.Row(visible=False) as model_name_row:
|
108 |
model_names[0] = gr.Textbox(show_label=False)
|
|
|
63 |
raise gr.Error("Please select a response type.")
|
64 |
|
65 |
|
66 |
+
def scroll_to_bottom_js(elem_id):
|
67 |
+
return f"""
|
68 |
+
() => {{
|
69 |
+
const element = document.querySelector("#{elem_id} textarea");
|
70 |
+
element.scrollTop = element.scrollHeight;
|
71 |
+
}}
|
72 |
+
"""
|
73 |
+
|
74 |
+
|
75 |
with gr.Blocks(title="Arena") as app:
|
76 |
with gr.Row():
|
77 |
category_radio = gr.Radio(
|
|
|
110 |
|
111 |
with gr.Group():
|
112 |
with gr.Row():
|
113 |
+
response_a_elem_id = "responseA"
|
114 |
+
response_a_textbox = gr.Textbox(label="Model A",
|
115 |
+
interactive=False,
|
116 |
+
elem_id=response_a_elem_id)
|
117 |
+
response_a_textbox.change(fn=None,
|
118 |
+
js=scroll_to_bottom_js(response_a_elem_id))
|
119 |
+
response_boxes[0] = response_a_textbox
|
120 |
+
|
121 |
+
response_b_elem_id = "responseB"
|
122 |
+
response_b_textbox = gr.Textbox(label="Model B",
|
123 |
+
interactive=False,
|
124 |
+
elem_id=response_b_elem_id)
|
125 |
+
response_b_textbox.change(fn=None,
|
126 |
+
js=scroll_to_bottom_js(response_b_elem_id))
|
127 |
+
response_boxes[1] = response_b_textbox
|
128 |
|
129 |
with gr.Row(visible=False) as model_name_row:
|
130 |
model_names[0] = gr.Textbox(show_label=False)
|