ADALAB EXTENSION
CONFIGURATION
Port
8501
Base Image
python:3.14-slim
Entry Point
app.py
Resources
2 vCPU
4 GB
DATA SOURCE
postgres:18● Connected
app.py×
| 1 | import streamlit as st |
| 2 | import pandas as pd |
| 3 | import numpy as np |
| 4 | from db_config import get_connection |
| 5 | |
| 6 | # Page config |
| 7 | st.set_page_config(page_title="Customer Churn Predictor", layout="wide") |
| 8 | |
| 9 | # Database connections |
| 10 | @st.cache_resource |
| 11 | def load_data(): |
| 12 | conn = get_connection("aws_rds") |
| 13 | query = """ |
| 14 | SELECT t.*, r.risk_score, r.category |
| 15 | FROM transactions t |
| 16 | JOIN risk_scores r ON t.id = r.transaction_id |
| 17 | WHERE t.date >= :start_date |
| 18 | """ |
| 19 | return pd.read_sql(query, conn) |
| 20 | |
| 21 | # Sidebar filters |
| 22 | st.sidebar.title("Customer Churn Predictor") |
| 23 | start_date = st.sidebar.date_input("Start Date") |
| 24 | end_date = st.sidebar.date_input("End Date") |
| 25 | threshold = st.sidebar.slider("Risk Threshold", 0.0, 1.0, 0.75) |
| 26 | |
| 27 | # Load and filter data |
| 28 | df = load_data() |
| 29 | flagged = df[df["risk_score"] >= threshold] |
| 30 | |
| 31 | # Metrics row |
| 32 | col1, col2, col3 = st.columns(3) |
| 33 | col1.metric("Total Transactions", f"{len(df):,}", "12.3%") |
| 34 | col2.metric("Flagged", f"{len(flagged):,}", "-5.2%") |
| 35 | col3.metric("Accuracy", "96.8%", "0.3%") |
| 36 | |
| 37 | # Chart |
| 38 | st.subheader("Flagged by Category") |
| 39 | st.bar_chart(flagged["category"].value_counts()) |
| 40 | |
| 41 | # Table |
| 42 | st.subheader("Recent Flagged Transactions") |
| 43 | st.dataframe(flagged.head(20)) |
| 44 | |
| 45 | # Export |
| 46 | st.download_button("Export CSV", flagged.to_csv(), "flagged_transactions.csv") |
| 47 |
TERMINALPROBLEMSOUTPUT
$ streamlit run app.py
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501
Network URL: http://192.168.1.42:8501
Connected to AWS RDS (us-east-1)
Loading transaction data... 1,247,893 rows
Risk scoring model loaded (v2.4.1)
Ready.
⎇ main⚠ 0⊗ 0
app.pyPythonUTF-8Ln 47, Col 1
