Streamlit is an incredibly powerful and versatile tool, making it essential to invest your time in truly grasping its full potential!
It is a Python library that converts scripts into reactive web apps — without HTML, CSS, or JS.
Each Streamlit run is stateless by default, hence you need to append conversation history yourself. Streamlit shines when connected to AI models, APIs, or databases. Streamlit can host your AI or RAG agents beautifully.
import streamlit as st
from langchain.llms import OpenAI
st.title("My AI Assistant")
if "history" not in st.session_state:
st.session_state.history = []
user_input = st.text_input("Ask something:")
if user_input:
llm = OpenAI(api_key=st.secrets["openai_key"])
response = llm.invoke(user_input)
st.session_state.history.append((user_input, response))
st.write(response)