Skip to content

Step 8 – Pipelines & Deployment (The Clinical Interface)

8 - Pipelines & Deployment (The Clinical Interface)

Section titled “8 - Pipelines & Deployment (The Clinical Interface)”

Streamlit (The App Builder) & Docker (The Shipping Container)

Streamlit turns Python scripts into shareable web apps without hand-writing HTML/CSS/JS. Docker packages code, runtimes, and system dependencies into containers so the app runs the same on laptops, hospital servers, or the cloud.

  • Cockpit (Streamlit): Buttons, file upload, sliders, and a clean dashboard—no terminal required during consults.
  • Box (Docker): Seals your code, exact Python version, and libraries into a portable container—no “works on my machine” issues.
  • User Interface: Upload slides, tweak sensitivity, view heatmaps in a browser.
  • Reproducibility: Freeze the environment for audits and long-term consistency.
  • Portability: Move from MacBook to hospital Linux cluster without rewriting code.

Situations where it’s used (Medical Examples)

Section titled “Situations where it’s used (Medical Examples)”
  • Second Opinion App: Share a Streamlit link; colleagues upload microscope photos and get counts or risk scores.
  • LIMS Integration: IT consumes a Docker image instead of installing PyTorch manually; plugs into lab workflow.

A model in a notebook cannot help a patient. Deployment crosses the translational gap: math → medicine.

Run in terminal:

Terminal window
pip install streamlit

Docker is separate; install Docker Desktop from docker.com if you need container builds.

Block A: The “One-Click” App (Streamlit)

Section titled “Block A: The “One-Click” App (Streamlit)”

The Situation: You have a trained model and need a clinician-friendly UI.
The Solution: A tiny app.py that uploads an image, runs inference, and displays a clear result.

import streamlit as st
from PIL import Image
import numpy as np
import time
st.title("🧬 AI Tumor Detector")
st.write("Upload a histology patch to screen for malignancy.")
uploaded_file = st.file_uploader("Choose a histology image...", type=["jpg", "png", "tif"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Patch", width=300)
if st.button("Analyze Patch"):
with st.spinner("AI is examining cellular morphology..."):
time.sleep(2) # simulate processing
# --- REAL AI WOULD GO HERE ---
prediction_score = np.random.random() # demo score 0.0–1.0
st.subheader("Diagnosis Report")
if prediction_score > 0.5:
st.error(f"⚠️ MALIGNANT DETECTED (Confidence: {prediction_score:.2%})")
else:
st.success(f"✅ BENIGN / NORMAL (Confidence: {1-prediction_score:.2%})")
st.info("Note: This is an investigational device. Verify all results.")

Run with: streamlit run app.py

Block B: The “Freeze” (requirements.txt)

Section titled “Block B: The “Freeze” (requirements.txt)”

The Situation: You installed many libraries; colleagues need the exact list.
The Solution: Record dependencies so others (or Docker) can install them consistently.

# Typically you run: pip freeze > requirements.txt
# Here is a sample contents you could write manually:
requirements_content = """
pandas==2.0.3
openslide-python==1.3.1
torch==2.0.1
torchvision==0.15.2
streamlit==1.25.0
opencv-python-headless==4.8.0
"""
with open("requirements.txt", "w", encoding="utf-8") as f:
f.write(requirements_content)
print("Dependencies saved to requirements.txt")
print("Install with: pip install -r requirements.txt")

Block C: The “Shipping Box” (Dockerfile)

Section titled “Block C: The “Shipping Box” (Dockerfile)”

The Situation: IT wants a container, not a manual setup.
The Solution: A Dockerfile that builds a portable image; Streamlit listens on port 8501.

# Save this as Dockerfile (no extension)
# 1. Base image with Python
FROM python:3.9-slim
# 2. Workdir
WORKDIR /app
# 3. Copy and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 4. Copy application code
COPY . .
# 5. Default command
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]