Get startedGet started for free

Getting ready to put it all together: Build a Streamlit app

1. Getting ready to put it all together: Build a Streamlit app

We've covered a lot in this module. In this video, we're going to put all of our learnings together to build an AI application using Streamlit that uses LLM functions as building blocks of that application. First, the scenario. We will be playing the part of an analyst that has a volume of customer support tickets that we need to process to understand the concerns that our customers are telling us about. The volume of support tickets is too large and it arrives in different languages, so handling it manually is not feasible. We need a way to automate this and make it faster and efficient for the support teams. Before we build an app to help our support teams, pause the video and navigate to the Git companion repo for this course. It is highlighted in the reading prior to this video. Click on the repo URL and navigate to module 2 and download the call transcripts analyst app Python file that has all the source code needed to build the AI app. Now we have the downloaded source code needed to build the Streamlit app. Next up, log into your Snowflake account and navigate to the projects tab on the left and select Streamlit. Choose your application by selecting the pull-down. Choose the database as Ski Gear Support DB and the schema as Ski Gear Support Schema and the warehouse as compute warehouse. Select create. Streamlit starts this with a sample code on the left pane. If you do not see this, select the edit button on the upper right to get it back. Copy the Python code we downloaded earlier and paste it into the left pane of the Snowsight UI. Let's not worry about what each line of the code does for the time being. We will come back to them in a few minutes. Once you paste the code on the Python file, click run on the top right of the screen. The Streamlit app has a text box called JSON summary. Click on the arrow on the right to it and you'll see a drop-down list. From the drop-down, you can pick JSON summary or translate or sentiment analysis. I'm going to select JSON summary. In the right pane, the text appears asking us to enter the call transcripts. I'm going to select the example transcript variable from our code stack and paste it into our text box on our app. And then run the app. You can see the model is able to summarize it in a JSON format with three keys. Product, defect, and summary. Very cool. Next, we're going to go back to the code and run the same call for another one to see the difference in performance. Go to line 29 where we call Snowflake Cortex complete function and switch out the function parameter. Replace Mistral Large with Llama 3.1, which is the best model for this use case at the time of the recording. Click run at the top right. If your account is set up on AWS US West 2 Oregon region, this should run with no problem. Not all models are available in all regions, so if you have a problem running with Llama 3.1, check the region of your account. Now you have your app. Let's take a look at the code that created this app. You don't need to install additional packages for this project, so we're all set. We start the code off with a bunch of import statements. Import the Snowflake session to run the app and Streamlit, of course, to create the app. Next up, we have defined example transcripts, so it's handy for you to copy-paste this into the app's text box later. We have not used it in the code anywhere. Great! In the source code, we have three functions defined. First is the summarize function. We define the prompt and invoke Cortex Complete with Mistral Large for summarization. We could also use task-specific LLM functions to summarize, but I have used a mix of complete and task-specific LLMs in the app to show how you could use a variety of these functions together to build an app. Next for translate Python function we defined, we invoke task-specific translate LLM function under the hood. Similarly, for the sentiment analysis Python function, we call the task-specific sentiment LLM function under the hood. Well done! You have successfully set up an app that translates, summarizes, and runs a sentiment analysis. You looked at how using different LLMs produce different completions, and the reasons to compare different LLMs while prototyping. Nice work! Play around with what you learned here and see what variations you can build for your own use cases. Everyone learns by doing, so I recommend that you experiment with what you've learned here using different models or producing variations on the Streamlit app that we created. In this next video, we'll review what we've covered in this module. See you then!

2. Let's practice!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.