liveBook · Manning

Chapter 8: Building a web UI with Streamlit

What you will learn in chapter 8 of Build Applications with Local AI Models on a Mac

This introduction explains why the local AI chat application needs a web interface and why Streamlit makes one approachable using Python alone.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This introduction explains why the local AI chat application needs a web interface and why Streamlit makes one approachable using Python alone.

Key terms: Streamlit, web interface, LLM backend, Python API layer, Python, HTML, CSS, JavaScript, interactive web application

8.1 What Is Streamlit?

This section explains how Streamlit turns Python function calls into a web interface and why it suits a beginner-built AI chatbot.

Key terms: Streamlit, st.title(), st.text_input(), data apps, dashboards, AI chatbot interface, backend infrastructure, Python-only, Sensible defaults

8.2 Your first Streamlit app

This section introduces the upcoming steps for creating and running a Streamlit app in the existing project folder.

8.2.1 Step 1: Install Streamlit

This subsection prepares the existing chatbot project to use Streamlit by activating its virtual environment and installing Streamlit if needed.

Key terms: my-ai-chatbot, virtual environment, Streamlit, source .venv/bin/activate

8.2.2 Step 2: Create the app file

This section has the reader create a small Streamlit app file and record Streamlit as a project dependency.

Key terms: app.py, import streamlit as st, st, Streamlit, requirements.txt, dependency

8.2.3 Step 3: Run the app

This section explains how to launch the first Streamlit app, what to expect when it opens, and how to handle two browser display problems.

Key terms: Streamlit, python app.py, Hello, Streamlit!, Streamlit server, Safari, HTTP-only warning, http://localhost

8.2.4 Step 4: Add interactivity

This section makes a Streamlit app interactive by showing a greeting when the user enters a name and explaining how to see the saved change in the browser.

Key terms: text input, if name:, empty string, greeting, Rerun, Always Rerun, refresh

8.2.5 How Streamlit’s execution model works

This section explains how Streamlit reruns a Python script after user interactions and why that makes interactive code simpler.

Key terms: rerun, st.text_input(), if name:, st.write(), callbacks, event handlers, top-to-bottom Python

8.3 Core Streamlit components

8.3.1 Text display

This section introduces Streamlit text-display functions and highlights st.write() as a flexible default.

Key terms: st.write(), strings, numbers, dataframes, charts, text display, import streamlit as st, streamlit run

8.3.2 User input

This section explains how Streamlit input widgets make a user’s current input available to application code.

Key terms: widgets, user input, current value, return value, variable

8.3.3 Buttons and actions

This section explains how a Streamlit button triggers an action and why its output disappears after another interaction.

Key terms: st.button, Generate, rerun, if block

8.3.4 The sidebar

This section explains how Streamlit places content in a collapsible sidebar and how a chatbot can separate settings from conversation.

Key terms: sidebar, expanded=True, with st.sidebar:, main content area

8.3.5 Column layout

This section shows how Streamlit columns place content side by side and how that layout may change in a narrow browser window.

Key terms: st.columns(), columns

8.4 Running Streamlit apps

8.4.1 Starting and stopping

Explains what happens when a Streamlit app starts and how to stop its development server.

Key terms: development server, browser, Ctrl-C

8.4.2 Auto-reload

This section explains how to see changes to a running Streamlit app after saving its Python file.

Key terms: Always Rerun, Rerun, auto-reload

8.4.3 Ports and multiple apps

This section explains how ports let Streamlit run multiple apps on the same computer.

Key terms: port, default port, 8501, next available port

8.4.4 The development workflow

This subsection recommends a side-by-side editor and browser setup for a fast, iterative Streamlit development cycle.

Key terms: Streamlit development cycle, VS Code, browser

8.4.5 Helpful command-line options

This subsection introduces Streamlit run flags for choosing a port and controlling whether the browser opens automatically.

Key terms: streamlit run, flags, port

8.5 Putting it all together

The section uses a personalized greeting app to show how Streamlit combines sidebar settings with input and content in the main area.

Key terms: sidebar, text input, conditional logic, column layout

8.6 Exercises

8.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 7: Controlling LLMs with the Ollama Python library Chapter 9: Recording audio and transcribing speech with MLX Whisper →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.