0
RAG Engineering
Phase 3Module 17 of 18

Streamlit

Stakeholders need to try AI features before production. Streamlit lets engineers demo LLM apps in hours, not weeks.

Streamlit is the PowerPoint of AI prototypes — paste Python, get a shareable UI instantly.

Visual Workflows

Start here — study each diagram, then use + / to zoom if needed.

100%
Loading diagram...

Scroll inside the frame · use + / − to zoom

Key Takeaways

  • 1.Streamlit turns Python scripts into interactive web apps — ideal for prototyping RAG chatbots and agent demos without frontend code.
  • 2.Uses st.chat_message, st.session_state for conversation history, st.sidebar for config, and reruns the script top-to-bottom on interaction.
  • 3.Pair with LangChain or direct API calls.
  • 4.Not for high-scale production — use FastAPI + React for that.

Real Example

Scenario

A 50-line Streamlit app with a chat input, message history, and OpenAI API call becomes a demoable RAG assistant.

What you would do

In RAG Engineering, apply Streamlit to this scenario: A 50-line Streamlit app with a chat input, message history, and OpenAI API call becomes a demoable RAG assistant. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

Practice Task

Open the Code Walkthrough below and run it locally. Change one parameter related to Streamlit (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

Code Walkthrough

Highlighted lines show where Streamlit happens in the code.

Streamlit
1import streamlit as st  # import dependencies2from openai import OpenAI  # import dependencies3client = OpenAI()  # create API client4st.title("RAG Demo")5if "messages" not in st.session_state:6    st.session_state.messages = []7for msg in st.session_state.messages:8    st.chat_message(msg["role"]).write(msg["content"])9if prompt := st.chat_input("Ask something"):10    st.session_state.messages.append({"role": "user", "content": prompt})11    reply = client.chat.completions.create(model="gpt-4o-mini", messages=st.session_state.messages)  # call the API12    answer = reply.choices[0].message.content13    st.session_state.messages.append({"role": "assistant", "content": answer})14    st.chat_message("assistant").write(answer)

Cheat Sheet

Quick recap

quick ref
  • Streamlit
  • Session State
  • Prototyping
  • Chat UI

Common Mistakes

  • Treating Streamlit as a black box without evaluation
  • Ignoring cost and latency in production
  • Skipping error handling for streamlit