sheonhan commited on
Commit
3309ae3
1 Parent(s): 27dc69b

reflect feedback

Browse files
Files changed (1) hide show
  1. app.py +130 -99
app.py CHANGED
@@ -27,16 +27,16 @@ theme = gr.themes.Monochrome(
27
  font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
28
  )
29
 
30
- # if HF_TOKEN:
31
- # try:
32
- # shutil.rmtree("./data/")
33
- # except:
34
- # pass
35
 
36
- # repo = Repository(
37
- # local_dir="./data/", clone_from="trl-lib/star-chat-prompts", use_auth_token=HF_TOKEN, repo_type="dataset"
38
- # )
39
- # repo.git_pull()
40
 
41
 
42
  def save_inputs_and_outputs(inputs, outputs, generate_kwargs):
@@ -76,10 +76,11 @@ def generate(
76
  user_message,
77
  chatbot,
78
  history,
79
- temperature=0.5,
80
- top_p=0.25,
81
- top_k=50,
82
- max_new_tokens=512,
 
83
  do_save=True,
84
  ):
85
  # Don't return meaningless message when the input is empty
@@ -109,8 +110,8 @@ def generate(
109
 
110
  generate_kwargs = {
111
  "temperature": temperature,
112
- "top_p": top_p,
113
  "top_k": top_k,
 
114
  "max_new_tokens": max_new_tokens,
115
  }
116
 
@@ -123,10 +124,10 @@ def generate(
123
  temperature=temperature,
124
  max_new_tokens=max_new_tokens,
125
  top_p=top_p,
 
126
  do_sample=True,
127
  truncate=999,
128
  seed=42,
129
- repetition_penalty=1.2,
130
  stop_sequences=["<|end|>"],
131
  )
132
 
@@ -147,22 +148,22 @@ def generate(
147
 
148
  chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
149
 
150
- # if HF_TOKEN and do_save:
151
- # try:
152
- # print("Pushing prompt and completion to the Hub")
153
- # save_inputs_and_outputs(prompt, output, generate_kwargs)
154
- # except Exception as e:
155
- # print(e)
156
 
157
  yield chat, history, user_message, ""
158
 
159
 
160
  examples = [
 
161
  "What's the capital city of Brunei?",
162
- "How can I sort a list in Python?",
163
- "What date is it today? Use Python to answer the question.",
164
  "What's the meaning of life?",
165
- "How can I write a Java function to generate the nth Fibonacci number?",
166
  ]
167
 
168
 
@@ -171,10 +172,11 @@ examples = [
171
  # user_message,
172
  # chatbot,
173
  # history,
174
- # temperature=0.5,
175
- # top_p=0.25,
176
- # top_k=50,
177
- # max_new_tokens=512,
 
178
  # do_save=True,
179
  # ):
180
  # # Do nothing if there's no history
@@ -189,7 +191,7 @@ examples = [
189
  # chatbot = chatbot[:-1]
190
  # history = history[:-2]
191
 
192
- # return generate(system_message, user_message, chatbot, history, temperature, top_p, top_k, max_new_tokens, do_save)
193
 
194
 
195
  def clear_chat():
@@ -205,38 +207,32 @@ def process_example(args):
205
  title = """<h1 align="center">⭐ Chat with StarCoder Demo 💬</h1>"""
206
  custom_css = """
207
  #banner-image {
208
- display: block;
209
- margin-left: auto;
210
- margin-right: auto;
211
- width: 40%;
212
  }
213
 
214
  #chat-message .message {
215
- padding: 15px;
216
- border-color: #a5b4fc;
217
- background-color: #eef2ff;
218
  }
219
 
220
  #chat-message .message.bot {
221
- padding: 15px;
222
- border-color: #e2e8f0;
223
  background-color: #f8fafc;
224
  }
225
 
226
- #system-message {
227
- min-height: 527px;
228
- }
229
-
230
- #system-message textarea {
231
- min-height: 462px;
232
- }
233
-
234
  #chat-message {
235
  font-size: 14px;
236
- min-height: 500px;
237
  }
238
 
239
- message pending
 
 
240
 
241
  """
242
 
@@ -244,17 +240,25 @@ message pending
244
 
245
  with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
246
  gr.HTML(title)
247
- gr.Image("StarCoderBanner.png", elem_id="banner-image", show_label=False)
248
- gr.Markdown(
 
 
 
 
249
  """
250
- This demo showcases an instruction fine-tuned model based on [StarCoder](https://huggingface.co/bigcode/starcoder), a 16B parameter model trained on one trillion tokens sourced from 80+ programming languages, GitHub issues, Git commits, and Jupyter notebooks (all permissively licensed). With an enterprise-friendly license, 8,192 token context length, and fast large-batch inference via [multi-query attention](https://arxiv.org/abs/1911.02150), StarCoder is currently the best open-source choice for code-based applications. For more details, check out our [blog post]().
 
 
 
 
251
 
252
  ⚠️ **Intended Use**: this app and its [supporting model](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1) are provided as educational tools to explain instruction fine-tuning; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1#bias-risks-and-limitations).
253
 
254
  ⚠️ **Data Collection**: by default, we are collecting the prompts entered in this app to further improve and evaluate the model. Do NOT share any personal or sensitive information while using the app! You can opt out of this data collection by removing the checkbox below.
255
  """
256
  )
257
-
258
  with gr.Row():
259
  do_save = gr.Checkbox(
260
  value=True,
@@ -263,27 +267,71 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
263
  )
264
 
265
  with gr.Row():
266
- with gr.Column(scale=1):
267
  system_message = gr.Textbox(
268
  elem_id="system-message",
269
- placeholder="Below is a conversation between a human user and a helpful AI coding assistant",
270
  label="System prompt",
271
  )
272
-
273
- with gr.Column(scale=1):
274
- with gr.Box():
275
- output = gr.Markdown()
276
- chatbot = gr.Chatbot(elem_id="chat-message", label="Chat")
277
 
278
  with gr.Row():
279
  with gr.Column(scale=3):
280
  user_message = gr.Textbox(placeholder="Enter your message here", show_label=False, elem_id="q-input")
281
  with gr.Row():
282
  send_button = gr.Button("Send", elem_id="send-btn", visible=True)
 
283
  # regenerate_button = gr.Button("Regenerate", elem_id="send-btn", visible=True)
284
 
285
  clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  # with gr.Group(elem_id="share-btn-container"):
288
  # community_icon = gr.HTML(community_icon_html, visible=True)
289
  # loading_icon = gr.HTML(loading_icon_html, visible=True)
@@ -297,43 +345,6 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
297
  outputs=[output],
298
  )
299
 
300
- with gr.Column(scale=1):
301
- temperature = gr.Slider(
302
- label="Temperature",
303
- value=0.2,
304
- minimum=0.0,
305
- maximum=1.0,
306
- step=0.1,
307
- interactive=True,
308
- info="Higher values produce more diverse outputs",
309
- )
310
- top_k = gr.Slider(
311
- label="Top-k",
312
- value=50,
313
- minimum=0.0,
314
- maximum=100,
315
- step=1,
316
- interactive=True,
317
- info="Sample from a shortlist of top-k tokens",
318
- )
319
- top_p = gr.Slider(
320
- label="Top-p (nucleus sampling)",
321
- value=0.95,
322
- minimum=0.0,
323
- maximum=1,
324
- step=0.05,
325
- interactive=True,
326
- info="Higher values sample more low-probability tokens",
327
- )
328
- max_new_tokens = gr.Slider(
329
- label="Max new tokens",
330
- value=384,
331
- minimum=0,
332
- maximum=2048,
333
- step=4,
334
- interactive=True,
335
- info="The maximum numbers of new tokens",
336
- )
337
 
338
  history = gr.State([])
339
  # To clear out "message" input textbox and use this to regenerate message
@@ -347,9 +358,10 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
347
  chatbot,
348
  history,
349
  temperature,
350
- top_p,
351
  top_k,
 
352
  max_new_tokens,
 
353
  do_save,
354
  ],
355
  outputs=[chatbot, history, last_user_message, user_message],
@@ -363,9 +375,10 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
363
  chatbot,
364
  history,
365
  temperature,
366
- top_p,
367
  top_k,
 
368
  max_new_tokens,
 
369
  do_save,
370
  ],
371
  outputs=[chatbot, history, last_user_message, user_message],
@@ -379,9 +392,10 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
379
  # chatbot,
380
  # history,
381
  # temperature,
382
- # top_p,
383
  # top_k,
 
384
  # max_new_tokens,
 
385
  # do_save,
386
  # ],
387
  # outputs=[chatbot, history, last_user_message, user_message],
@@ -389,5 +403,22 @@ with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
389
 
390
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
391
  # share_button.click(None, [], [], _js=share_js)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
 
393
  demo.queue(concurrency_count=16).launch(debug=True)
 
27
  font=[gr.themes.GoogleFont("Open Sans"), "ui-sans-serif", "system-ui", "sans-serif"],
28
  )
29
 
30
+ if HF_TOKEN:
31
+ try:
32
+ shutil.rmtree("./data/")
33
+ except:
34
+ pass
35
 
36
+ repo = Repository(
37
+ local_dir="./data/", clone_from="trl-lib/star-chat-prompts", use_auth_token=HF_TOKEN, repo_type="dataset"
38
+ )
39
+ repo.git_pull()
40
 
41
 
42
  def save_inputs_and_outputs(inputs, outputs, generate_kwargs):
 
76
  user_message,
77
  chatbot,
78
  history,
79
+ temperature,
80
+ top_k,
81
+ top_p,
82
+ max_new_tokens,
83
+ repetition_penalty,
84
  do_save=True,
85
  ):
86
  # Don't return meaningless message when the input is empty
 
110
 
111
  generate_kwargs = {
112
  "temperature": temperature,
 
113
  "top_k": top_k,
114
+ "top_p": top_p,
115
  "max_new_tokens": max_new_tokens,
116
  }
117
 
 
124
  temperature=temperature,
125
  max_new_tokens=max_new_tokens,
126
  top_p=top_p,
127
+ repetition_penalty=repetition_penalty,
128
  do_sample=True,
129
  truncate=999,
130
  seed=42,
 
131
  stop_sequences=["<|end|>"],
132
  )
133
 
 
148
 
149
  chat = [(history[i].strip(), history[i + 1].strip()) for i in range(0, len(history) - 1, 2)]
150
 
151
+ if HF_TOKEN and do_save:
152
+ try:
153
+ print("Pushing prompt and completion to the Hub")
154
+ save_inputs_and_outputs(prompt, output, generate_kwargs)
155
+ except Exception as e:
156
+ print(e)
157
 
158
  yield chat, history, user_message, ""
159
 
160
 
161
  examples = [
162
+ "How can I write a Python function to generate the nth Fibonacci number?",
163
  "What's the capital city of Brunei?",
164
+ "How do I get the current date using shell commands? Explain how it works.",
 
165
  "What's the meaning of life?",
166
+ "Write a function in Python to reverse words in a given string.",
167
  ]
168
 
169
 
 
172
  # user_message,
173
  # chatbot,
174
  # history,
175
+ # temperature,
176
+ # top_k,
177
+ # top_p,
178
+ # max_new_tokens,
179
+ # repetition_penalty,
180
  # do_save=True,
181
  # ):
182
  # # Do nothing if there's no history
 
191
  # chatbot = chatbot[:-1]
192
  # history = history[:-2]
193
 
194
+ # return generate(system_message, user_message, chatbot, history, temperature, top_k, top_p, max_new_tokens, repetition_penalty, do_save)
195
 
196
 
197
  def clear_chat():
 
207
  title = """<h1 align="center">⭐ Chat with StarCoder Demo 💬</h1>"""
208
  custom_css = """
209
  #banner-image {
210
+ display: block;
211
+ margin-left: auto;
212
+ margin-right: auto;
213
+ /* width: 40%; */
214
  }
215
 
216
  #chat-message .message {
217
+ /* padding: 15px; */
218
+ border-color: #a5b4fc;
219
+ background-color: #eef2ff;
220
  }
221
 
222
  #chat-message .message.bot {
223
+ /* padding: 15px; */
224
+ border-color: #e2e8f0;
225
  background-color: #f8fafc;
226
  }
227
 
 
 
 
 
 
 
 
 
228
  #chat-message {
229
  font-size: 14px;
230
+ min-height: 300px;
231
  }
232
 
233
+ #parameters-accordion {
234
+ color: #0f172a;
235
+ }
236
 
237
  """
238
 
 
240
 
241
  with gr.Blocks(theme=theme, analytics_enabled=False, css=custom_css) as demo:
242
  gr.HTML(title)
243
+
244
+ with gr.Row():
245
+ with gr.Column():
246
+ gr.Image("StarCoderBanner.png", elem_id="banner-image", show_label=False)
247
+ with gr.Column():
248
+ gr.Markdown(
249
  """
250
+ 💻 This demo showcases an instruction fine-tuned model based on **[StarCoder](https://huggingface.co/bigcode/starcoder)**, a 16B parameter model trained on one trillion tokens sourced from 80+ programming languages, GitHub issues, Git commits, and Jupyter notebooks (all permissively licensed).
251
+
252
+ 🤗 With an enterprise-friendly license, 8,192 token context length, and fast large-batch inference via [multi-query attention](https://arxiv.org/abs/1911.02150), **StarCoder** is currently the best open-source choice for code-based applications.
253
+
254
+ 📝 For more details, check out our [blog post]().
255
 
256
  ⚠️ **Intended Use**: this app and its [supporting model](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1) are provided as educational tools to explain instruction fine-tuning; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1#bias-risks-and-limitations).
257
 
258
  ⚠️ **Data Collection**: by default, we are collecting the prompts entered in this app to further improve and evaluate the model. Do NOT share any personal or sensitive information while using the app! You can opt out of this data collection by removing the checkbox below.
259
  """
260
  )
261
+
262
  with gr.Row():
263
  do_save = gr.Checkbox(
264
  value=True,
 
267
  )
268
 
269
  with gr.Row():
270
+ with gr.Box(elem_id="chat-box"):
271
  system_message = gr.Textbox(
272
  elem_id="system-message",
273
+ placeholder="Below is a conversation between a human user and a helpful AI coding assistant.",
274
  label="System prompt",
275
  )
276
+ output = gr.Markdown()
277
+ chatbot = gr.Chatbot(elem_id="chat-message", label="Chat")
 
 
 
278
 
279
  with gr.Row():
280
  with gr.Column(scale=3):
281
  user_message = gr.Textbox(placeholder="Enter your message here", show_label=False, elem_id="q-input")
282
  with gr.Row():
283
  send_button = gr.Button("Send", elem_id="send-btn", visible=True)
284
+
285
  # regenerate_button = gr.Button("Regenerate", elem_id="send-btn", visible=True)
286
 
287
  clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
288
 
289
+ with gr.Accordion(label="Parameters", open=False, elem_id="parameters-accordion"):
290
+ temperature = gr.Slider(
291
+ label="Temperature",
292
+ value=0.2,
293
+ minimum=0.0,
294
+ maximum=1.0,
295
+ step=0.1,
296
+ interactive=True,
297
+ info="Higher values produce more diverse outputs",
298
+ )
299
+ top_k = gr.Slider(
300
+ label="Top-k",
301
+ value=50,
302
+ minimum=0.0,
303
+ maximum=100,
304
+ step=1,
305
+ interactive=True,
306
+ info="Sample from a shortlist of top-k tokens",
307
+ )
308
+ top_p = gr.Slider(
309
+ label="Top-p (nucleus sampling)",
310
+ value=0.95,
311
+ minimum=0.0,
312
+ maximum=1,
313
+ step=0.05,
314
+ interactive=True,
315
+ info="Higher values sample more low-probability tokens",
316
+ )
317
+ max_new_tokens = gr.Slider(
318
+ label="Max new tokens",
319
+ value=384,
320
+ minimum=0,
321
+ maximum=2048,
322
+ step=4,
323
+ interactive=True,
324
+ info="The maximum numbers of new tokens",
325
+ )
326
+ repetition_penalty = gr.Slider(
327
+ label="Repetition Penalty",
328
+ value=1.2,
329
+ minimum=0.0,
330
+ maximum=10,
331
+ step=0.1,
332
+ interactive=True,
333
+ info="The parameter for repetition penalty. 1.0 means no penalty.",
334
+ )
335
  # with gr.Group(elem_id="share-btn-container"):
336
  # community_icon = gr.HTML(community_icon_html, visible=True)
337
  # loading_icon = gr.HTML(loading_icon_html, visible=True)
 
345
  outputs=[output],
346
  )
347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
 
349
  history = gr.State([])
350
  # To clear out "message" input textbox and use this to regenerate message
 
358
  chatbot,
359
  history,
360
  temperature,
 
361
  top_k,
362
+ top_p,
363
  max_new_tokens,
364
+ repetition_penalty,
365
  do_save,
366
  ],
367
  outputs=[chatbot, history, last_user_message, user_message],
 
375
  chatbot,
376
  history,
377
  temperature,
 
378
  top_k,
379
+ top_p,
380
  max_new_tokens,
381
+ repetition_penalty,
382
  do_save,
383
  ],
384
  outputs=[chatbot, history, last_user_message, user_message],
 
392
  # chatbot,
393
  # history,
394
  # temperature,
 
395
  # top_k,
396
+ # top_p,
397
  # max_new_tokens,
398
+ # repetition_penalty,
399
  # do_save,
400
  # ],
401
  # outputs=[chatbot, history, last_user_message, user_message],
 
403
 
404
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
405
  # share_button.click(None, [], [], _js=share_js)
406
+ with gr.Row():
407
+ with gr.Column():
408
+ gr.Image("StarCoderBanner.png", elem_id="banner-image", show_label=False)
409
+ with gr.Column():
410
+ gr.Markdown(
411
+ """
412
+ 💻 This demo showcases an instruction fine-tuned model based on **[StarCoder](https://huggingface.co/bigcode/starcoder)**, a 16B parameter model trained on one trillion tokens sourced from 80+ programming languages, GitHub issues, Git commits, and Jupyter notebooks (all permissively licensed).
413
+
414
+ 🤗 With an enterprise-friendly license, 8,192 token context length, and fast large-batch inference via [multi-query attention](https://arxiv.org/abs/1911.02150), **StarCoder** is currently the best open-source choice for code-based applications.
415
+
416
+ 📝 For more details, check out our [blog post]().
417
+
418
+ ⚠️ **Intended Use**: this app and its [supporting model](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1) are provided as educational tools to explain instruction fine-tuning; not to serve as replacement for human expertise. For more details on the model's limitations in terms of factuality and biases, see the [model card](https://huggingface.co/HuggingFaceH4/starcoderbase-finetuned-oasst1#bias-risks-and-limitations).
419
+
420
+ ⚠️ **Data Collection**: by default, we are collecting the prompts entered in this app to further improve and evaluate the model. Do NOT share any personal or sensitive information while using the app! You can opt out of this data collection by removing the checkbox below.
421
+ """
422
+ )
423
 
424
  demo.queue(concurrency_count=16).launch(debug=True)