UI: add "Maximum UI updates/second" parameter

This commit is contained in:
oobabooga 2023-12-24 09:17:40 -08:00
parent 1b8b61b928
commit 8c60495878
4 changed files with 10 additions and 3 deletions

View file

@ -77,6 +77,10 @@ def _generate_reply(question, state, stopping_strings=None, is_chat=False, escap
state = copy.deepcopy(state)
state['stream'] = True
min_update_interval = 0
if state.get('max_updates_second', 0) > 0:
min_update_interval = 1 / state['max_updates_second']
# Generate
for reply in generate_func(question, original_question, seed, state, stopping_strings, is_chat=is_chat):
reply, stop_found = apply_stopping_strings(reply, all_stop_strings)
@ -94,10 +98,9 @@ def _generate_reply(question, state, stopping_strings=None, is_chat=False, escap
last_update = time.time()
yield reply
# Limit updates to 24 or 5 per second to avoid lag in the Gradio UI
# Limit updates to avoid lag in the Gradio UI
# API updates are not limited
else:
min_update_interval = 0 if not for_ui else 0.2 if (shared.args.listen or shared.args.share) else 0.0417
if cur_time - last_update > min_update_interval:
last_update = cur_time
yield reply