Last active
May 30, 2023 17:18
-
-
Save treuille/ac7755eb37c63a78fac7dfef89f3517e to your computer and use it in GitHub Desktop.
This demonstrates how piping cached functions into one another automatically sets up an efficient directed acyclic computational graph.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import pandas as pd | |
@st.cache | |
def load_metadata(): | |
DATA_URL = "https://streamlit-self-driving.s3-us-west-2.amazonaws.com/labels.csv.gz" | |
return pd.read_csv(DATA_URL, nrows=1000) | |
@st.cache | |
def create_summary(metadata, summary_type): | |
one_hot_encoded = pd.get_dummies(metadata[["frame", "label"]], columns=["label"]) | |
return getattr(one_hot_encoded.groupby(["frame"]), summary_type)() | |
# Piping one st.cache function into another forms a computation DAG. | |
summary_type = st.selectbox("Type of summary:", ["sum", "any"]) | |
metadata = load_metadata() | |
summary = create_summary(metadata, summary_type) | |
st.write('## Metadata', metadata, '## Summary', summary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can run this gist directly from the command line with: