From 7d0548f4a7e9e516ada4278193230401079209d3 Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 08:12:38 +0100 Subject: [PATCH 1/6] Implement GDPR compliance workaround --- images/ui-base/Dockerfile | 5 ++++- images/ui-base/purge-google-fonts.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 images/ui-base/purge-google-fonts.sh diff --git a/images/ui-base/Dockerfile b/images/ui-base/Dockerfile index 689301c..222de27 100644 --- a/images/ui-base/Dockerfile +++ b/images/ui-base/Dockerfile @@ -3,4 +3,7 @@ FROM python:3.11-slim ENV GRADIO_SERVER_PORT=7680 COPY requirements.txt requirements.txt -RUN pip install --no-cache-dir -r requirements.txt \ No newline at end of file +RUN pip install --no-cache-dir -r requirements.txt + +COPY purge-google-fonts.sh purge-google-fonts.sh +RUN bash purge-google-fonts.sh diff --git a/images/ui-base/purge-google-fonts.sh b/images/ui-base/purge-google-fonts.sh new file mode 100644 index 0000000..2e759f1 --- /dev/null +++ b/images/ui-base/purge-google-fonts.sh @@ -0,0 +1,12 @@ + +SOURCE_CODE_PATH=/usr/local/lib/python3.11/site-packages/gradio/ + +# Strip out preconnect directives from HTML tags +find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!'rel="preconnect"'!!g {} \; + +# Replace links with something harmless but identifiable +declare -a LINKS=("https://fonts.gstatic.com" "https://fonts.googleapis.com") +REPLACEMENT="no-google-fonts-here" +for item in "${LINKS[@]}"; do + find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!$item!$REPLACEMENT!g {} \; +done From 41d934f5ab833574967b2a236142a283b5f84bf3 Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 08:38:08 +0100 Subject: [PATCH 2/6] Pure additional CDN links --- images/ui-base/purge-google-fonts.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/images/ui-base/purge-google-fonts.sh b/images/ui-base/purge-google-fonts.sh index 2e759f1..4ceb65f 100644 --- a/images/ui-base/purge-google-fonts.sh +++ b/images/ui-base/purge-google-fonts.sh @@ -4,9 +4,13 @@ SOURCE_CODE_PATH=/usr/local/lib/python3.11/site-packages/gradio/ # Strip out preconnect directives from HTML tags find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!'rel="preconnect"'!!g {} \; -# Replace links with something harmless but identifiable -declare -a LINKS=("https://fonts.gstatic.com" "https://fonts.googleapis.com") -REPLACEMENT="no-google-fonts-here" +# Replace hard-coded links in HTML templates with something harmless but identifiable +declare -a LINKS=( + "https://fonts.gstatic.com" + "https://fonts.googleapis.com" + "https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/.*/iframeResizer.contentWindow.min.js" +) +REPLACEMENT="no-GDPR-violations-here" for item in "${LINKS[@]}"; do find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!$item!$REPLACEMENT!g {} \; done From 58891e358dda17e063d8b57c7924d2065d9bc978 Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 08:57:24 +0100 Subject: [PATCH 3/6] Make replacement URL clearer --- images/ui-base/purge-google-fonts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/ui-base/purge-google-fonts.sh b/images/ui-base/purge-google-fonts.sh index 4ceb65f..bc6cc96 100644 --- a/images/ui-base/purge-google-fonts.sh +++ b/images/ui-base/purge-google-fonts.sh @@ -10,7 +10,7 @@ declare -a LINKS=( "https://fonts.googleapis.com" "https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/.*/iframeResizer.contentWindow.min.js" ) -REPLACEMENT="no-GDPR-violations-here" +REPLACEMENT="external-url-removed-for-gdpr-compliance" for item in "${LINKS[@]}"; do find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!$item!$REPLACEMENT!g {} \; done From 3cb801283c88a4b427ac0a51acff6c19ab172944 Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 08:59:48 +0100 Subject: [PATCH 4/6] Default to local system fonts --- chart/values.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/chart/values.yaml b/chart/values.yaml index b52a461..248cadb 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -84,6 +84,17 @@ ui: appSettings: hf_model_name: *model-name hf_model_instruction: "You are a helpful AI assistant. Please response appropriately." + # Use local system fonts by default to avoid GDPR issues + # with Gradio's defaults fonts which require fetching from + # the Google fonts API. To restore default Gradio theme + # fonts, remove the font and font-mono keys. + theme_params: + font: + - sans-serif + - Arial + font_mono: + - sans-serif + - Arial # Container image config image: repository: ghcr.io/stackhpc/azimuth-llm-ui-base From 8453f09336b77990be368a8e09de3f1973b2981e Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 08:59:53 +0100 Subject: [PATCH 5/6] Allow lists in theme params --- chart/web-app/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chart/web-app/config.py b/chart/web-app/config.py index 6f7efe4..9e45ae5 100644 --- a/chart/web-app/config.py +++ b/chart/web-app/config.py @@ -2,7 +2,7 @@ from pydantic import Field, HttpUrl from pydantic_settings import BaseSettings, SettingsConfigDict -from typing import Optional +from typing import Optional, Union, List def get_k8s_namespace(): @@ -52,7 +52,7 @@ class AppSettings(BaseSettings): # Variables explicitly passed to gradio.theme.Default() # For example: # {"primary_hue": "red"} - theme_params: dict[str, str] = Field(default_factory=dict) + theme_params: dict[str, Union[str, List[str]]] = Field(default_factory=dict) # Overrides for theme.body_background_fill property theme_background_colour: Optional[str] = Field(default=None) # Custom page title colour override passed as CSS From 9ca548583a39b21dbd70a234d7f0f187c099b596 Mon Sep 17 00:00:00 2001 From: sd109 Date: Wed, 1 May 2024 09:42:08 +0100 Subject: [PATCH 6/6] Update example settings --- chart/web-app/example-settings.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/chart/web-app/example-settings.yml b/chart/web-app/example-settings.yml index 463cf66..2d9a6b7 100644 --- a/chart/web-app/example-settings.yml +++ b/chart/web-app/example-settings.yml @@ -1,13 +1,19 @@ -backend_url: http://128.232.226.230 -hf_model_name: tiiuae/falcon-7b +backend_url: http://localhost:8081 +hf_model_name: ise-uiuc/Magicoder-S-DS-6.7B -hf_model_instruction: You are a helpful and cheerful AI assistant. Please respond appropriately. +# model_instruction: You are a helpful and cheerful AI assistant. Please respond appropriately. + +page_description: "[Privacy statement](https://google.com)" # UI theming tweaks # theme_title_colour: white # theme_background_colour: "#00376c" -# theme_params: -# primary_hue: blue +theme_params: + # primary_hue: blue + font: + - sans-serif + font_mono: + - sans-serif # llm_max_tokens: # llm_temperature: