Gradio
Gradio is an open-source Python package that allows you to quickly build a demo or web application for your machine learning model, API, or any arbitrary Python function.
Deploying
Deploy Gradio app with the rsconnect-python
package.
When deploying a Gradio app, ensure that you specify the correct entrypoint
. for the specific application you are deploying. The example application on this page has its source code in a file named app.py
. The application object is named demo
. Therefore, the entrypoint for this application is app:demo
. See the documentation on entrypoints for more information.
rsconnect deploy gradio -n <saved server name> --entrypoint app:demo
Example app
app.py
import gradio as gr
def greet(name):
return "Hello " + name + "!"
= gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
demo
if __name__ == "__main__":
demo.launch()
To deploy this example, first save the code to a file named app.py
.
Install any required dependencies. Then, test the app locally:
python app.py
Then deploy to Posit Connect:
rsconnect deploy gradio -n <saved server name> app.py
User meta-data
import gradio as gr
def get_user_info(text, request: gr.Request):
= request.headers["RStudio-Connect-Credentials"]
user_info return {
"user_info": user_info
}
= gr.Interface(get_user_info, "text", "json")
demo demo.launch()
User and group uniqueness
Most environments have unique usernames where each user
identifies a single user and groups
the name of the groups the user is a member of.
However, in large organizations with hundreds of users and groups, this may not be true. See the Admin Guide Credentials for Content sections for more information.
Models and data
Code that relies on the transformers
or datasets
library may attempt to fetch data from the Hugging Face Hub as the application starts. Depending on the networking configuration of the Connect server, this may result in failed deployments or application timeouts.
To work around this issue:
- Ask your administrator to configure a directory that Connect can use to cache downloaded data.
- Set the environment variable
HUGGINGFACE_HUB_CACHE
on a per-application basis or in a supervisor script. - Increase the initial timeout for the application.
For smaller volumes of data, you can also download the required data and include it as part of your deployment. See the Hugging Face Transformers documentation for more information.
Alternatively, if your model framework enables installing trained pipelines as Python pacakages, you can specify the URL to those Python packages in the requirements.txt
file for your application, which Connect will use to download the pipeline while reconstructing your app environment. See the Spacy documentation for an example: https://spacy.io/usage/models#download-pip
Limitations
Git LFS
Connect does not currently support Git LFS.
Flagging
Flagging is disabled.