Spaces:
Running
Running
James McCool
commited on
Commit
·
6c12e73
1
Parent(s):
74af059
Refactor Dockerfile to set MongoDB URI as an environment variable during runtime, enhancing security. Update Streamlit app to reduce cache duration and add display options for data presentation, improving user experience.
Browse files- Dockerfile +5 -5
- src/streamlit_app.py +13 -9
Dockerfile
CHANGED
@@ -14,13 +14,13 @@ COPY src/ ./src/
|
|
14 |
|
15 |
RUN pip3 install -r requirements.txt
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
git init && \
|
20 |
-
git remote add origin $(cat /run/secrets/mongo_uri)
|
21 |
|
22 |
EXPOSE 8501
|
23 |
|
24 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
25 |
|
26 |
-
|
|
|
|
|
|
14 |
|
15 |
RUN pip3 install -r requirements.txt
|
16 |
|
17 |
+
# Set the environment variable from the secret during runtime
|
18 |
+
ENV mongo_uri=""
|
|
|
|
|
19 |
|
20 |
EXPOSE 8501
|
21 |
|
22 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
23 |
|
24 |
+
# Use the secret as an environment variable during container runtime
|
25 |
+
ENTRYPOINT --mount=type=secret,id=mongo_uri,target=/run/secrets/mongo_uri,mode=0444,required=true \
|
26 |
+
sh -c 'export mongo_uri=$(cat /run/secrets/mongo_uri) && streamlit run src/streamlit_app.py --server.port=8501 --server.address=0.0.0.0'
|
src/streamlit_app.py
CHANGED
@@ -16,18 +16,22 @@ def init_conn():
|
|
16 |
|
17 |
db = init_conn()
|
18 |
|
19 |
-
@st.cache_resource(ttl =
|
20 |
def init_baselines():
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
return raw_frame
|
28 |
|
|
|
29 |
|
30 |
hr_frame = init_baselines()
|
31 |
st.title("HR Finder Table")
|
32 |
|
33 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
db = init_conn()
|
18 |
|
19 |
+
@st.cache_resource(ttl = 60)
|
20 |
def init_baselines():
|
21 |
+
collection = db["HR_Table"]
|
22 |
+
cursor = collection.find()
|
23 |
+
raw_display = pd.DataFrame(cursor)
|
24 |
+
raw_display.rename(columns={"Names": "Player"}, inplace = True)
|
25 |
+
raw_frame = raw_display.drop(columns=['_id']).drop_duplicates(subset='Player')
|
|
|
|
|
26 |
|
27 |
+
return raw_frame
|
28 |
|
29 |
hr_frame = init_baselines()
|
30 |
st.title("HR Finder Table")
|
31 |
|
32 |
+
disp_options = st.radio("Display options:" ['Exclude DFS Info', 'Include DFS Info'], key='display_options')
|
33 |
+
if disp_options == 'Exclude DFS Info':
|
34 |
+
disp_frame = hr_frame.drop(columns=['Salary', 'Position', 'FD_Position', 'Order'])
|
35 |
+
else:
|
36 |
+
disp_frame = hr_frame.copy()
|
37 |
+
st.dataframe(disp_frame, use_container_width = True, hide_index = True)
|