Skip to content

Commit 1f6c60a

Browse files
authored
Merge pull request #21 from stackhpc/feat/custom-css-and-js
Allow additional UI customisation via chart values
2 parents b8cb754 + d2630aa commit 1f6c60a

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

chart/web-app/app.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,6 @@ def inference(latest_message, history):
127127
if settings.theme_background_colour:
128128
theme.body_background_fill = settings.theme_background_colour
129129

130-
css_overrides = ""
131-
if settings.theme_title_colour:
132-
css_overrides += """
133-
h1 {{
134-
color: {0};
135-
padding-top: 0.5em;
136-
}}
137-
""".format(
138-
settings.theme_title_colour
139-
)
140-
141130

142131
def inference_wrapper(*args):
143132
"""
@@ -171,12 +160,14 @@ def inference_wrapper(*args):
171160
scale=7,
172161
),
173162
title=settings.page_title,
163+
description=settings.page_description,
174164
retry_btn="Retry",
175165
undo_btn="Undo",
176166
clear_btn="Clear",
177167
analytics_enabled=False,
178168
theme=theme,
179-
css=css_overrides,
169+
css=settings.css_overrides,
170+
js=settings.custom_javascript,
180171
) as app:
181172
logger.debug("Gradio chat interface config: %s", app.config)
182173
# For running locally in tilt dev setup

chart/web-app/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AppSettings(BaseSettings):
3333
default_factory=lambda: f"http://llm-backend.{get_k8s_namespace()}.svc"
3434
)
3535
page_title: str = Field(default="Large Language Model")
36+
page_description: Optional[str] = Field(default=None)
3637
hf_model_instruction: str = Field(
3738
default="You are a helpful and cheerful AI assistant. Please respond appropriately."
3839
)
@@ -55,8 +56,10 @@ class AppSettings(BaseSettings):
5556
theme_params: dict[str, Union[str, List[str]]] = Field(default_factory=dict)
5657
# Overrides for theme.body_background_fill property
5758
theme_background_colour: Optional[str] = Field(default=None)
58-
# Custom page title colour override passed as CSS
59-
theme_title_colour: Optional[str] = Field(default=None)
59+
# Provides arbitrary CSS and JS overrides to the UI,
60+
# see https://www.gradio.app/guides/custom-CSS-and-JS
61+
css_overrides: Optional[str] = Field(default=None)
62+
custom_javascript: Optional[str] = Field(default=None)
6063

6164
# Method for loading settings file
6265
@staticmethod

chart/web-app/example-settings.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,39 @@ backend_url: http://localhost:8081
22
hf_model_name: ise-uiuc/Magicoder-S-DS-6.7B
33

44
# model_instruction: You are a helpful and cheerful AI assistant. Please respond appropriately.
5+
# llm_max_tokens:
6+
# llm_temperature:
7+
# llm_top_p:
8+
# llm_frequency_penalty:
9+
# llm_presence_penalty:
510

6-
page_description: "[Privacy statement](https://google.com)"
11+
page_description: "[Custom Markdown](https://google.com)"
712

813
# UI theming tweaks
9-
# theme_title_colour: white
10-
# theme_background_colour: "#00376c"
14+
theme_background_colour: "#00376c"
1115
theme_params:
1216
# primary_hue: blue
17+
# Use local system fonts rather than Google fonts API
1318
font:
1419
- sans-serif
1520
font_mono:
1621
- sans-serif
1722

18-
# llm_max_tokens:
19-
# llm_temperature:
20-
# llm_top_p:
21-
# llm_frequency_penalty:
22-
# llm_presence_penalty:
23+
# Customise page title colour
24+
css_overrides: |
25+
h1 {
26+
color: white;
27+
padding-top: 1em;
28+
}
29+
30+
# Example of a custom JS function which adds a
31+
# privacy statement link to the page footer
32+
custom_javascript: |
33+
function addPrivacyStatement() {
34+
var footer = document.querySelector('footer');
35+
footer.appendChild(footer.children[1].cloneNode(deep=true));
36+
var item = footer.children[2].cloneNode();
37+
item.href = 'https://gdpr.eu/eu-gdpr-personal-data/';
38+
item.textContent = 'Privacy Statement';
39+
footer.appendChild(item);
40+
}

0 commit comments

Comments
 (0)