From the course: Build with AI: LLM-Powered Data Analysis App with Python and Streamlit

Create a basic Streamlit application

- [Instructor] Welcome to the Streamlit section of this course. Let's start by setting up a basic Streamlit application. In your GitHub repo, create a new codespace on main. Once you have this set up, open up the app.py file in the repository. This file should be empty at this stage. First, let's import Streamlit as st in our Python file. Before we display anything, let's configure our page settings. We'll use the built-in function st.set_page_config to do this. This configuration does three things. One, it sets the browser tab title to Ask Your CSV. Two, it adds a char emoji as a favicon. This emoji is optional. And three, it uses the wide layout for better screen real estate. I recommend you use this function for every Streamlit app that you build, as these small touches can make your MVP feel more professional right from the start. Let's go ahead and give our app a title using st.title. To run this Streamlit app, in the terminal, type in the command streamlit run app.py Streamlit will spin up a local server, will follow the local URL link to open up a browser page. This is your live Streamlit app running in your local environment. Notice the wide layout we configured and the custom page title in the browser tab. Any code changes that you save in the notebook will automatically be reflected on this browser page once you hit Refresh. This is called hot reloading, a feature that allows developers to see changes instantly without restarting the application. It's one of the many reasons Streamlit is perfect for rapid prototyping. As your app gets more complex, you'll want to organize your code. For example, you can move helper functions into a separate file like functions.py and import them into the main file. This keeps your main app script clean and maintainable. In the next video, we'll start building the user interface with the Streamlet's powerful widget system.

Contents