ChatBot / Passing params.py
bumk766fall2023's picture
Major update
dd4984c
Raw History Blame Contribute Delete
791 Bytes
import gradio as gr
def echo(params):
print(params)
return params
def get_params(request: gr.Request):
params = request.query_params
ip = request.client.host
return {"params": params,
"ip": ip}
with gr.Blocks() as demo:
#session state, where data persists across multiple submits within a page session
url_params = gr.State()
text_in = gr.Textbox()
text_out = gr.JSON()
btn = gr.Button(value="Get params")
# Listener, "echo" - the function to call when this event is triggered.
btn.click(echo, inputs=[url_params], outputs=[text_out])
#This listener is triggered when the Blocks initially loads in the browser.
demo.load(get_params, None, url_params, queue=True)
#demo.load(get_params, None, url_params, queue=False)
demo.launch()