File size: 992 Bytes
2666aeb
 
4e700c1
 
 
 
 
 
 
 
 
095b3d6
4e700c1
095b3d6
 
 
d165717
095b3d6
 
d165717
095b3d6
 
 
 
 
d165717
095b3d6
 
 
 
7d28350
4e700c1
 
 
 
 
d165717
2666aeb
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
34
35
36
37
38
import gradio as gr

get_window_url_params = """
    function() {
        console.log(text_input, url_params);
        const params = new URLSearchParams(window.location.search);
        url_params = Object.fromEntries(params);
        return url_params;
        }
    """

with gr.Blocks() as demo:
    url_params = gr.JSON({}, visible=True, label="URL Params")
    chatbot = gr.Chatbot()
    msg = gr.Textbox()
    clear = gr.Button("Clear")

    def user(user_message, history):
        return "", history + [[user_message, None]]

    def bot(history):
        bot_message = random.choice(["Yes", "No"])
        history[-1][1] = bot_message
        time.sleep(1)
        return history

    msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    clear.click(lambda: None, None, chatbot, queue=False)
    demo.load(
        None,
        inputs=None,
        outputs=url_params,
        _js=get_window_url_params
    )   

demo.launch()