From notebook to shipped app

In Lesson 04, you built a ChatSession in a notebook. It worked. You fed it prompts, it remembered context, you saw the magic. But your friend can't run Jupyter. Non-technical people need a UI.

Streamlit bridges that gap: a Python framework that turns scripts into interactive web apps in minutes. No HTML, no JavaScript, no server setup. You write Python; Streamlit handles the UI and runs it in a browser.

Notebook + ChatSession
→
Streamlit app.py
→
Live URL (Streamlit Cloud)

By the end of this lesson, your agent will have a professional chat UI, persist memory across browser reloads, and run on a free cloud server anyone can visit.

Streamlit in 5 minutes

Three commands get you started:

streamlit_setup.sh Install and run your first Streamlit app

A minimal Streamlit app:

minimal_app.py Smallest working Streamlit app
Key insight:
Streamlit runs your script top-to-bottom on every interaction. When the user clicks a button or types in a text box, the entire script reruns. This is both a strength (simple) and a challenge (you need to manage state with `st.session_state`).

Building a chat UI around ChatSession

Streamlit has chat-specific widgets: `st.chat_input()` for the user's message box, and `st.chat_message()` to display messages as cards. Here's a working chat app that uses your ChatSession from Lesson 04:

🤖
Real scenario
SouthBank India chat agent — polished UI

A user opens the app in their browser. They see a chat interface. They type "What's my balance?" The agent responds. On the next message, the agent still remembers the account number from the first turn. All messages appear in a clean chat log.

app.py Streamlit chat UI with ChatSession
What you'll see in browser
SouthBank India Agent Chat with your banking assistant User: What's my balance? Agent: Hi! To help you check your balance, please share your account number... User: Account SB-2026-9001. Agent: Your balance is ₹23,500...

Session state: memory persists across reruns

The magic of `st.session_state` is that it remembers data across page reloads. Every time the user sends a message, Streamlit reruns your script. Without session state, the ChatSession would reset. With it, the same ChatSession object stays in memory for that browser session.

session_state_pattern.py Session state persistence (pattern used above)
Why this matters:
Session state is scoped to one browser tab. If a user closes the browser and comes back 24 hours later, their chat history is lost. To save conversations permanently, you'd save to a database or JSON file—but for demos, session state is enough.

Display tool calls: show work-in-progress

When an agent calls a tool (search, database query), users want to see it happening. Streamlit's status containers let you show "🔧 Searching for HDFCBANK.NS..." as the agent works.

tool_call_display.py Show tool calls with st.status()

Streaming responses: watch tokens appear

Instead of waiting for the full response, users enjoy watching tokens stream in. Streamlit's `st.write_stream()` shows words as they arrive from the LLM.

streaming.py Stream LLM responses token-by-token
User experience boost:
Streaming makes the app feel snappier. Instead of a 3-second blank wait, users see text appearing immediately. Token streaming is now standard for chat apps.

Deploy free to Streamlit Cloud

Streamlit Cloud is free, GitHub-connected, and handles all infrastructure. Three steps:

Step 1: Push code to GitHub

Create a repo with your `app.py` and a `requirements.txt`:

requirements.txt Python dependencies for Streamlit Cloud

Step 2: Connect your GitHub repo

Go to streamlit.io/cloud, sign in with GitHub, select your repo, and click "Deploy". Streamlit runs `pip install -r requirements.txt` and starts your app.

Step 3: Your app is live

Streamlit assigns you a URL like https://yourname-agentwiki.streamlit.app. Share it. Your agent is now live on the internet.

On-premise alternative:
If you control your own server (AWS, DigitalOcean, Heroku), run `streamlit run app.py` with `--server.port 80` to expose the app on the web. Streamlit Cloud is simpler for demos.

Secrets: Ollama endpoint, API keys

Never hardcode API keys or endpoints in your code. Streamlit has a secrets file.

Locally: Create `.streamlit/secrets.toml`:

.streamlit/secrets.toml Local secrets file (gitignore this)

In your app, access via `st.secrets`:

using_secrets.py Access secrets in code

On Streamlit Cloud: Go to your app's settings, paste secrets in the UI, and Streamlit injects them at runtime. Your code reads them the same way: `st.secrets["key"]`.

Making it presentable: portfolio-ready polish

This is a demo of your work. Polish it. Add a logo, description, and professionalism.

polished_app.py Production-ready Streamlit agent
Portfolio impact:
When you interview, this is tangible. You can say: "I built a customer support agent, shipped it to production, and 500+ people used it." That beats vague resume bullets.
🎯 Mini Challenge: Deploy a Jumia Kenya bot

Task: Create a Streamlit app for a Jumia Kenya customer support bot. Include:

1. Chat interface with st.chat_input

2. Model picker in sidebar (llama3.2, mistral)

3. Temperature slider (0.0–2.0)

4. Reset button

5. At least one message in chat history showing order context

Run locally with `streamlit run app.py`.

Hint: Combine the chat UI code from Section 3 with sidebar controls from Section 5. Initialize st.session_state with a ChatSession. For the system prompt, use something like "You are Aisha, Jumia Kenya support agent. Help with orders and refunds."

How production AI systems use this

Every major AI company (OpenAI, Anthropic, Google) runs Streamlit instances, Flask apps, or custom UIs on top of their LLMs. The pattern is identical: a web framework (Streamlit, React, Flutter) talks to an LLM backend (locally or via API), manages conversation state, and streams responses. Streamlit is the fastest path from "working agent" to "shipped product"—which is why startups use it to demo to investors.

UI Frameworks Deployment Patterns State Management Production Agents

Test your knowledge

Question 1 of 5
Why does Streamlit's entire script rerun on every user interaction?
Question 2 of 5
What does `st.session_state` preserve?
Question 3 of 5
What is the primary benefit of `st.write_stream()`?
Question 4 of 5
How do you deploy a Streamlit app for free on the internet?
Question 5 of 5
Where should API keys and Ollama endpoints be stored in a Streamlit app?
0
/5
Excellent! You're ready to ship Streamlit agents to production.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

Your agent is live.
Now build the next one.

Join the Best AI Program: The AI-Era Agentic Engineer — 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Agentic Engineer →