Gradio logo

New to Gradio? Start here: Getting Started

See the Release History

Request

gradio.Request(ยทยทยท)

Description

A Gradio request object that can be used to access the request headers, cookies, query parameters and other information about the request from within the prediction function. The class is a thin wrapper around the fastapi.Request class. Attributes of this class include: `headers`, `client`, `query_params`, and `path_params`. If auth is enabled, the `username` attribute can be used to get the logged in user.

Example Usage

import gradio as gr
def echo(name, request: gr.Request):
    print("Request headers dictionary:", request.headers)
    print("IP address:", request.client.host)
    return name
io = gr.Interface(echo, "textbox", "textbox").launch()

Initialization

Parameter Description
request

fastapi.Request | None

default: None

A fastapi.Request

username

str | None

default: None