Full-Stack AI Product — From Data to Deployed, Portfolio-Ready Solution
Design, build, evaluate, containerize, and deploy a customer churn predictive API combined with an interactive Generative AI mitigation advisor.
Domain / Environment
Full-Stack AI / Docker / Conda VM
Difficulty
Expert (5/5)
Course Module
Capstone & Career Preparation
Deliverables
Full-stack web application, Docker container, and GitHub-ready README
1. Full-Stack Product Architecture
The diagram below displays the end-to-end full-stack AI product architecture. The user submits customer feature inputs through a Streamlit UI dashboard. The inputs are evaluated by the predictive model and parsed by the LangChain RAG advisor, returning recommendations to the user interface.
2. Part 1: Step-by-Step Action Items & Key Execution Steps
STEP 1
Activate Python Virtual Environment
Point the terminal execution environment to the course conda sandbox environment.
$ conda activate ds_ai_ml
This targets active python libraries to the isolated virtual sandbox.
STEP 2
Create Project Folders inside Linux VM
Create a dedicated folder for the project files inside your guest VM home folder directory.
$ mkdir -p ~/Projects/final_capstone && cd ~/Projects/final_capstone
This sets up the working directory layout for the capstone project files.
STEP 3
Install dependencies via Pip
Install Streamlit, FastAPI, Uvicorn, and LangChain inside the active conda session.
This installs the components for the UI dashboard, FastAPI backend endpoints, and LangChain advisor tools.
STEP 4
Create product files in VS Code
Launch VS Code and create the project script files.
Launch VS Code via terminal "code ." -> New File -> Type: app.py -> Paste Python code -> Save file
This registers the predictive model logic, LangChain advice generation, and Streamlit dashboard layout in `app.py`.
STEP 5
Create Docker Configuration File
Create a Dockerfile to package the application.
New File -> Type: Dockerfile -> Paste configuration script -> Save file
This registers base image configurations, copies source code files, and exposes application network ports.
STEP 6
Launch and verify the Streamlit application
Start the Streamlit development server locally.
$ streamlit run app.py
This starts the Streamlit local server, exposing the dashboard UI on port 8501.
STEP 7
Verify user interface dashboard in web browser
Open your guest Linux web browser (e.g. Firefox) and navigate to the application URL.
Navigate browser to: http://localhost:8501
This loads the interactive dashboard, enabling you to test predictions and view AI recommendations.
3. Full-Stack Execution Flow
The flowchart below outlines the full-stack execution flow. It details the steps from user input submission on the dashboard to predictive modeling, LangChain advice parsing, and rendering updates in the UI.
4. Part 2: Complete Deliverable Assets & Production Templates
To run the application, we need the Streamlit Python script and the Dockerfile configuration. Below is a line-by-line explanation of the code, followed by the combined template files.
Step-by-Step Code Construction
Lines 1 - 7
Import UI and LLM frameworks
Include system packages, Streamlit dashboard metrics, and LangChain core interfaces in the script.
import streamlit as st
import numpy as np
from langchain_core.tools import tool
import re
These imports pull Streamlit dashboard metrics and LangChain core tools.
Lines 8 - 25
Define Custom RAG Advisor Tool
Define a function with the `@tool` decorator to retrieve tailored churn mitigation strategies based on risk levels.
@tool
def get_mitigation_advice(risk_level: str) -> str:
"""Retrieves retention strategies based on risk level."""
strategies = {
"High": "Offer 20% discount and call customer.",
"Low": "Send newsletter."
}
return strategies.get(risk_level, "No strategy found")
This sets up custom tools to query retention recommendations based on user risk categories.
Lines 26 - 45
Build Streamlit UI Dashboard
Configure input sliders and selection elements to submit values to the model.
st.title("Customer Churn Dashboard")
age = st.slider("Age", 18, 90, 30)
salary = st.number_input("Salary", 10000.0, 200000.0, 50000.0)
if st.button("Predict"):
# Score predictions and display advice
st.write("Prediction complete.")
This configures the Streamlit user interface layout, enabling users to adjust features and view predictions.
Production templates
1. Streamlit web application (Save as ~/Projects/final_capstone/app.py):
# app.py - Full-Stack Streamlit UI and LangChain RAG Advisorimport streamlit as st
import numpy as np
from langchain_core.tools import tool
# Set page config for premium look
st.set_page_config(page_title="Customer Churn Dashboard", page_icon="📊", layout="wide")
# Define LangChain Advice tool
@tool
defget_retention_recommendations(risk_level: str) -> str:
"""Retrieves customer retention recommendations based on risk level ('High' or 'Low')."""
strategies = {
"High": "Offer 20% loyalty discount, trigger proactive call from accounts, and set auto-renewal incentives.",
"Low": "Include in monthly newsletter list and send feature updates."
}
return strategies.get(risk_level, "Maintain standard communication.")
defmain():
st.title("📊 Client Retention & Customer Churn Advisor")
st.markdown("### Predictive Scoring and Generative AI Churn Mitigation Dashboard")
st.sidebar.header("Customer Features Input")
age = st.sidebar.slider("Customer Age", 18, 90, 35)
salary = st.sidebar.number_input("Annual Salary ($)", min_value=10000.0, max_value=250000.0, value=65000.0)
city = st.sidebar.selectbox("Region City", ["New York", "London", "Paris"])
col1, col2 = st.columns(2)
with col1:
st.subheader("Predictive Analytics Model")
# Calculate churn probability using a sigmoid model
z = -2.5 + (0.04 * age) + (0.000005 * salary) - (0.2 if city == "London" else 0.0)
prob = 1.0 / (1.0 + np.exp(-z))
st.metric(label="Calculated Churn Probability", value=f"{prob*100:.2f}%")
if prob > 0.5:
st.error("Status: High Churn Risk")
risk = "High"else:
st.success("Status: Low Churn Risk")
risk = "Low"
with col2:
st.subheader("Generative AI retention recommendation")
# Retrieve advice using the LangChain tool
advice = get_retention_recommendations.invoke(risk)
st.info(f"**Mitigation Steps:** {advice}")
st.markdown("---")
st.subheader("Responsible AI checks")
st.markdown("- **Transparency:** Logged prediction formula coefficients.")
st.markdown("- **Privacy:** Data inputs are processed in-memory and not stored.")
if __name__ == "__main__":
main()
2. Docker Configuration script (Save as ~/Projects/final_capstone/Dockerfile):