![]() For example, here if you instantiate the Image component with the following parameters, it will convert the image to the PIL type and reshape it to be (100, 100) no matter the original size that it was submitted as: ![]() You can control the preprocessing using the parameters when constructing the image component. Similarly, when a component is used as an output, Gradio automatically handles the postprocessing needed to convert the data from what is returned by your function (such as a list of image paths) to a form that can be displayed in the user's browser (such as a Gallery of images in base64 format). When a component is used as an input, Gradio automatically handles the preprocessing needed to convert the data from a type sent by the user's browser (such as a base64 representation of a webcam snapshot) to a form that can be accepted by your function (such as a numpy array). Most components can be used both as inputs or outputs. Preprocessing and PostprocessingĪs you've seen, Gradio includes components that can handle a variety of different data types, such as images, audio, and video. Users will have to select one of the strings when flagging, which will be saved as an additional column to the CSV. If you wish for the user to provide a reason for flagging, you can pass a list of strings to the flagging_options argument of Interface. You can also add the info= keyword argument to form elements like Textbox or Radio to provide further information on their usage. This modifies the label text at the top of each Component. If you're using the Blocks API instead, you can insert text, markdown, or HTML anywhere using the gr.Markdown(.) or gr.HTML(.) components, with descriptive content inside the Component constructor.Īnother useful keyword argument is label=, which is present in every Component. article: which also accepts text, markdown or HTML and places it below the interface.description: which accepts text, markdown or HTML and places it right under the title.title: which accepts text and can display it at the very top of interface, and also becomes the page title.There are three arguments in the Interface constructor to specify where this content should go: In the previous example, you may have noticed the title= and description= keyword arguments in the Interface constructor that helps users understand your app. ![]() If you try to divide by zero in the calculator demo above, a popup modal will display the custom error message. To do so, raise a gr.Error("custom message") to display an error message. You wish to pass custom error messages to the user. The examples will be automatically paginated (you can configure this through the examples_per_page argument of Interface).Ĭontinue learning about examples in the More On Examples guide. You can load a large dataset into the examples to browse and interact with the dataset through Gradio. Allows you to calculate things like $2+2=4$", Gr.Radio(),ĭescription="Here's a sample toy calculator.
0 Comments
Leave a Reply. |