Anthony Truchet commited on
Commit ·
aa1a2e9
1
Parent(s): f578c56
misc: too many things mixed together
Browse files- .streamlit/config.toml +4 -1
- Dockerfile +10 -14
- packages.txt +3 -0
- scripts/build-run-local-docker.sh +7 -2
- src/app.py +14 -3
- {static → src/static}/cat.jpeg +0 -0
.streamlit/config.toml
CHANGED
|
@@ -10,4 +10,7 @@ maxUploadSize = 200
|
|
| 10 |
headless = true
|
| 11 |
address = "0.0.0.0"
|
| 12 |
port = 8501
|
| 13 |
-
enableStaticServing = true
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
headless = true
|
| 11 |
address = "0.0.0.0"
|
| 12 |
port = 8501
|
| 13 |
+
enableStaticServing = true
|
| 14 |
+
|
| 15 |
+
[browser]
|
| 16 |
+
gatherUsageStats = false
|
Dockerfile
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
FROM python:3.10.12
|
| 2 |
|
| 3 |
ARG APP_HOME=/home/user
|
|
@@ -12,24 +13,22 @@ COPY ./requirements.txt $APP_CODE/requirements.txt
|
|
| 12 |
COPY ./packages.txt $APP_CODE/packages.txt
|
| 13 |
|
| 14 |
RUN apt-get update && xargs -r -a $APP_CODE/packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/*
|
| 15 |
-
RUN pip3 install --upgrade pip
|
| 16 |
RUN pip3 install --no-cache-dir -r $APP_CODE/requirements.txt
|
| 17 |
|
| 18 |
# Creates an unpriviliedged user
|
| 19 |
RUN useradd -m -u 1000 user
|
|
|
|
| 20 |
# Copy our code to $APP_CODE taking car of the permissions
|
| 21 |
-
COPY --chown=
|
| 22 |
-
|
| 23 |
|
| 24 |
# Persistent disk space
|
| 25 |
# Assumes a mount is passed to the docker command, like:
|
| 26 |
# $ docker ... --mount type=volume,src=ai-playground-vol,dst=/data ...
|
| 27 |
#
|
| 28 |
# see https://huggingface.co/docs/hub/spaces-storage
|
| 29 |
-
RUN mkdir -p
|
| 30 |
-
ENV HF_HOME $HF_HOME
|
| 31 |
-
RUN mkdir -p $APP_DATA
|
| 32 |
-
RUN chown user:user /data/* && chmod ug+rwXs /data
|
| 33 |
|
| 34 |
# User
|
| 35 |
USER user
|
|
@@ -37,17 +36,14 @@ ENV APP_DATA $APP_DATA
|
|
| 37 |
ENV APP_CODE $APP_CODE
|
| 38 |
ENV HOME $APP_HOME
|
| 39 |
ENV PATH $HOME/.local/bin:$PATH
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
RUN mkdir -p $APP_HOME/.streamlit
|
| 43 |
-
COPY .streamlit $APP_HOME/.streamlit
|
| 44 |
-
COPY $HOST_STATIC_FILES/ $APP_CODE/static/
|
| 45 |
|
| 46 |
# Expose streamlit application
|
| 47 |
WORKDIR $APP_HOME
|
| 48 |
EXPOSE 8501
|
| 49 |
CMD streamlit run $APP_CODE/app.py \
|
| 50 |
-
--logger.level=
|
| 51 |
--server.enableXsrfProtection=true \
|
| 52 |
-
--server.fileWatcherType=
|
| 53 |
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
FROM python:3.10.12
|
| 3 |
|
| 4 |
ARG APP_HOME=/home/user
|
|
|
|
| 13 |
COPY ./packages.txt $APP_CODE/packages.txt
|
| 14 |
|
| 15 |
RUN apt-get update && xargs -r -a $APP_CODE/packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/*
|
| 16 |
+
RUN pip3 install --no-cache-dir --upgrade pip
|
| 17 |
RUN pip3 install --no-cache-dir -r $APP_CODE/requirements.txt
|
| 18 |
|
| 19 |
# Creates an unpriviliedged user
|
| 20 |
RUN useradd -m -u 1000 user
|
| 21 |
+
|
| 22 |
# Copy our code to $APP_CODE taking car of the permissions
|
| 23 |
+
COPY --chown=user:user --chmod=u=rX src/ $APP_CODE/
|
| 24 |
+
COPY --chown=user:user --chmod=u=rX .streamlit/ $APP_HOME/.streamlit/
|
| 25 |
|
| 26 |
# Persistent disk space
|
| 27 |
# Assumes a mount is passed to the docker command, like:
|
| 28 |
# $ docker ... --mount type=volume,src=ai-playground-vol,dst=/data ...
|
| 29 |
#
|
| 30 |
# see https://huggingface.co/docs/hub/spaces-storage
|
| 31 |
+
RUN mkdir -p /data && chown root:user /data && chmod ug+rwX /data
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# User
|
| 34 |
USER user
|
|
|
|
| 36 |
ENV APP_CODE $APP_CODE
|
| 37 |
ENV HOME $APP_HOME
|
| 38 |
ENV PATH $HOME/.local/bin:$PATH
|
| 39 |
+
ENV HF_HOME $HF_HOME
|
| 40 |
+
RUN mkdir -p $HF_HOME $APP_DATA
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Expose streamlit application
|
| 43 |
WORKDIR $APP_HOME
|
| 44 |
EXPOSE 8501
|
| 45 |
CMD streamlit run $APP_CODE/app.py \
|
| 46 |
+
--logger.level=debug \
|
| 47 |
--server.enableXsrfProtection=true \
|
| 48 |
+
--server.fileWatcherType=auto
|
| 49 |
|
packages.txt
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nano
|
| 2 |
+
vim
|
| 3 |
+
tree
|
scripts/build-run-local-docker.sh
CHANGED
|
@@ -15,9 +15,14 @@ poetry export -f requirements.txt -o requirements.txt --without-hashes --only=ma
|
|
| 15 |
# Re-build the docker image.
|
| 16 |
docker build --label tests -t $CONTAINER_NAME .
|
| 17 |
|
|
|
|
|
|
|
| 18 |
docker run -it \
|
| 19 |
-p 8501:8501 \
|
| 20 |
-
--mount type=volume,src=$VOLUME_NAME,dst=/data
|
| 21 |
-
$
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
popd
|
|
|
|
| 15 |
# Re-build the docker image.
|
| 16 |
docker build --label tests -t $CONTAINER_NAME .
|
| 17 |
|
| 18 |
+
# During development ONLY use a `bind mount` to enable
|
| 19 |
+
# editing the code without having to rebuild the container.
|
| 20 |
docker run -it \
|
| 21 |
-p 8501:8501 \
|
| 22 |
+
--mount type=volume,src=$VOLUME_NAME,dst=/data \
|
| 23 |
+
--mount type=bind,source=${ROOT_DIRECTORY}/src/,target=/app/,readonly \
|
| 24 |
+
--mount type=bind,source=${ROOT_DIRECTORY}/.streamlit,target=/user/.streamlit,readonly \
|
| 25 |
+
$CONTAINER_NAME:latest \
|
| 26 |
+
$@
|
| 27 |
|
| 28 |
popd
|
src/app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import numpy as np
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
st.title("Uber pickups in NYC")
|
|
@@ -11,11 +14,18 @@ DATA_URL = (
|
|
| 11 |
"streamlit-demo-data/uber-raw-data-sep14.csv.gz"
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@st.cache_resource
|
| 16 |
def load_data(nrows):
|
| 17 |
-
data =
|
| 18 |
-
|
| 19 |
def lowercase(x):
|
| 20 |
return str(x).lower()
|
| 21 |
|
|
@@ -51,4 +61,5 @@ if uploaded_file is not None:
|
|
| 51 |
bytes_data = uploaded_file.getvalue()
|
| 52 |
st.write(len(bytes_data), "bytes")
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
| 4 |
+
import shelve
|
| 5 |
+
import os
|
| 6 |
+
import pathlib
|
| 7 |
|
| 8 |
|
| 9 |
st.title("Uber pickups in NYC")
|
|
|
|
| 14 |
"streamlit-demo-data/uber-raw-data-sep14.csv.gz"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
DATA_PATH = pathlib.Path(os.environ.get("APP_DATA"))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def cached_download_csv(url : str, **kwargs) -> pd.DataFrame:
|
| 21 |
+
with shelve.open(DATA_PATH.joinpath("shelf.dat").as_posix(), writeback=True, flag='c') as shelf:
|
| 22 |
+
df = shelf.get(url, pd.read_csv(url, **kwargs))
|
| 23 |
+
return df
|
| 24 |
+
|
| 25 |
|
| 26 |
@st.cache_resource
|
| 27 |
def load_data(nrows):
|
| 28 |
+
data = cached_download_csv(DATA_URL, nrows=nrows)
|
|
|
|
| 29 |
def lowercase(x):
|
| 30 |
return str(x).lower()
|
| 31 |
|
|
|
|
| 61 |
bytes_data = uploaded_file.getvalue()
|
| 62 |
st.write(len(bytes_data), "bytes")
|
| 63 |
|
| 64 |
+
|
| 65 |
+
st.markdown("")
|
{static → src/static}/cat.jpeg
RENAMED
|
File without changes
|