Getting ready to put it all together: Build a Streamlit app
1. Getting ready to put it all together: Build a Streamlit app
We have covered a lot in this module. In this video, we're going to put all 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 two and download the call transcripts analytics app Python file that has all the source code needed to build the AI app. Now we have downloaded the source code needed to build the Streamlit app. Next up, log into your Snowflake account and navigate to the projects tab in the left panel and select Streamlit. Select the blue button on the upper right side of the screen which reads Streamlit app to create your app. On the pop-up, name your app. I'm calling it call underscore center underscore analytics underscore app. Choose your app location by selecting the pull down. Choose the database as SkiGear support DB and schema as SkiGear support schema and warehouse as compute warehouse. Select create. Streamlit starts this with some sample code on the left pane. If you do not see this, select the edit button on the upper right to get back to it. 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 code does for the time being. We will come back to them in a few minutes. Once you pasted the code from the Python file, click run on the top right of the page. Click run on the top right of the screen. The Streamlit app has a text box called JSON summary. Click on the arrow right next to it and you see a dropdown list. From the dropdown, you can pick JSON summary or translate or sentiment analysis. I am going to select JSON summary. And in the right pane, a text box appears asking us to enter the call transcript. I am going to select the example transcript variable from our code snippet and paste it in the text box on our app. And run the app. You can see that the model is able to summarize it in JSON format with three keys, product, defect, and summary. Very cool. Next, we are going to go back to the code and switch out the LLM we call for another one to see the differences in performance. Go to line 29 where we call Snowflake Cortex complete function and switch out the function parameter. Replace Mistral Large with Llama3.1 70 billion. Click run on the top right. If your account is set up on AWS West to Oregon region, this should run no problem. Not all models are available in all regions, so if you have problems running the Llama3.1 70 billion, check the region of your account. Now you have your app. Let's take a look at the code that created this app. If the source code is not visible, click on edit at the top right of the app UI. We have the Python code right in front of us. On the top left, just when the source code starts, you see packages drop down list. You can use that to install the packages you need for the app. I have Python 3.8, Snowflake Snowpark Python, and Streamlit packages installed. 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. Imported the Snowflake session to run the app and Streamlit, of course, to create the app. Next up, we have defined the example transcript, so it's handy for you to copy paste this into the app's text box later. We've not used it in the code anywhere. Great. In the source code, we have three functions defined. First is the summarize function. We defined the prompt and invoked cortex-complete with Mistral Large for summarization. We could also use task-specific LLM function 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 the translate Python function we defined, we invoke task-specific translate LLM function under the hood. Similarly, for 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 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've 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 we created. In the next video, we will review what we 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.