davanstrien HF staff commited on
Commit
a328dd2
1 Parent(s): 3a74761

feat: Add TufteInspired theme for Gradio UI

Browse files

The TufteInspired theme is added to the Gradio UI for a visually appealing and consistent user experience. This theme provides a clean and elegant design with custom font styles and color schemes. The theme file `theme.py` is created to define the TufteInspired class, which extends the Base theme class and sets various styling properties.

Commit message generated by assistant.

Files changed (2) hide show
  1. app.py +17 -57
  2. theme.py +56 -0
app.py CHANGED
@@ -1,68 +1,28 @@
1
- import gradio as gr
2
- from gradio.themes.base import Base
3
- from gradio.themes.utils import colors, fonts, sizes
4
-
5
- class TufteInspired(Base):
6
- def __init__(
7
- self,
8
- *,
9
- primary_hue: colors.Color | str = colors.stone,
10
- secondary_hue: colors.Color | str = colors.gray,
11
- neutral_hue: colors.Color | str = colors.gray,
12
- spacing_size: sizes.Size | str = sizes.spacing_md,
13
- radius_size: sizes.Size | str = sizes.radius_sm,
14
- text_size: sizes.Size | str = sizes.text_lg,
15
- font: list[fonts.Font | str] = [
16
- fonts.GoogleFont("EB Garamond"),
17
- "Georgia",
18
- "serif"
19
- ],
20
- font_mono: list[fonts.Font | str] = [
21
- fonts.GoogleFont("IBM Plex Mono"),
22
- "Consolas",
23
- "monospace"
24
- ],
25
- ):
26
- super().__init__(
27
- primary_hue=primary_hue,
28
- secondary_hue=secondary_hue,
29
- neutral_hue=neutral_hue,
30
- spacing_size=spacing_size,
31
- radius_size=radius_size,
32
- text_size=text_size,
33
- font=font,
34
- font_mono=font_mono,
35
- )
36
- self.set(
37
- body_background_fill="#fffff8",
38
- body_background_fill_dark="#151515",
39
- body_text_color="*neutral_950",
40
- body_text_color_dark="*neutral_50",
41
- background_fill_primary="#fffff8",
42
- background_fill_primary_dark="#151515",
43
- block_title_text_weight="400",
44
- block_border_width="0px",
45
- block_shadow="none",
46
- button_primary_background_fill="*primary_100",
47
- button_primary_background_fill_hover="*primary_200",
48
- button_primary_text_color="*neutral_950",
49
- button_primary_border_color="*primary_300",
50
- button_shadow="none",
51
- input_background_fill="*secondary_50",
52
- input_background_fill_dark="*secondary_900",
53
- input_border_color="*secondary_200",
54
- input_border_color_dark="*secondary_700",
55
- input_shadow="none",
56
- )
57
 
58
  import gradio as gr
59
  import json
60
  from datetime import datetime
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  # Placeholder LLM function
63
  def generate_blurb():
64
  # This is where you'd call your LLM model
65
- return "A thrilling journey through time and space, where heroes rise and fall, and the fate of the universe hangs in the balance."
66
 
67
  # Function to log blurb and vote
68
  def log_blurb_and_vote(blurb, vote):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import gradio as gr
3
  import json
4
  from datetime import datetime
5
+ from theme import TufteInspired
6
+
7
+ from transformers import pipeline
8
+
9
+ # Load the model
10
+ model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
11
+ tokenizer = AutoTokenizer.from_pretrained(model_id, add_special_tokens=True)
12
+
13
+ pipeline = transformers.pipeline(
14
+ "text-generation",
15
+ model=model_id,
16
+ model_kwargs={"torch_dtype": torch.bfloat16},
17
+ device="cuda",
18
+ )
19
+
20
+
21
 
22
  # Placeholder LLM function
23
  def generate_blurb():
24
  # This is where you'd call your LLM model
25
+ return pipeline("Write a blurb for a made-up book")[0]["generated_text"]
26
 
27
  # Function to log blurb and vote
28
  def log_blurb_and_vote(blurb, vote):
theme.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio.themes.base import Base
3
+ from gradio.themes.utils import colors, fonts, sizes
4
+
5
+ class TufteInspired(Base):
6
+ def __init__(
7
+ self,
8
+ *,
9
+ primary_hue: colors.Color | str = colors.stone,
10
+ secondary_hue: colors.Color | str = colors.gray,
11
+ neutral_hue: colors.Color | str = colors.gray,
12
+ spacing_size: sizes.Size | str = sizes.spacing_md,
13
+ radius_size: sizes.Size | str = sizes.radius_sm,
14
+ text_size: sizes.Size | str = sizes.text_lg,
15
+ font: list[fonts.Font | str] = [
16
+ fonts.GoogleFont("EB Garamond"),
17
+ "Georgia",
18
+ "serif"
19
+ ],
20
+ font_mono: list[fonts.Font | str] = [
21
+ fonts.GoogleFont("IBM Plex Mono"),
22
+ "Consolas",
23
+ "monospace"
24
+ ],
25
+ ):
26
+ super().__init__(
27
+ primary_hue=primary_hue,
28
+ secondary_hue=secondary_hue,
29
+ neutral_hue=neutral_hue,
30
+ spacing_size=spacing_size,
31
+ radius_size=radius_size,
32
+ text_size=text_size,
33
+ font=font,
34
+ font_mono=font_mono,
35
+ )
36
+ self.set(
37
+ body_background_fill="#fffff8",
38
+ body_background_fill_dark="#151515",
39
+ body_text_color="*neutral_950",
40
+ body_text_color_dark="*neutral_50",
41
+ background_fill_primary="#fffff8",
42
+ background_fill_primary_dark="#151515",
43
+ block_title_text_weight="400",
44
+ block_border_width="0px",
45
+ block_shadow="none",
46
+ button_primary_background_fill="*primary_100",
47
+ button_primary_background_fill_hover="*primary_200",
48
+ button_primary_text_color="*neutral_950",
49
+ button_primary_border_color="*primary_300",
50
+ button_shadow="none",
51
+ input_background_fill="*secondary_50",
52
+ input_background_fill_dark="*secondary_900",
53
+ input_border_color="*secondary_200",
54
+ input_border_color_dark="*secondary_700",
55
+ input_shadow="none",
56
+ )