ffeew commited on
Commit
8967d6a
ยท
1 Parent(s): cd3f41e

Enhance Dockerfile and main.py: add non-root user, improve PII masking tool UI with label selection

Browse files
Files changed (2) hide show
  1. Dockerfile +15 -4
  2. main.py +20 -1
Dockerfile CHANGED
@@ -2,12 +2,23 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y redis-server && rm -rf /var/lib/apt/lists/*
6
-
7
- COPY requirements.txt /app
 
8
 
 
 
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
- COPY . /app
 
 
 
 
 
 
 
 
12
 
13
  CMD ["/bin/bash", "-c", "redis-server --daemonize yes && streamlit run main.py --server.port=7860 --server.address=0.0.0.0"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Install system packages as root
6
+ RUN apt-get update && \
7
+ apt-get install -y redis-server && \
8
+ rm -rf /var/lib/apt/lists/*
9
 
10
+ # Copy and install Python requirements
11
+ COPY requirements.txt /app/
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
14
+ # Copy application code
15
+ COPY . /app/
16
+
17
+ # Create non-root user and set permissions
18
+ RUN useradd -m -u 1000 user && \
19
+ chown -R user:user /app
20
+
21
+ # Switch to non-root user
22
+ USER user
23
 
24
  CMD ["/bin/bash", "-c", "redis-server --daemonize yes && streamlit run main.py --server.port=7860 --server.address=0.0.0.0"]
main.py CHANGED
@@ -1,16 +1,35 @@
1
  import math
2
  import streamlit as st
3
 
4
- from utils.model import pii_masking_pipeline
5
  from utils.redis import redis_client
6
 
7
  st.set_page_config(page_title="PII Masking Tool", page_icon="๐Ÿ”’")
8
 
9
  st.title("PII Masking Tool")
10
 
 
 
 
 
 
 
11
  # Text input
12
  text_to_mask = st.text_area("Enter text to mask PII:", height=200)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if st.button("Mask Text"):
15
  if text_to_mask:
16
  masked_text = pii_masking_pipeline(text_to_mask)
 
1
  import math
2
  import streamlit as st
3
 
4
+ from utils.model import pii_masking_pipeline, valid_labels
5
  from utils.redis import redis_client
6
 
7
  st.set_page_config(page_title="PII Masking Tool", page_icon="๐Ÿ”’")
8
 
9
  st.title("PII Masking Tool")
10
 
11
+ if 'selected_labels' not in st.session_state:
12
+ st.session_state.selected_labels = ["name", "nric", "phone number", "address", "email"]
13
+
14
+ def select_all_labels():
15
+ st.session_state.selected_labels = valid_labels
16
+
17
  # Text input
18
  text_to_mask = st.text_area("Enter text to mask PII:", height=200)
19
 
20
+ col1, col2 = st.columns([3, 1])
21
+ with col1:
22
+ selected_labels = st.multiselect(
23
+ "Select PII types to mask:",
24
+ options=valid_labels,
25
+ key='selected_labels',
26
+ help="Choose the types of PII you want to redact from the text"
27
+ )
28
+
29
+ with col2:
30
+ st.button("Select All", on_click=select_all_labels)
31
+
32
+
33
  if st.button("Mask Text"):
34
  if text_to_mask:
35
  masked_text = pii_masking_pipeline(text_to_mask)