Skip to content

Commit b8cb754

Browse files
authored
Merge pull request #19 from stackhpc/feat/purge-google-fonts
Workaround Google fonts issue in Gradio for GDPR compliance
2 parents a739216 + 9ca5485 commit b8cb754

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

chart/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ ui:
8484
appSettings:
8585
hf_model_name: *model-name
8686
hf_model_instruction: "You are a helpful AI assistant. Please response appropriately."
87+
# Use local system fonts by default to avoid GDPR issues
88+
# with Gradio's defaults fonts which require fetching from
89+
# the Google fonts API. To restore default Gradio theme
90+
# fonts, remove the font and font-mono keys.
91+
theme_params:
92+
font:
93+
- sans-serif
94+
- Arial
95+
font_mono:
96+
- sans-serif
97+
- Arial
8798
# Container image config
8899
image:
89100
repository: ghcr.io/stackhpc/azimuth-llm-ui-base

chart/web-app/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pydantic import Field, HttpUrl
33
from pydantic_settings import BaseSettings, SettingsConfigDict
44

5-
from typing import Optional
5+
from typing import Optional, Union, List
66

77

88
def get_k8s_namespace():
@@ -52,7 +52,7 @@ class AppSettings(BaseSettings):
5252
# Variables explicitly passed to gradio.theme.Default()
5353
# For example:
5454
# {"primary_hue": "red"}
55-
theme_params: dict[str, str] = Field(default_factory=dict)
55+
theme_params: dict[str, Union[str, List[str]]] = Field(default_factory=dict)
5656
# Overrides for theme.body_background_fill property
5757
theme_background_colour: Optional[str] = Field(default=None)
5858
# Custom page title colour override passed as CSS

chart/web-app/example-settings.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
backend_url: http://128.232.226.230
2-
hf_model_name: tiiuae/falcon-7b
1+
backend_url: http://localhost:8081
2+
hf_model_name: ise-uiuc/Magicoder-S-DS-6.7B
33

4-
hf_model_instruction: You are a helpful and cheerful AI assistant. Please respond appropriately.
4+
# model_instruction: You are a helpful and cheerful AI assistant. Please respond appropriately.
5+
6+
page_description: "[Privacy statement](https://google.com)"
57

68
# UI theming tweaks
79
# theme_title_colour: white
810
# theme_background_colour: "#00376c"
9-
# theme_params:
10-
# primary_hue: blue
11+
theme_params:
12+
# primary_hue: blue
13+
font:
14+
- sans-serif
15+
font_mono:
16+
- sans-serif
1117

1218
# llm_max_tokens:
1319
# llm_temperature:

images/ui-base/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ FROM python:3.11-slim
33
ENV GRADIO_SERVER_PORT=7680
44

55
COPY requirements.txt requirements.txt
6-
RUN pip install --no-cache-dir -r requirements.txt
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY purge-google-fonts.sh purge-google-fonts.sh
9+
RUN bash purge-google-fonts.sh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
SOURCE_CODE_PATH=/usr/local/lib/python3.11/site-packages/gradio/
3+
4+
# Strip out preconnect directives from HTML <link> tags
5+
find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!'rel="preconnect"'!!g {} \;
6+
7+
# Replace hard-coded links in HTML templates with something harmless but identifiable
8+
declare -a LINKS=(
9+
"https://fonts.gstatic.com"
10+
"https://fonts.googleapis.com"
11+
"https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/.*/iframeResizer.contentWindow.min.js"
12+
)
13+
REPLACEMENT="external-url-removed-for-gdpr-compliance"
14+
for item in "${LINKS[@]}"; do
15+
find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!$item!$REPLACEMENT!g {} \;
16+
done

0 commit comments

Comments
 (0)