{
"pages": [
{
"name": "Interface",
"url": "https://www.gradio.app/docs/gradio/interface",
"content": "queue gradio.Interface.queue(···) Description By enabling the queue you can control when users know their position in the queue, and set a limit on maximum number of events allowed. Example Usage demo = gr.Interface(image_generator, gr.Textbox(), gr.Image()) demo.queue(max_size=20) demo.launch() Parameters ▼ status_update_rate: float | Literal['auto'] default = 'auto' If 'auto', Queue will send status estimations to all clients whenever a job is finished. Otherwise Queue will send status at regular intervals set by this parameter as the number of seconds. api_open: bool | None default = None If True, the REST routes of the backend will be open, allowing requests made directly to those endpoints to skip the queue. max_size: int | None default = None The maximum number of events the queue will store at any given moment. If the queue is full, new events will not be added and a user will receive a message saying that the queue is full. If None, the queue size will be unlimited. default_concurrency_limit: int | None | Literal['not_set'] default = 'not_set' The default value of `concurrency_limit` to use for event listeners that don't specify a value. Can be set by environment variable GRADIO_DEFAULT_CONCURRENCY_LIMIT. Defaults to 1 if not set otherwise."
},
{
"name": "ChatInterface",
"url": "https://www.gradio.app/docs/gradio/chatinterface",
"content": "ChatInterface gradio.ChatInterface(fn, type='messages', ···) Description ChatInterface is Gradio's high-level abstraction for creating chatbot UIs, and allows you to create a web-based demo around a chatbot model in a few lines of code. Only one parameter is required: fn, which takes a function that governs the response of the chatbot based on the user input and chat history. Additional parameters can be used to control the appearance and behavior of the demo. Example Usage Basic Example: A chatbot that echoes back the users's message import gradio as gr def echo(message, history): return message demo = gr.ChatInterface(fn=echo, type='messages', examples=['hello', 'hola', 'merhaba'], title='Echo Bot') demo.launch() Custom Chatbot: A gr.ChatInterface with a custom gr.Chatbot that includes a placeholder as well as upvote/downvote buttons. The upvote/downvote buttons are automatically added when a .like() event is attached to a gr.Chatbot. In order to attach event listeners to your custom chatbot, wrap the gr.Chatbot as well as the gr.ChatInterface inside of a gr.Blocks like this: import gradio as gr def yes(message, history): return 'yes' def vote(data: gr.LikeData): if data.liked: print('You upvoted this response: ' + data.value['value']) else: print('You downvoted this response: ' + data.value['value']) with gr.Blocks() as demo: chatbot = gr.Chatbot(placeholder='Your Personal Yes-Man
Ask Me Anything') chatbot.like(vote, None, None) gr.ChatInterface(fn=yes, type='messages', chatbot=chatbot) demo.launch() Initialization Parameters ▼ fn: Callable the function to wrap the chat interface around. Should accept two parameters: a string input message and list of two-element lists of the form [[user_message, bot_message], ...] representing the chat history, and return a string response. See the Chatbot documentation for more information on the chat history format. multimodal: bool default = False if True, the chat interface will use a gr.MultimodalTextbox component for the input, which allows for the uploading of multimedia files. If False, the chat interface will use a gr.Textbox component for the input. type: Literal['messages', 'tuples'] default = 'tuples' The format of the messages passed into the chat history parameter of `fn`. If 'messages', passes the value as a list of dictionaries with openai-style 'role' and 'content' keys. The 'content' key's value should be one of the following - (1) strings in valid Markdown (2) a dictionary with a 'path' key and value corresponding to the file to display or (3) an instance of a Gradio component. At the moment Image, Plot, Video, Gallery, Audio, and HTML are supported. The 'role' key should be one of 'user' or 'assistant'. Any other roles will not be displayed in the output. If this parameter is 'tuples', expects a `list[list[str | None | tuple]]`, i.e. a list of lists. The inner list should have 2 elements: the user message and the response message, but this format is deprecated. chatbot: Chatbot | None default = None an instance of the gr.Chatbot component to use for the chat interface, if you would like to customize the chatbot properties. If not provided, a default gr.Chatbot component will be created. textbox: Textbox | MultimodalTextbox | None default = None an instance of the gr.Textbox or gr.MultimodalTextbox component to use for the chat interface, if you would like to customize the textbox properties. If not provided, a default gr.Textbox or gr.MultimodalTextbox component will be created. additional_inputs: str | Component | list[str | Component] | None default = None an instance or list of instances of gradio components (or their string shortcuts) to use as additional inputs to the chatbot. If components are not already rendered in a surrounding Blocks, then the components will be displayed under the chatbot, in an accordion. additional_inputs_accordion: str | Accordion | None default = None if a string is provided, this is the label of the `gr.Accordion` to use to contain additional inputs. A `gr.Accordion` object can be provided as well to configure other properties of the container holding the additional inputs. Defaults to a `gr.Accordion(label='Additional Inputs', open=False)`. This parameter is only used if `additional_inputs` is provided. examples: list[str] | list[MultimodalValue] | list[list] | None default = None sample inputs for the function; if provided, appear within the chatbot and can be clicked to populate the chatbot input. Should be a list of strings if `multimodal` is False, and a list of dictionaries (with keys `text` and `files`) if `multimodal` is True. Should also include values for the additional inputs if they are provided. example_labels: list[str] | None default = None labels for the examples, to be displayed instead of the examples themselves. If provided, should be a list of strings with the same length as the examples list. example_icons: list[str] | None default = None icons for the examples, to be displayed above the examples. If provided, should be a list of string URLs or local paths with the same length as the examples list. cache_examples: bool | None default = None if True, caches examples in the server for fast runtime in examples. The default option in HuggingFace Spaces is True. The default option elsewhere is False. cache_mode: Literal['eager', 'lazy'] | None default = None If 'lazy', then examples are cached (for all users of the app) after their first use (by any user of the app). If 'eager', all examples are cached at app launch. If None, will use the GRADIO_CACHE_MODE environment variable if defined, or default to 'eager'. title: str | None default = None a title for the interface; if provided, appears above chatbot in large font. Also used as the tab title when opened in a browser window. description: str | None default = None a description for the interface; if provided, appears above the chatbot and beneath the title in regular font. Accepts Markdown and HTML content. theme: Theme | str | None default = None a Theme object or a string representing a theme. If a string, will look for a built-in theme with that name (e.g. 'soft' or 'default'), or will attempt to load a theme from the Hugging Face Hub (e.g. 'gradio/monochrome'). If None, will use the Default theme. css: str | None default = None Custom css as a code string. This css will be included in the demo webpage. css_paths: str | Path | list[str | Path] | None default = None Custom css as a pathlib.Path to a css file or a list of such paths. This css files will be read, concatenated, and included in the demo webpage. If the `css` parameter is also set, the css from `css` will be included first. js: str | None default = None Custom js as a code string. The custom js should be in the form of a single js function. This function will automatically be executed when the page loads. For more flexibility, use the head parameter to insert js inside