chansung commited on
Commit
d813bf6
·
1 Parent(s): 0610132

stylizing chatbot interface

Browse files
Files changed (1) hide show
  1. app.py +67 -2
app.py CHANGED
@@ -19,6 +19,52 @@ from text_generation import Client
19
 
20
  from utils import get_full_text, wrap_html_code
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
23
  REPO_ID = "sheonhan/rm-test-data"
24
  API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/starcoderbase-finetuned-oasst1"
@@ -134,7 +180,7 @@ def on_select(event: gr.SelectData, history):
134
  return history
135
 
136
 
137
- with gr.Blocks() as demo:
138
  chatbot = gr.Chatbot()
139
  user_message = gr.Textbox()
140
  clear = gr.Button("Clear")
@@ -144,9 +190,28 @@ with gr.Blocks() as demo:
144
  [user_message, chatbot],
145
  [user_message, chatbot],
146
  queue=False,
 
 
 
 
 
 
 
 
147
  )
148
 
149
- chatbot.select(on_select, chatbot, chatbot)
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  clear.click(lambda: None, None, chatbot, queue=False)
152
 
 
19
 
20
  from utils import get_full_text, wrap_html_code
21
 
22
+ STYLE = """
23
+
24
+ // for the last chat message on user side
25
+ .message.user.latest {
26
+ background-color: #F9FBE7;
27
+ border: none;
28
+ color: black;
29
+ }
30
+
31
+ // for the last chat message on bot side
32
+ .message.bot.latest {
33
+ background-color: #CE93D8;
34
+ border: none;
35
+ color: black;
36
+ }
37
+
38
+ // when user hovers on the two answers
39
+ // generated by a language model
40
+ .message.bot.latest:hover {
41
+ box-shadow: 0 0 15px 0.5px #E1BEE7 !important;
42
+ }
43
+
44
+ // "done" class is injected when user has made
45
+ // decision between two candidate generated answers
46
+ .message.bot.done {
47
+ animation: colorTransition 2s ease-in-out;
48
+ }
49
+
50
+ // fade out animation effect when user selects a choice
51
+ @keyframes colorTransition {
52
+ 0% {
53
+ background-color: var(--checkbox-background-color-selected);
54
+ }
55
+ 100% {
56
+ background-color: var(--background-fill-secondary);
57
+ }
58
+ }
59
+
60
+ .button:active {
61
+ color: black;
62
+ border: none;
63
+ background-color: #CE93D8 !important;
64
+ box-shadow: 0 0 15px 0.5px #F3E5F5 !important;
65
+ }
66
+ """
67
+
68
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
69
  REPO_ID = "sheonhan/rm-test-data"
70
  API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/starcoderbase-finetuned-oasst1"
 
180
  return history
181
 
182
 
183
+ with gr.Blocks(css=STYLE) as demo:
184
  chatbot = gr.Chatbot()
185
  user_message = gr.Textbox()
186
  clear = gr.Button("Clear")
 
190
  [user_message, chatbot],
191
  [user_message, chatbot],
192
  queue=False,
193
+ ).then(
194
+ None, None, None,
195
+ _js="""()=>{
196
+
197
+ let last_elem = document.querySelector("div.message.bot.done");
198
+ last_elem.classList.remove("done");
199
+ }
200
+ """
201
  )
202
 
203
+ chatbot.select(
204
+ on_select, chatbot, chatbot
205
+ ).then(
206
+ None, None, None,
207
+ _js="""()=>{
208
+
209
+ let last_elem = document.querySelector("div.message.bot.latest");
210
+ last_elem.classList.remove("latest");
211
+ last_elem.classList.add("done");
212
+ }
213
+ """
214
+ )
215
 
216
  clear.click(lambda: None, None, chatbot, queue=False)
217