Skip to content

Commit 7144f40

Browse files
author
sd109
committed
Allow customising UI JS and CSS via app settings
1 parent b8cb754 commit 7144f40

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ 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.
55

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

88
# UI theming tweaks
9-
# theme_title_colour: white
10-
# theme_background_colour: "#00376c"
9+
theme_background_colour: "#00376c"
1110
theme_params:
1211
# primary_hue: blue
1312
font:
1413
- sans-serif
1514
font_mono:
1615
- sans-serif
1716

17+
css_overrides: |
18+
h1 {
19+
color: white;
20+
padding-top: 1em;
21+
}
22+
1823
# llm_max_tokens:
1924
# llm_temperature:
2025
# llm_top_p:

0 commit comments

Comments
 (0)