lvkaokao commited on
Commit
9747a90
1 Parent(s): 51f950f

update codes.

Browse files
Files changed (1) hide show
  1. app.py +32 -35
app.py CHANGED
@@ -96,7 +96,7 @@ def load_demo_single(models, url_params):
96
  gr.Textbox.update(visible=True),
97
  gr.Button.update(visible=True),
98
  gr.Row.update(visible=True),
99
- gr.Accordion.update(visible=False),
100
  )
101
 
102
 
@@ -248,7 +248,7 @@ def http_bot(state, model_selector, temperature, max_new_tokens, request: gr.Req
248
  try:
249
  # Stream output
250
  response = requests.post(
251
- worker_addr + "/worker_generate_stream",
252
  headers=headers,
253
  json=pload,
254
  stream=True,
@@ -260,7 +260,6 @@ def http_bot(state, model_selector, temperature, max_new_tokens, request: gr.Req
260
  if data["error_code"] == 0:
261
  output = data["text"][skip_echo_len:].strip()
262
  output = post_process_code(output)
263
-
264
  state.messages[-1][-1] = output + "▌"
265
  yield (state, state.to_gradio_chatbot()) + (disable_btn,) * 5
266
  else:
@@ -287,15 +286,12 @@ def http_bot(state, model_selector, temperature, max_new_tokens, request: gr.Req
287
  return
288
 
289
  finish_tstamp = time.time() - start_time
 
290
 
291
- elapsed_time = "{}s".format(round(finish_tstamp, 4))
292
- last_message = state.messages[-1]
293
- last_element = last_message[-1]
294
- if "<p id='time-style'>" in last_element:
295
- last_element = last_element.split("<p id='time-style'>")[0]
296
 
297
-
298
- state.messages[-1][-1] = last_element + "<p id='time-style'>" + elapsed_time + "</p>"
299
  yield (state, state.to_gradio_chatbot()) + (enable_btn,) * 5
300
 
301
  logger.info(f"{output}")
@@ -340,18 +336,16 @@ pre {
340
  margin-top: 0;
341
  }
342
 
343
- #time-style {
344
- position: absolute;
345
- right: 0;
346
- bottom: -10px;
347
- font-size: 0.9rem;
348
- color: #979797;
349
- }
350
-
351
  #notice_markdown p{
352
  color: #fff !important;
353
  }
354
 
 
 
 
 
 
 
355
  gradio-app {
356
  background: linear-gradient(to bottom, #ba97d8, #5400ff) !important;
357
  padding: 3%;
@@ -400,12 +394,7 @@ gradio-app {
400
  #btn-list-style {
401
  background: #eee0;
402
  border: 1px solid #691ef7;
403
- }
404
-
405
- .img-logo-style {
406
- width: 3.5rem;
407
- float: left;
408
- }
409
 
410
  .title {
411
  font-size: 1.5rem;
@@ -416,12 +405,17 @@ width: 3.5rem;
416
  footer {
417
  display: none !important;
418
  }
 
 
 
 
 
419
  """
420
  )
421
 
422
 
423
  def build_single_model_ui(models):
424
-
425
  notice_markdown = """
426
  <div class='title'>
427
  <img src='https://i.postimg.cc/Pfv4vV6R/Microsoft-Teams-image-23.png' class='img-logo-style'/> NeuralChat
@@ -454,15 +448,7 @@ def build_single_model_ui(models):
454
  with gr.Column(scale=1, min_width=50):
455
  send_btn = gr.Button(value="Send", visible=False, elem_id="btn-send-style")
456
 
457
- with gr.Row(visible=False, elem_id="btn-style") as button_row:
458
- upvote_btn = gr.Button(value="👍 Upvote", interactive=False, visible=False, elem_id="btn-list-style")
459
- downvote_btn = gr.Button(value="👎 Downvote", interactive=False, visible=False, elem_id="btn-list-style")
460
- flag_btn = gr.Button(value="⚠️ Flag", interactive=False, visible=False, elem_id="btn-list-style")
461
- # stop_btn = gr.Button(value="⏹️ Stop Generation", interactive=False)
462
- regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False, elem_id="btn-list-style")
463
- clear_btn = gr.Button(value="🗑️ Clear history", interactive=False, elem_id="btn-list-style")
464
-
465
- with gr.Accordion("Parameters", open=False, visible=False) as parameter_row:
466
  temperature = gr.Slider(
467
  minimum=0.0,
468
  maximum=1.0,
@@ -470,6 +456,7 @@ def build_single_model_ui(models):
470
  step=0.1,
471
  interactive=True,
472
  label="Temperature",
 
473
  )
474
  max_output_tokens = gr.Slider(
475
  minimum=0,
@@ -480,6 +467,16 @@ def build_single_model_ui(models):
480
  label="Max output tokens",
481
  )
482
 
 
 
 
 
 
 
 
 
 
 
483
  gr.Markdown(learn_more_markdown)
484
 
485
  # Register listeners
@@ -572,7 +569,7 @@ if __name__ == "__main__":
572
  # port = "mlp-dgx-01.sh.intel.com"
573
  concurrency_count = 10
574
  model_list_mode = "once"
575
- share = True
576
  moderate = False
577
 
578
  set_global_vars(controller_url, moderate)
 
96
  gr.Textbox.update(visible=True),
97
  gr.Button.update(visible=True),
98
  gr.Row.update(visible=True),
99
+ gr.Accordion.update(visible=True),
100
  )
101
 
102
 
 
248
  try:
249
  # Stream output
250
  response = requests.post(
251
+ controller_url + "/worker_generate_stream",
252
  headers=headers,
253
  json=pload,
254
  stream=True,
 
260
  if data["error_code"] == 0:
261
  output = data["text"][skip_echo_len:].strip()
262
  output = post_process_code(output)
 
263
  state.messages[-1][-1] = output + "▌"
264
  yield (state, state.to_gradio_chatbot()) + (disable_btn,) * 5
265
  else:
 
286
  return
287
 
288
  finish_tstamp = time.time() - start_time
289
+ elapsed_time = "\n✅generation elapsed time: {}s".format(round(finish_tstamp, 4))
290
 
291
+ # elapsed_time = "\n{}s".format(round(finish_tstamp, 4))
292
+ # elapsed_time = "<p class='time-style'>{}s </p>".format(round(finish_tstamp, 4))
 
 
 
293
 
294
+ state.messages[-1][-1] = state.messages[-1][-1][:-1] + elapsed_time
 
295
  yield (state, state.to_gradio_chatbot()) + (enable_btn,) * 5
296
 
297
  logger.info(f"{output}")
 
336
  margin-top: 0;
337
  }
338
 
 
 
 
 
 
 
 
 
339
  #notice_markdown p{
340
  color: #fff !important;
341
  }
342
 
343
+
344
+ #notice_markdown h1, #notice_markdown h4 {
345
+ color: #fff;
346
+ margin-top: 0;
347
+ }
348
+
349
  gradio-app {
350
  background: linear-gradient(to bottom, #ba97d8, #5400ff) !important;
351
  padding: 3%;
 
394
  #btn-list-style {
395
  background: #eee0;
396
  border: 1px solid #691ef7;
397
+ }
 
 
 
 
 
398
 
399
  .title {
400
  font-size: 1.5rem;
 
405
  footer {
406
  display: none !important;
407
  }
408
+
409
+ .img-logo-style {
410
+ width: 3.5rem;
411
+ float: left;
412
+ }
413
  """
414
  )
415
 
416
 
417
  def build_single_model_ui(models):
418
+
419
  notice_markdown = """
420
  <div class='title'>
421
  <img src='https://i.postimg.cc/Pfv4vV6R/Microsoft-Teams-image-23.png' class='img-logo-style'/> NeuralChat
 
448
  with gr.Column(scale=1, min_width=50):
449
  send_btn = gr.Button(value="Send", visible=False, elem_id="btn-send-style")
450
 
451
+ with gr.Accordion("Parameters", open=False, visible=False, elem_id="btn-style") as parameter_row:
 
 
 
 
 
 
 
 
452
  temperature = gr.Slider(
453
  minimum=0.0,
454
  maximum=1.0,
 
456
  step=0.1,
457
  interactive=True,
458
  label="Temperature",
459
+ visible=False,
460
  )
461
  max_output_tokens = gr.Slider(
462
  minimum=0,
 
467
  label="Max output tokens",
468
  )
469
 
470
+
471
+ with gr.Row(visible=False, elem_id="btn-style") as button_row:
472
+ upvote_btn = gr.Button(value="👍 Upvote", interactive=False, visible=False, elem_id="btn-list-style")
473
+ downvote_btn = gr.Button(value="👎 Downvote", interactive=False, visible=False, elem_id="btn-list-style")
474
+ flag_btn = gr.Button(value="⚠️ Flag", interactive=False, visible=False, elem_id="btn-list-style")
475
+ # stop_btn = gr.Button(value="⏹️ Stop Generation", interactive=False)
476
+ regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False, elem_id="btn-list-style")
477
+ clear_btn = gr.Button(value="🗑️ Clear history", interactive=False, elem_id="btn-list-style")
478
+
479
+
480
  gr.Markdown(learn_more_markdown)
481
 
482
  # Register listeners
 
569
  # port = "mlp-dgx-01.sh.intel.com"
570
  concurrency_count = 10
571
  model_list_mode = "once"
572
+ share = False
573
  moderate = False
574
 
575
  set_global_vars(controller_url, moderate)