Skip to content

Commit

Permalink
Merge pull request #19 from stackhpc/feat/purge-google-fonts
Browse files Browse the repository at this point in the history
Workaround Google fonts issue in Gradio for GDPR compliance
  • Loading branch information
sd109 authored May 1, 2024
2 parents a739216 + 9ca5485 commit b8cb754
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
11 changes: 11 additions & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions chart/web-app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions chart/web-app/example-settings.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 4 additions & 1 deletion images/ui-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
RUN pip install --no-cache-dir -r requirements.txt

COPY purge-google-fonts.sh purge-google-fonts.sh
RUN bash purge-google-fonts.sh
16 changes: 16 additions & 0 deletions images/ui-base/purge-google-fonts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

SOURCE_CODE_PATH=/usr/local/lib/python3.11/site-packages/gradio/

# Strip out preconnect directives from HTML <link> tags
find $SOURCE_CODE_PATH -name "*.html" -type f -exec sed -i s!'rel="preconnect"'!!g {} \;

# 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="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

0 comments on commit b8cb754

Please sign in to comment.