
Deploy an LLM-powered Shiny for Python app to Connect Cloud in minutes!
Connect Cloud lets you quickly deploy data applications and documents from public GitHub repositories for Python and R projects. This short demo showcases secret variable management on Connect Cloud to help deploy an LLM-powered Shiny for Python application. → Signup for a free Connect Cloud account → https://connect.posit.cloud/ → View the how-to guide → https://docs.posit.co/connect-cloud/how-to/python/llm-shiny-python.html
image: thumbnail.jpg
Transcript#
This transcript was generated automatically and may contain errors.
Hi everyone, my name is Alex Chisholm. I am a product manager here at Posit and I'm currently working on Connect Cloud. Today in this short demo, I want to go through and look at a Shiny for Python application that's going to give us the ability to leverage an OpenAI API key and automatically generate some datasets and then see how easy it is to take that from a public GitHub repo and put it up on Connect Cloud.
So here is the application running locally. We give users the ability to describe a specific dataset that they're looking for. When they click on generate dataset, it's going to go off over to OpenAI using chat GPT, come back here and give us a data table, we hope. So let's start with maybe something simple. Most popular Python packages for data science. So it's going to go back, grab this information in some way, create this information, and we can see we have a package name and we have the number of downloads. If I filter this, we can see the packages at the top are at least believable, although I have no idea where the numbers came from or when they are from.
We could also do something like family health data for 25 extended relatives. Now it's going to go up, and what I hope is create completely fictitious data, and we have age and heart rate for 25 people. So nothing super sophisticated, but kind of interesting, and then we give users the ability to download this synthetic dataset as a CSV file.
Walking through the code
If we go over to GitHub, we can find our code. So here is the repo. We have a README file, a requirements file, and our application file. In the requirements file, you can find Shiny, pandas, and requests with specific versions that work with this example. And if I go into my main application file, app.py, you can get a sense for what the code looks like.
The biggest thing for this example is that we do need to bring in an OpenAI API key, which we do here through an environment variable, and that we will later store on Connect Cloud securely. You can see on the UI side, we essentially have a sidebar and a main panel where the data table is going to be shown to users. And the two things that I want to show you in the code are where the OpenAI API key come to play. We're going to actually go ahead and call twice.
So we're going to take our description from what the user said. We're going to say, generate a fake dataset with at least two variables as a CSV string based on the description provided. That's going to come back and return the CSV format for this. Then we're going to pass it back a second time and say, give us a brief summary of the dataset. That's pretty much it. At a later date, we'll do a full tutorial on how this thing was built up and how each piece of code helps the application function. But now I want to go back into Posit Connect Cloud.
Deploying to Connect Cloud
I want to log into the system. I'm going to go ahead and log in with GitHub. I already have an account, so this should let me in fairly quickly. And then once I'm in, you can see the portfolio of work that I've published already.
But we want to do a new publish here. I'm going to go out and hit publish. I'm going to click Shiny. I'm going to pull up the repo that I'm looking for. And in this case, I'm actually going to go out and grab this specific address here. If it was my own repo in my own account, I'd be able to pull it up automatically. Then I'm going to say app.py. And this is really all I need to set, with the exception of that OpenAI API key.
So I also want to bring in a configurable variable here that Connect Cloud will store securely. So I need to pass in the variable name that we're going to be looking for in the application. And I also need to go find the API key from OpenAI. So the way that you would do this in OpenAI, you go to your platform, you log in, if you click on dashboard, API keys, create new secret key. This will give you a long string that you can use for the project.
I'm going to go ahead and copy the actual one I used for this project from a different screen. Go back to Connect Cloud, paste in that variable. Now we have our OpenAPI key stored securely. I'm going to press publish.
When I do this, we're going to go out, we're going to clone that public repository. We're going to install all the dependencies needed for the application. And then we're going to publish the application to Connect Cloud. This should take around 10 to 15 seconds. And we have that same app that we had before.
So let's take another look. We can go see popular data science packages in Python. I'm going to generate that data set. It should come back. Perfect. Now we added stars with the different prompt that I passed through this time. I can download the CSV file and I can also share my application by clicking on this. And sharing the URL with anyone who is interested.
So in a relatively short period of time, we were able to go through, take a look at this LLM powered Shiny for Python application, and then deploy it to Connect Cloud.
So in a relatively short period of time, we were able to go through, take a look at this LLM powered Shiny for Python application, and then deploy it to Connect Cloud.
