BryanBradfo commited on
Commit
fd4f813
·
1 Parent(s): e0cf4f1

adding icons, improving user interface

Browse files
Files changed (3) hide show
  1. app.py +62 -6
  2. gemma.png +0 -0
  3. user.png +0 -0
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from collections.abc import Iterator
3
  from threading import Thread
4
 
@@ -42,6 +43,7 @@ def generate(
42
  top_k: int = 50,
43
  repetition_penalty: float = 1.2,
44
  ) -> Iterator[str]:
 
45
  conversation = chat_history.copy()
46
  conversation.append({"role": "user", "content": message})
47
 
@@ -63,16 +65,24 @@ def generate(
63
  num_beams=1,
64
  repetition_penalty=repetition_penalty,
65
  )
 
66
  t = Thread(target=model.generate, kwargs=generate_kwargs)
67
  t.start()
68
 
69
  outputs = []
70
- for text in streamer:
71
- outputs.append(text)
72
- yield "".join(outputs)
 
 
 
 
73
 
74
 
75
- # A revised Gemini-like CSS with smoother gradients and better contrast.
 
 
 
76
  gemini_css = """
77
  :root {
78
  --gradient-start: #66AEEF; /* lighter top */
@@ -110,9 +120,33 @@ a, a:visited {
110
  /* Remove harsh frames around chat messages */
111
  .chat-message {
112
  border: none !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  }
114
 
115
- /* User message bubble: a deeper blue with white text */
 
 
 
 
 
 
 
 
 
 
 
116
  .chat-message.user {
117
  background-color: #0284C7 !important;
118
  color: #FFFFFF !important;
@@ -121,7 +155,7 @@ a, a:visited {
121
  margin: 6px 0;
122
  }
123
 
124
- /* Bot message bubble: very light blue with darker text */
125
  .chat-message.bot {
126
  background-color: #EFF8FF !important;
127
  color: #333 !important;
@@ -158,6 +192,28 @@ form.sliders label {
158
  background-color: #026FA6 !important;
159
  }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  /* Additional spacing / small tweaks */
162
  #duplicate-button {
163
  margin: auto;
 
1
  import os
2
+ import queue
3
  from collections.abc import Iterator
4
  from threading import Thread
5
 
 
43
  top_k: int = 50,
44
  repetition_penalty: float = 1.2,
45
  ) -> Iterator[str]:
46
+ """Generate text from the model and stream tokens back to the UI."""
47
  conversation = chat_history.copy()
48
  conversation.append({"role": "user", "content": message})
49
 
 
65
  num_beams=1,
66
  repetition_penalty=repetition_penalty,
67
  )
68
+
69
  t = Thread(target=model.generate, kwargs=generate_kwargs)
70
  t.start()
71
 
72
  outputs = []
73
+ try:
74
+ for text in streamer:
75
+ outputs.append(text)
76
+ yield "".join(outputs)
77
+ except queue.Empty:
78
+ # End of stream; avoid traceback
79
+ return
80
 
81
 
82
+ # Updated CSS to:
83
+ # 1) give the examples a soft blue style,
84
+ # 2) add small icons for user/bot,
85
+ # 3) keep the overall smooth, Gemini-like gradient.
86
  gemini_css = """
87
  :root {
88
  --gradient-start: #66AEEF; /* lighter top */
 
120
  /* Remove harsh frames around chat messages */
121
  .chat-message {
122
  border: none !important;
123
+ position: relative;
124
+ }
125
+
126
+ /* Icons for user and bot messages */
127
+ .chat-message.user::before {
128
+ content: '';
129
+ display: inline-block;
130
+ background: url('user.png') center center no-repeat;
131
+ background-size: cover;
132
+ width: 24px;
133
+ height: 24px;
134
+ margin-right: 8px;
135
+ vertical-align: middle;
136
  }
137
 
138
+ .chat-message.bot::before {
139
+ content: '';
140
+ display: inline-block;
141
+ background: url('gemma.png') center center no-repeat;
142
+ background-size: cover;
143
+ width: 24px;
144
+ height: 24px;
145
+ margin-right: 8px;
146
+ vertical-align: middle;
147
+ }
148
+
149
+ /* User bubble: a deeper blue with white text */
150
  .chat-message.user {
151
  background-color: #0284C7 !important;
152
  color: #FFFFFF !important;
 
155
  margin: 6px 0;
156
  }
157
 
158
+ /* Bot bubble: very light blue with darker text */
159
  .chat-message.bot {
160
  background-color: #EFF8FF !important;
161
  color: #333 !important;
 
192
  background-color: #026FA6 !important;
193
  }
194
 
195
+ /* Style the example "pill" buttons */
196
+ .show-examples {
197
+ display: flex !important;
198
+ flex-wrap: wrap;
199
+ gap: 16px;
200
+ justify-content: center;
201
+ margin-bottom: 1em;
202
+ }
203
+
204
+ .show-examples .example {
205
+ background-color: #EFF8FF;
206
+ border: 1px solid #66AEEF;
207
+ border-radius: 8px;
208
+ color: #333 !important;
209
+ padding: 10px 16px;
210
+ cursor: pointer;
211
+ transition: background-color 0.2s;
212
+ }
213
+ .show-examples .example:hover {
214
+ background-color: #E0F2FF;
215
+ }
216
+
217
  /* Additional spacing / small tweaks */
218
  #duplicate-button {
219
  margin: auto;
gemma.png ADDED
user.png ADDED