24
24
import gradio
25
25
else :
26
26
gradio = ModuleType ("gradio" )
27
+ gradio .themes = ModuleType ("gradio.themes" )
28
+
29
+ class __DummyBase :
30
+ pass
31
+
32
+ gradio .themes .Base = __DummyBase
27
33
28
34
29
35
class ServeGradio (LightningWork , abc .ABC ):
@@ -49,11 +55,12 @@ class ServeGradio(LightningWork, abc.ABC):
49
55
50
56
_start_method = "spawn"
51
57
52
- def __init__ (self , * args : Any , ** kwargs : Any ):
58
+ def __init__ (self , * args : Any , theme : Optional [ gradio . themes . Base ] = None , ** kwargs : Any ):
53
59
requires ("gradio" )(super ().__init__ (* args , ** kwargs ))
54
60
assert self .inputs
55
61
assert self .outputs
56
62
self ._model = None
63
+ self ._theme = theme or ServeGradio .__get_lightning_gradio_theme ()
57
64
58
65
self .ready = False
59
66
@@ -85,6 +92,7 @@ def run(self, *args: Any, **kwargs: Any):
85
92
examples = self .examples ,
86
93
title = self .title ,
87
94
description = self .description ,
95
+ theme = self ._theme ,
88
96
).launch (
89
97
server_name = self .host ,
90
98
server_port = self .port ,
@@ -93,3 +101,98 @@ def run(self, *args: Any, **kwargs: Any):
93
101
94
102
def configure_layout (self ) -> str :
95
103
return self .url
104
+
105
+ @staticmethod
106
+ def __get_lightning_gradio_theme ():
107
+ return gradio .themes .Default (
108
+ primary_hue = gradio .themes .Color (
109
+ "#ffffff" ,
110
+ "#e9d5ff" ,
111
+ "#d8b4fe" ,
112
+ "#c084fc" ,
113
+ "#fcfcfc" ,
114
+ "#a855f7" ,
115
+ "#9333ea" ,
116
+ "#8823e1" ,
117
+ "#6b21a8" ,
118
+ "#2c2730" ,
119
+ "#1c1c1c" ,
120
+ ),
121
+ secondary_hue = gradio .themes .Color (
122
+ "#c3a1e8" ,
123
+ "#e9d5ff" ,
124
+ "#d3bbec" ,
125
+ "#c795f9" ,
126
+ "#9174af" ,
127
+ "#a855f7" ,
128
+ "#9333ea" ,
129
+ "#6700c2" ,
130
+ "#000000" ,
131
+ "#991ef1" ,
132
+ "#33243d" ,
133
+ ),
134
+ neutral_hue = gradio .themes .Color (
135
+ "#ede9fe" ,
136
+ "#ddd6fe" ,
137
+ "#c4b5fd" ,
138
+ "#a78bfa" ,
139
+ "#fafafa" ,
140
+ "#8b5cf6" ,
141
+ "#7c3aed" ,
142
+ "#6d28d9" ,
143
+ "#6130b0" ,
144
+ "#8a4ce6" ,
145
+ "#3b3348" ,
146
+ ),
147
+ ).set (
148
+ body_background_fill = "*primary_50" ,
149
+ body_background_fill_dark = "*primary_950" ,
150
+ body_text_color_dark = "*primary_100" ,
151
+ body_text_size = "*text_sm" ,
152
+ body_text_color_subdued_dark = "*primary_100" ,
153
+ background_fill_primary = "*primary_50" ,
154
+ background_fill_primary_dark = "*primary_950" ,
155
+ background_fill_secondary = "*primary_50" ,
156
+ background_fill_secondary_dark = "*primary_950" ,
157
+ border_color_accent = "*primary_400" ,
158
+ border_color_accent_dark = "*primary_900" ,
159
+ border_color_primary = "*primary_600" ,
160
+ border_color_primary_dark = "*primary_800" ,
161
+ color_accent = "*primary_400" ,
162
+ color_accent_soft = "*primary_300" ,
163
+ color_accent_soft_dark = "*primary_700" ,
164
+ link_text_color = "*primary_500" ,
165
+ link_text_color_dark = "*primary_50" ,
166
+ link_text_color_active = "*secondary_800" ,
167
+ link_text_color_active_dark = "*primary_500" ,
168
+ link_text_color_hover = "*primary_400" ,
169
+ link_text_color_hover_dark = "*primary_400" ,
170
+ link_text_color_visited = "*primary_500" ,
171
+ link_text_color_visited_dark = "*secondary_100" ,
172
+ block_background_fill = "*primary_50" ,
173
+ block_background_fill_dark = "*primary_900" ,
174
+ block_border_color_dark = "*primary_800" ,
175
+ checkbox_background_color = "*primary_50" ,
176
+ checkbox_background_color_dark = "*primary_50" ,
177
+ checkbox_background_color_focus = "*primary_100" ,
178
+ checkbox_background_color_focus_dark = "*primary_100" ,
179
+ checkbox_background_color_hover = "*primary_400" ,
180
+ checkbox_background_color_hover_dark = "*primary_500" ,
181
+ checkbox_background_color_selected = "*primary_300" ,
182
+ checkbox_background_color_selected_dark = "*primary_500" ,
183
+ checkbox_border_color_dark = "*primary_200" ,
184
+ checkbox_border_radius = "*radius_md" ,
185
+ input_background_fill = "*primary_50" ,
186
+ input_background_fill_dark = "*primary_900" ,
187
+ input_radius = "*radius_xxl" ,
188
+ slider_color = "*primary_600" ,
189
+ slider_color_dark = "*primary_700" ,
190
+ button_large_radius = "*radius_xxl" ,
191
+ button_large_text_size = "*text_md" ,
192
+ button_small_radius = "*radius_xxl" ,
193
+ button_primary_background_fill_dark = "*primary_800" ,
194
+ button_primary_background_fill_hover_dark = "*primary_700" ,
195
+ button_primary_border_color_dark = "*primary_800" ,
196
+ button_secondary_background_fill = "*neutral_200" ,
197
+ button_secondary_background_fill_dark = "*primary_600" ,
198
+ )
0 commit comments