File size: 1,153 Bytes
38e7d78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio as gr

# Create a Gradio Blocks app
demo = gr.Blocks()

# Define the layout and components within the Blocks app
with demo:
    # Input Textbox for user to enter text
    inp = gr.Textbox(placeholder="Enter text.")
    # Button to trigger scrolling to the output
    scroll_btn = gr.Button("Scroll")
    # Button to trigger output without scrolling
    no_scroll_btn = gr.Button("No Scroll")
    # A large HTML block to simulate a long page
    big_block = gr.HTML("""
    <div style='height: 860px; width: 100px; background-color: pink;'></div>
    """)
    # Output Textbox to display the result
    out = gr.Textbox()

    # Event listener for the "Scroll" button
    scroll_btn.click(lambda x: x,
                     inputs=inp,
                     outputs=out,
                     scroll_to_output=True)  # Scroll to the output after updating
    # Event listener for the "No Scroll" button
    no_scroll_btn.click(lambda x: x,
                        inputs=inp,
                        outputs=out)  # Do not scroll to the output after updating

# Launch the Gradio app
if __name__ == "__main__":
    demo.launch(show_error=True)