BryanBradfo commited on
Commit
c133cf6
·
1 Parent(s): 3385dfa

change the style

Browse files
Files changed (2) hide show
  1. app.py +138 -221
  2. style.css +3 -107
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  from collections.abc import Iterator
3
  from threading import Thread
4
 
@@ -7,148 +7,11 @@ import spaces
7
  import torch
8
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
9
 
10
- # Gemini-style colors
11
- GEMINI_COLORS = {
12
- "light_blue": "#8ab4f8",
13
- "blue": "#4285f4",
14
- "dark_blue": "#1a73e8",
15
- "marine_blue": "#174ea6",
16
- "white": "#ffffff",
17
- "light_gray": "#f8f9fa"
18
- }
19
-
20
- # Custom CSS for Gemini styling
21
- GEMINI_CSS = """
22
- /* Main styling for Gemini theme */
23
- body {
24
- background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
25
- font-family: 'Google Sans', Arial, sans-serif;
26
- }
27
-
28
- /* Header and title styling */
29
- h1 {
30
- text-align: center;
31
- display: block;
32
- color: #174ea6;
33
- font-weight: 600;
34
- margin-bottom: 1.5rem;
35
- }
36
-
37
- /* Chat interface styling */
38
- .gradio-container {
39
- max-width: 1200px !important;
40
- margin-left: auto !important;
41
- margin-right: auto !important;
42
- }
43
-
44
- /* Message bubbles */
45
- .message-wrap .message.user-message {
46
- background-color: #f8f9fa;
47
- border: 1px solid #e0e0e0;
48
- color: #202124;
49
- }
50
-
51
- .message-wrap .message.bot-message {
52
- background: linear-gradient(135deg, #8ab4f8 0%, #4285f4 100%);
53
- color: #ffffff;
54
- }
55
-
56
- /* Button styling */
57
- button.primary, .button.primary {
58
- background: linear-gradient(135deg, #4285f4 0%, #174ea6 100%) !important;
59
- color: #ffffff !important;
60
- border-radius: 100vh !important;
61
- border: none !important;
62
- transition: all 0.3s ease !important;
63
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
64
- }
65
-
66
- button.primary:hover, .button.primary:hover {
67
- background: #174ea6 !important;
68
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
69
- transform: translateY(-1px) !important;
70
- }
71
-
72
- /* Slider styling */
73
- .gradio-slider input[type="range"]::-webkit-slider-thumb {
74
- background: #4285f4 !important;
75
- }
76
-
77
- .gradio-slider input[type="range"] {
78
- background: linear-gradient(90deg, #4285f4 0%, #8ab4f8 100%) !important;
79
- }
80
-
81
- /* Chat input area */
82
- .chat-input {
83
- border-color: #8ab4f8 !important;
84
- box-shadow: 0 0 4px rgba(138, 180, 248, 0.3) !important;
85
- border-radius: 100vh !important;
86
- }
87
-
88
- .chat-input:focus {
89
- border-color: #4285f4 !important;
90
- box-shadow: 0 0 6px rgba(66, 133, 244, 0.5) !important;
91
- }
92
-
93
- /* Examples section */
94
- .examples-panel {
95
- background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
96
- border: 1px solid rgba(138, 180, 248, 0.3);
97
- border-radius: 8px;
98
- }
99
-
100
- .examples button {
101
- background-color: #f8f9fa !important;
102
- border: 1px solid #8ab4f8 !important;
103
- color: #174ea6 !important;
104
- margin: 5px !important;
105
- }
106
-
107
- .examples button:hover {
108
- background-color: #8ab4f8 !important;
109
- color: #ffffff !important;
110
- }
111
-
112
- /* Code blocks styling */
113
- .chatbot pre {
114
- background-color: #f8f9fa !important;
115
- border-left: 4px solid #4285f4 !important;
116
- }
117
-
118
- /* Additional styling for the description block */
119
- .prose {
120
- color: #174ea6;
121
- }
122
-
123
- .prose a {
124
- color: #4285f4;
125
- text-decoration: none;
126
- }
127
-
128
- .prose a:hover {
129
- text-decoration: underline;
130
- }
131
-
132
- /* Header banner with Gemini style */
133
- .gemini-header {
134
- background: linear-gradient(90deg, #4285f4, #174ea6);
135
- color: white;
136
- padding: 15px;
137
- border-radius: 10px;
138
- margin-bottom: 20px;
139
- text-align: center;
140
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
141
- }
142
- """
143
-
144
  DESCRIPTION = """\
145
- <div class="gemini-header">
146
- <h1>Gemini-Style Gemma 2 2B IT</h1>
147
- <p>Welcome to our Gemini-themed interface for Google's latest iteration of open LLMs.</p>
148
- </div>
149
 
150
  This is a demo of [`google/gemma-2-2b-it`](https://huggingface.co/google/gemma-2-2b-it), fine-tuned for instruction following.
151
- For more details, please check [our post](https://huggingface.co/blog/gemma2).
152
 
153
  👉 Looking for a larger and more powerful version? Try the 27B version in [HuggingChat](https://huggingface.co/chat/models/google/gemma-2-27b-it) and the 9B version in [this Space](https://huggingface.co/spaces/huggingface-projects/gemma-2-9b-it).
154
  """
@@ -210,87 +73,141 @@ def generate(
210
  yield "".join(outputs)
211
 
212
 
213
- # Create a custom theme with Gemini-inspired colors
214
- gemini_theme = gr.themes.Base(
215
- primary_hue="blue",
216
- secondary_hue="blue",
217
- neutral_hue="gray",
218
- text_size=gr.themes.sizes.text_md,
219
- ).set(
220
- body_background_fill=GEMINI_COLORS["white"],
221
- body_background_fill_dark=GEMINI_COLORS["white"],
222
-
223
- button_primary_background_fill=GEMINI_COLORS["blue"],
224
- button_primary_background_fill_hover=GEMINI_COLORS["dark_blue"],
225
- button_primary_background_fill_dark=GEMINI_COLORS["blue"],
226
- button_primary_text_color=GEMINI_COLORS["white"],
227
- button_primary_text_color_dark=GEMINI_COLORS["white"],
228
-
229
- button_secondary_background_fill=GEMINI_COLORS["light_gray"],
230
- button_secondary_background_fill_hover=GEMINI_COLORS["light_blue"],
231
- button_secondary_text_color=GEMINI_COLORS["dark_blue"],
232
-
233
- block_title_text_color=GEMINI_COLORS["marine_blue"],
234
- block_label_text_color=GEMINI_COLORS["dark_blue"],
235
-
236
- slider_color=GEMINI_COLORS["blue"],
237
- slider_color_dark=GEMINI_COLORS["blue"],
238
- )
239
 
240
- with gr.Blocks(theme=gemini_theme, css=GEMINI_CSS) as demo:
241
- gr.HTML(DESCRIPTION)
242
-
243
- chatbot = gr.ChatInterface(
244
- fn=generate,
245
- additional_inputs=[
246
- gr.Slider(
247
- label="Max new tokens",
248
- minimum=1,
249
- maximum=MAX_MAX_NEW_TOKENS,
250
- step=1,
251
- value=DEFAULT_MAX_NEW_TOKENS,
252
- ),
253
- gr.Slider(
254
- label="Temperature",
255
- minimum=0.1,
256
- maximum=4.0,
257
- step=0.1,
258
- value=0.6,
259
- ),
260
- gr.Slider(
261
- label="Top-p (nucleus sampling)",
262
- minimum=0.05,
263
- maximum=1.0,
264
- step=0.05,
265
- value=0.9,
266
- ),
267
- gr.Slider(
268
- label="Top-k",
269
- minimum=1,
270
- maximum=1000,
271
- step=1,
272
- value=50,
273
- ),
274
- gr.Slider(
275
- label="Repetition penalty",
276
- minimum=1.0,
277
- maximum=2.0,
278
- step=0.05,
279
- value=1.2,
280
- ),
281
- ],
282
- stop_btn=None,
283
- examples=[
284
- ["Hello there! How are you doing?"],
285
- ["Can you explain briefly to me what is the Python programming language?"],
286
- ["Explain the plot of Cinderella in a sentence."],
287
- ["How many hours does it take a man to eat a Helicopter?"],
288
- ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
289
- ],
290
- cache_examples=False,
291
- type="messages",
292
- fill_height=True,
293
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
  if __name__ == "__main__":
296
- demo.queue(max_size=20).launch()
 
1
+ import os
2
  from collections.abc import Iterator
3
  from threading import Thread
4
 
 
7
  import torch
8
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  DESCRIPTION = """\
11
+ # Hi, I'm Gemma 2 (2B) 👋
 
 
 
12
 
13
  This is a demo of [`google/gemma-2-2b-it`](https://huggingface.co/google/gemma-2-2b-it), fine-tuned for instruction following.
14
+ For more details, please check [the post](https://huggingface.co/blog/gemma2).
15
 
16
  👉 Looking for a larger and more powerful version? Try the 27B version in [HuggingChat](https://huggingface.co/chat/models/google/gemma-2-27b-it) and the 9B version in [this Space](https://huggingface.co/spaces/huggingface-projects/gemma-2-9b-it).
17
  """
 
73
  yield "".join(outputs)
74
 
75
 
76
+ # Embed our custom Gemini-like CSS here:
77
+ gemini_css = """
78
+ :root {
79
+ /* Adjust these if you want different start/end colors. */
80
+ --gradient-start: #0077BE; /* Marine/clear blue */
81
+ --gradient-end: #FFFFFF; /* White */
82
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ /* Overall page and container background gradient */
85
+ html, body, .gradio-container {
86
+ margin: 0;
87
+ padding: 0;
88
+ background: linear-gradient(to bottom, var(--gradient-start), var(--gradient-end));
89
+ font-family: "Helvetica", sans-serif;
90
+ color: #003366; /* A darker blue for text */
91
+ }
92
+
93
+ /* Center and style the h1 in the description block */
94
+ .gradio-container h1 {
95
+ text-align: center;
96
+ margin-top: 1.2em;
97
+ margin-bottom: 0.6em;
98
+ }
99
+
100
+ /* Chat area styling */
101
+ .chat-interface, .chat-interface .message {
102
+ background-color: transparent;
103
+ }
104
+
105
+ /* User message bubble */
106
+ .chat-message.user {
107
+ background-color: #0099FF;
108
+ color: #FFFFFF;
109
+ border-radius: 8px;
110
+ padding: 8px 12px;
111
+ margin: 4px 0;
112
+ }
113
+
114
+ /* Bot message bubble */
115
+ .chat-message.bot {
116
+ background-color: #E0F2FF;
117
+ color: #003366;
118
+ border-radius: 8px;
119
+ padding: 8px 12px;
120
+ margin: 4px 0;
121
+ }
122
+
123
+ /* Chat input */
124
+ .chat-input textarea {
125
+ background-color: #FFFFFF;
126
+ color: #003366;
127
+ border: 1px solid #0099FF;
128
+ border-radius: 6px;
129
+ }
130
+
131
+ /* Slider bars, buttons, etc. */
132
+ form.sliders input[type="range"] {
133
+ accent-color: #0077BE;
134
+ }
135
+ form.sliders label {
136
+ color: #003366;
137
+ }
138
+
139
+ .gradio-button, .chat-send-btn {
140
+ background-color: #0077BE;
141
+ color: #FFFFFF;
142
+ border-radius: 5px;
143
+ border: none;
144
+ cursor: pointer;
145
+ }
146
+
147
+ .gradio-button:hover, .chat-send-btn:hover {
148
+ background-color: #005FA0;
149
+ }
150
+
151
+ /* For warnings or system notes */
152
+ .text-orange-500 {
153
+ color: #FF6600 !important;
154
+ }
155
+ """
156
+
157
+ demo = gr.ChatInterface(
158
+ fn=generate,
159
+ additional_inputs=[
160
+ gr.Slider(
161
+ label="Max new tokens",
162
+ minimum=1,
163
+ maximum=MAX_MAX_NEW_TOKENS,
164
+ step=1,
165
+ value=DEFAULT_MAX_NEW_TOKENS,
166
+ ),
167
+ gr.Slider(
168
+ label="Temperature",
169
+ minimum=0.1,
170
+ maximum=4.0,
171
+ step=0.1,
172
+ value=0.6,
173
+ ),
174
+ gr.Slider(
175
+ label="Top-p (nucleus sampling)",
176
+ minimum=0.05,
177
+ maximum=1.0,
178
+ step=0.05,
179
+ value=0.9,
180
+ ),
181
+ gr.Slider(
182
+ label="Top-k",
183
+ minimum=1,
184
+ maximum=1000,
185
+ step=1,
186
+ value=50,
187
+ ),
188
+ gr.Slider(
189
+ label="Repetition penalty",
190
+ minimum=1.0,
191
+ maximum=2.0,
192
+ step=0.05,
193
+ value=1.2,
194
+ ),
195
+ ],
196
+ stop_btn=None,
197
+ examples=[
198
+ ["Hello there! How are you doing?"],
199
+ ["Can you explain briefly to me what is the Python programming language?"],
200
+ ["Explain the plot of Cinderella in a sentence."],
201
+ ["How many hours does it take a man to eat a Helicopter?"],
202
+ ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
203
+ ],
204
+ cache_examples=False,
205
+ type="messages",
206
+ description=DESCRIPTION,
207
+ # Removing css_paths, replace with direct CSS:
208
+ css=gemini_css,
209
+ fill_height=True,
210
+ )
211
 
212
  if __name__ == "__main__":
213
+ demo.queue(max_size=20).launch()
style.css CHANGED
@@ -1,115 +1,11 @@
1
- /* Main styling for Gemini theme */
2
- :root {
3
- --gemini-light-blue: #8ab4f8;
4
- --gemini-blue: #4285f4;
5
- --gemini-dark-blue: #1a73e8;
6
- --gemini-marine-blue: #174ea6;
7
- --gemini-white: #ffffff;
8
- --gemini-light-gray: #f8f9fa;
9
- }
10
-
11
- body {
12
- background: linear-gradient(135deg, var(--gemini-light-gray) 0%, var(--gemini-white) 100%);
13
- }
14
-
15
- /* Header and title styling */
16
  h1 {
17
  text-align: center;
18
  display: block;
19
- color: var(--gemini-marine-blue);
20
- font-weight: 600;
21
- margin-bottom: 1.5rem;
22
- }
23
-
24
- /* Chat interface styling */
25
- .gradio-container {
26
- max-width: 1200px !important;
27
- margin-left: auto !important;
28
- margin-right: auto !important;
29
- }
30
-
31
- /* Message bubbles */
32
- .message-wrap .message.user {
33
- background-color: var(--gemini-light-gray);
34
- border: 1px solid #e0e0e0;
35
  }
36
 
37
- .message-wrap .message.bot {
38
- background-color: var(--gemini-light-blue);
39
- background: linear-gradient(135deg, var(--gemini-light-blue) 0%, var(--gemini-blue) 100%);
40
- color: var(--gemini-white);
41
- }
42
-
43
- /* Button styling */
44
- #duplicate-button,
45
- button.primary,
46
- .button.primary {
47
  margin: auto;
48
- color: var(--gemini-white);
49
- background: var(--gemini-dark-blue);
50
- background: linear-gradient(135deg, var(--gemini-blue) 0%, var(--gemini-marine-blue) 100%);
51
  border-radius: 100vh;
52
- border: none;
53
- transition: all 0.3s ease;
54
- box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
55
- }
56
-
57
- #duplicate-button:hover,
58
- button.primary:hover,
59
- .button.primary:hover {
60
- background: var(--gemini-marine-blue);
61
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
62
- transform: translateY(-1px);
63
- }
64
-
65
- /* Slider styling */
66
- .gradio-slider input[type="range"]::-webkit-slider-thumb {
67
- background: var(--gemini-blue);
68
- }
69
-
70
- .gradio-slider input[type="range"] {
71
- background: linear-gradient(90deg, var(--gemini-blue) 0%, var(--gemini-light-blue) 100%);
72
  }
73
-
74
- /* Chat input area */
75
- .chat-input {
76
- border-color: var(--gemini-light-blue);
77
- box-shadow: 0 0 4px rgba(138, 180, 248, 0.3);
78
- }
79
-
80
- .chat-input:focus {
81
- border-color: var(--gemini-blue);
82
- box-shadow: 0 0 6px rgba(66, 133, 244, 0.5);
83
- }
84
-
85
- /* Examples section */
86
- .examples-panel {
87
- background: linear-gradient(135deg, var(--gemini-white) 0%, var(--gemini-light-gray) 100%);
88
- border: 1px solid rgba(138, 180, 248, 0.3);
89
- border-radius: 8px;
90
- }
91
-
92
- .examples button {
93
- background-color: var(--gemini-light-gray);
94
- border: 1px solid var(--gemini-light-blue);
95
- color: var(--gemini-marine-blue);
96
- }
97
-
98
- .examples button:hover {
99
- background-color: var(--gemini-light-blue);
100
- color: var(--gemini-white);
101
- }
102
-
103
- /* Additional styling for the description block */
104
- .prose {
105
- color: var(--gemini-marine-blue);
106
- }
107
-
108
- .prose a {
109
- color: var(--gemini-blue);
110
- text-decoration: none;
111
- }
112
-
113
- .prose a:hover {
114
- text-decoration: underline;
115
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  h1 {
2
  text-align: center;
3
  display: block;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  }
5
 
6
+ #duplicate-button {
 
 
 
 
 
 
 
 
 
7
  margin: auto;
8
+ color: #fff;
9
+ background: #1565c0;
 
10
  border-radius: 100vh;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }