AnwenHu commited on
Commit
e7bafa9
1 Parent(s): 8fe1594

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -5,7 +5,6 @@ import os
5
  import time
6
 
7
  import gradio as gr
8
- print(gr.__version__)
9
  import requests
10
 
11
  from mplug_docowl.conversation import (default_conversation, conv_templates,
@@ -21,14 +20,13 @@ model_dir = snapshot_download('mPLUG/DocOwl1.5-Omni', cache_dir='./')
21
 
22
  print(os.listdir('./'))
23
 
24
-
25
  logger = build_logger("gradio_web_server_local", "gradio_web_server_local.log")
26
 
27
  headers = {"User-Agent": "mPLUG-DocOwl1.5 Client"}
28
 
29
- no_change_btn = gr.Button.update()
30
- enable_btn = gr.Button.update(interactive=True)
31
- disable_btn = gr.Button.update(interactive=False)
32
 
33
  def get_conv_log_filename():
34
  t = datetime.datetime.now()
@@ -160,7 +158,6 @@ def http_bot(state, temperature, top_p, max_new_tokens, request: gr.Request):
160
  "stop": state.sep if state.sep_style in [SeparatorStyle.SINGLE, SeparatorStyle.MPT] else state.sep2,
161
  "images": f'List of {len(state.get_images())} images: {all_image_hash}',
162
  }
163
-
164
  logger.info(f"==== request ====\n{pload}")
165
 
166
  pload['images'] = state.get_images()
@@ -174,10 +171,8 @@ def http_bot(state, temperature, top_p, max_new_tokens, request: gr.Request):
174
  # headers=headers, json=pload, stream=True, timeout=10)
175
  # for chunk in response.iter_lines(decode_unicode=False, delimiter=b"\0"):
176
  response = model.generate_stream_gate(pload)
177
- # print('response:', response)
178
  for chunk in response:
179
  if chunk:
180
- print('chunk:', chunk.decode())
181
  data = json.loads(chunk.decode())
182
  if data["error_code"] == 0:
183
  output = data["text"][len(prompt):].strip()
@@ -271,7 +266,7 @@ block_css = """
271
 
272
  def build_demo(embed_mode):
273
  textbox = gr.Textbox(show_label=False, placeholder="Enter text and press ENTER", container=False)
274
- with gr.Blocks(title="mPLUG-DocOwl1.5", theme=gr.themes.Default(), css=block_css) as demo:
275
  state = gr.State()
276
 
277
  if not embed_mode:
@@ -297,7 +292,7 @@ def build_demo(embed_mode):
297
  ], inputs=[imagebox, textbox])
298
 
299
  with gr.Accordion("Parameters", open=True) as parameter_row:
300
- temperature = gr.Slider(minimum=0.0, maximum=1.0, value=1.0, step=0.1, interactive=True, label="Temperature",)
301
  top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.7, step=0.1, interactive=True, label="Top P",)
302
  max_output_tokens = gr.Slider(minimum=0, maximum=1024, value=512, step=64, interactive=True, label="Max output tokens",)
303
 
@@ -327,26 +322,30 @@ def build_demo(embed_mode):
327
  upvote_last_response,
328
  state,
329
  [textbox, upvote_btn, downvote_btn, flag_btn],
330
- queue=False
 
331
  )
332
  downvote_btn.click(
333
  downvote_last_response,
334
  state,
335
  [textbox, upvote_btn, downvote_btn, flag_btn],
336
- queue=False
 
337
  )
338
  flag_btn.click(
339
  flag_last_response,
340
  state,
341
  [textbox, upvote_btn, downvote_btn, flag_btn],
342
- queue=False
 
343
  )
344
 
345
  regenerate_btn.click(
346
  regenerate,
347
  [state, image_process_mode],
348
  [state, chatbot, textbox, imagebox] + btn_list,
349
- queue=False
 
350
  ).then(
351
  http_bot,
352
  [state, temperature, top_p, max_output_tokens],
@@ -357,7 +356,8 @@ def build_demo(embed_mode):
357
  clear_history,
358
  None,
359
  [state, chatbot, textbox, imagebox] + btn_list,
360
- queue=False
 
361
  )
362
 
363
  textbox.submit(
@@ -375,7 +375,8 @@ def build_demo(embed_mode):
375
  add_text,
376
  [state, textbox, imagebox, image_process_mode],
377
  [state, chatbot, textbox, imagebox] + btn_list,
378
- queue=False
 
379
  ).then(
380
  http_bot,
381
  [state, temperature, top_p, max_output_tokens],
@@ -386,7 +387,7 @@ def build_demo(embed_mode):
386
  load_demo,
387
  [url_params],
388
  state,
389
- _js=get_window_url_params,
390
  queue=False
391
  )
392
 
@@ -420,7 +421,6 @@ if __name__ == "__main__":
420
  logger.info(args)
421
  demo = build_demo(args.embed)
422
  demo.queue(
423
- concurrency_count=args.concurrency_count,
424
  api_open=False
425
  ).launch(
426
  server_name=args.host,
 
5
  import time
6
 
7
  import gradio as gr
 
8
  import requests
9
 
10
  from mplug_docowl.conversation import (default_conversation, conv_templates,
 
20
 
21
  print(os.listdir('./'))
22
 
 
23
  logger = build_logger("gradio_web_server_local", "gradio_web_server_local.log")
24
 
25
  headers = {"User-Agent": "mPLUG-DocOwl1.5 Client"}
26
 
27
+ no_change_btn = gr.Button()
28
+ enable_btn = gr.Button(interactive=True)
29
+ disable_btn = gr.Button(interactive=False)
30
 
31
  def get_conv_log_filename():
32
  t = datetime.datetime.now()
 
158
  "stop": state.sep if state.sep_style in [SeparatorStyle.SINGLE, SeparatorStyle.MPT] else state.sep2,
159
  "images": f'List of {len(state.get_images())} images: {all_image_hash}',
160
  }
 
161
  logger.info(f"==== request ====\n{pload}")
162
 
163
  pload['images'] = state.get_images()
 
171
  # headers=headers, json=pload, stream=True, timeout=10)
172
  # for chunk in response.iter_lines(decode_unicode=False, delimiter=b"\0"):
173
  response = model.generate_stream_gate(pload)
 
174
  for chunk in response:
175
  if chunk:
 
176
  data = json.loads(chunk.decode())
177
  if data["error_code"] == 0:
178
  output = data["text"][len(prompt):].strip()
 
266
 
267
  def build_demo(embed_mode):
268
  textbox = gr.Textbox(show_label=False, placeholder="Enter text and press ENTER", container=False)
269
+ with gr.Blocks(title="mPLUG-Owl2", theme=gr.themes.Default(), css=block_css) as demo:
270
  state = gr.State()
271
 
272
  if not embed_mode:
 
292
  ], inputs=[imagebox, textbox])
293
 
294
  with gr.Accordion("Parameters", open=True) as parameter_row:
295
+ temperature = gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.1, interactive=True, label="Temperature",)
296
  top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.7, step=0.1, interactive=True, label="Top P",)
297
  max_output_tokens = gr.Slider(minimum=0, maximum=1024, value=512, step=64, interactive=True, label="Max output tokens",)
298
 
 
322
  upvote_last_response,
323
  state,
324
  [textbox, upvote_btn, downvote_btn, flag_btn],
325
+ queue=False,
326
+ concurrency_limit=10,
327
  )
328
  downvote_btn.click(
329
  downvote_last_response,
330
  state,
331
  [textbox, upvote_btn, downvote_btn, flag_btn],
332
+ queue=False,
333
+ concurrency_limit=10,
334
  )
335
  flag_btn.click(
336
  flag_last_response,
337
  state,
338
  [textbox, upvote_btn, downvote_btn, flag_btn],
339
+ queue=False,
340
+ concurrency_limit=10,
341
  )
342
 
343
  regenerate_btn.click(
344
  regenerate,
345
  [state, image_process_mode],
346
  [state, chatbot, textbox, imagebox] + btn_list,
347
+ queue=False,
348
+ concurrency_limit=10,
349
  ).then(
350
  http_bot,
351
  [state, temperature, top_p, max_output_tokens],
 
356
  clear_history,
357
  None,
358
  [state, chatbot, textbox, imagebox] + btn_list,
359
+ queue=False,
360
+ concurrency_limit=10,
361
  )
362
 
363
  textbox.submit(
 
375
  add_text,
376
  [state, textbox, imagebox, image_process_mode],
377
  [state, chatbot, textbox, imagebox] + btn_list,
378
+ queue=False,
379
+ concurrency_limit=10,
380
  ).then(
381
  http_bot,
382
  [state, temperature, top_p, max_output_tokens],
 
387
  load_demo,
388
  [url_params],
389
  state,
390
+ js=get_window_url_params,
391
  queue=False
392
  )
393
 
 
421
  logger.info(args)
422
  demo = build_demo(args.embed)
423
  demo.queue(
 
424
  api_open=False
425
  ).launch(
426
  server_name=args.host,