Skip to content

Commit

Permalink
Implement "*Is recording a voice message...*" for TTS oobabooga#303
Browse files Browse the repository at this point in the history
  • Loading branch information
oobabooga committed Mar 14, 2023
1 parent 94e309a commit 4c03ce8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions extensions/silero_tts/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def input_modifier(string):
if (shared.args.chat or shared.args.cai_chat) and len(shared.history['internal']) > 0:
shared.history['visible'][-1] = [shared.history['visible'][-1][0], shared.history['visible'][-1][1].replace('controls autoplay>','controls>')]

shared.processing_message = "*Is recording a voice message...*"
return string

def output_modifier(string):
Expand Down Expand Up @@ -119,6 +120,7 @@ def output_modifier(string):
if params['show_text']:
string += f'\n\n{original_string}'

shared.processing_message = "*Is typing...*"
return string

def bot_prefix_modifier(string):
Expand Down
10 changes: 6 additions & 4 deletions modules/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ def chatbot_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typical
else:
prompt = custom_generate_chat_prompt(text, max_new_tokens, name1, name2, context, chat_prompt_size)

# Yield *Is typing...*
if not regenerate:
yield shared.history['visible']+[[visible_text, '*Is typing...*']]
yield shared.history['visible']+[[visible_text, shared.processing_message]]

# Generate
reply = ''
Expand Down Expand Up @@ -168,7 +169,8 @@ def impersonate_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typ
prompt = generate_chat_prompt(text, max_new_tokens, name1, name2, context, chat_prompt_size, impersonate=True)

reply = ''
yield '*Is typing...*'
# Yield *Is typing...*
yield shared.processing_message
for i in range(chat_generation_attempts):
for reply in generate_reply(prompt+reply, max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, eos_token=eos_token, stopping_string=f"\n{name2}:"):
reply, next_character_found = extract_message_from_reply(prompt, reply, name1, name2, check, impersonate=True)
Expand All @@ -187,8 +189,8 @@ def regenerate_wrapper(text, max_new_tokens, do_sample, temperature, top_p, typi
else:
last_visible = shared.history['visible'].pop()
last_internal = shared.history['internal'].pop()

yield generate_chat_output(shared.history['visible']+[[last_visible[0], '*Is typing...*']], name1, name2, shared.character)
# Yield '*Is typing...*'
yield generate_chat_output(shared.history['visible']+[[last_visible[0], shared.processing_message]], name1, name2, shared.character)
for _history in chatbot_wrapper(last_internal[0], max_new_tokens, do_sample, temperature, top_p, typical_p, repetition_penalty, top_k, min_length, no_repeat_ngram_size, num_beams, penalty_alpha, length_penalty, early_stopping, name1, name2, context, check, chat_prompt_size, chat_generation_attempts, regenerate=True):
if shared.args.cai_chat:
shared.history['visible'][-1] = [last_visible[0], _history[-1][1]]
Expand Down
1 change: 1 addition & 0 deletions modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
history = {'internal': [], 'visible': []}
character = 'None'
stop_everything = False
processing_message = '*Is typing...*'

# UI elements (buttons, sliders, HTML, etc)
gradio = {}
Expand Down

0 comments on commit 4c03ce8

Please sign in to comment.