From the course: Build with AI: LLM-Powered Applications with Streamlit
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Build chat features: Add input and display messages - Python Tutorial
From the course: Build with AI: LLM-Powered Applications with Streamlit
Build chat features: Add input and display messages
- [Narrator] Let's wrap up building your foundations by using what you learned so far with building a Streamlit app and incorporating widgets. Let's take this to the next level by turning your widgets into a working chat box. For this video, let's work with file 01_04b.pi, which you could see off to the left side here, and I have it open for you right here. Like for most of these, you'll want to import your Streamlit package, which should already be in this beginner file. Next, you'll want to write a title using st.title since it is great to have a clear title for your users to understand what your application is. Let's call this one chat input and display. Something important to know is Streamlit reruns your script, top to bottom, on every interaction you have with it. To remember data between these different runs, you can store it in what is called st.session_state. Here, you will initialize chat history by seeing if chat_history is not in the st.session_state. You'll then…