Spaces:
Sleeping
Sleeping
File size: 1,410 Bytes
e2ee3b3 bc5bf1a 75023c4 bc5bf1a 75023c4 bc5bf1a 75023c4 bc5bf1a |
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 |
import gradio as gr
def echo(text, request: gr.Request):
if request:
print("Request headers dictionary:", request.headers)
print("IP address:", request.client.host)
print("Query parameters:", dict(request.query_params))
return request.headers, request.client.host
def echo_load(request: gr.Request):
if request:
print("Request headers dictionary:", request.headers)
print("IP address:", request.client.host)
print("Query parameters:", dict(request.query_params))
user_agent = request.headers["user-agent"]
device_type = detect_device(user_agent)
if "Mobile" in user_agent or "Android" in user_agent or "iPhone" in user_agent:
return request.headers, "Mobile Device", gr.Textbox(visible=False), gr.Textbox(visible=True)
else:
return request.headers, "Web Browser", gr.Textbox(visible=True), gr.Textbox(visible=False)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
tb = gr.Textbox()
submit = gr.Button('submit')
with gr.Column():
js = gr.JSON()
tb1 = gr.Textbox()
tb2 = gr.Textbox(label='Visible only when you are on a Web-browser')
tb3 = gr.Textbox(label='Visible only when you are on a Mobile device')
submit.click(echo, tb, [js, tb1])
demo.load(echo_load, [], [js,tb1, tb2, tb3])
demo.launch() |