broadfield commited on
Commit
837d0bc
·
verified ·
1 Parent(s): dc53cc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -12,7 +12,6 @@ def format_prompt(message, history):
12
  prompt=""
13
  if history:
14
  prompt = "<s>"
15
-
16
  for user_prompt, bot_response in history:
17
  #print (bot_response)
18
  prompt += f"[INST] {user_prompt} [/INST]"
@@ -34,21 +33,15 @@ def generate(prompt,history):
34
  do_sample=True,
35
  seed=seed,
36
  )
37
-
38
  formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
39
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
40
  output = ""
41
  buf = ""
42
- #out = history.append((prompt,""))
43
  for response in stream:
44
  output += response.token.text
45
  yield [(prompt,output)], ""
46
  yield [(prompt,output)], output
47
- def tts(inp,voice,length,noise,width,sen_pause):
48
- #print(inp)
49
- #print(type(inp))
50
- inp=inp.strip("</s>")
51
- yield from pp.stream_tts(inp,voice,length,noise,width,sen_pause)
52
  def load_mod(model):
53
  yield f"Loading: {model}"
54
  pp.load_mod(model)
@@ -56,14 +49,12 @@ def load_mod(model):
56
 
57
  with gr.Blocks() as iface:
58
  aud=gr.Audio(streaming=True,autoplay=True)
59
- #chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
60
- chatbot=gr.Chatbot()
61
  prompt = gr.Textbox()
62
- with gr.Group():
63
- with gr.Row():
64
- submit_b = gr.Button()
65
- stop_b = gr.Button("Stop")
66
- clear = gr.ClearButton([chatbot])
67
  with gr.Accordion("Voice Controls",open=False):
68
  msg = gr.HTML("""""")
69
  names=gr.Dropdown(label="Voice", choices=pp.key_list,value="en_US-joe-medium")
@@ -76,9 +67,9 @@ with gr.Blocks() as iface:
76
  stt=gr.Textbox(visible=True)
77
 
78
  iface.load(load_mod,names,msg)
79
- names.change(load_mod,names,msg)
80
  sub_b = submit_b.click(generate, [prompt,chatbot],[chatbot,stt])
81
- #sub_e = prompt.submit(generate, [prompt, chatbot], [chatbot,stt])
82
- stt.change(pp.stream_tts,[stt,names,length,noise,width,sen_pause],aud)
83
- stop_b.click(None,None,None, cancels=[sub_b])
 
84
  iface.queue(default_concurrency_limit=10).launch()
 
12
  prompt=""
13
  if history:
14
  prompt = "<s>"
 
15
  for user_prompt, bot_response in history:
16
  #print (bot_response)
17
  prompt += f"[INST] {user_prompt} [/INST]"
 
33
  do_sample=True,
34
  seed=seed,
35
  )
 
36
  formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
37
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
38
  output = ""
39
  buf = ""
 
40
  for response in stream:
41
  output += response.token.text
42
  yield [(prompt,output)], ""
43
  yield [(prompt,output)], output
44
+
 
 
 
 
45
  def load_mod(model):
46
  yield f"Loading: {model}"
47
  pp.load_mod(model)
 
49
 
50
  with gr.Blocks() as iface:
51
  aud=gr.Audio(streaming=True,autoplay=True)
52
+ chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, layout="panel")
 
53
  prompt = gr.Textbox()
54
+ with gr.Row():
55
+ submit_b = gr.Button()
56
+ stop_b = gr.Button("Stop")
57
+ clear = gr.ClearButton([chatbot,prompt,aud])
 
58
  with gr.Accordion("Voice Controls",open=False):
59
  msg = gr.HTML("""""")
60
  names=gr.Dropdown(label="Voice", choices=pp.key_list,value="en_US-joe-medium")
 
67
  stt=gr.Textbox(visible=True)
68
 
69
  iface.load(load_mod,names,msg)
 
70
  sub_b = submit_b.click(generate, [prompt,chatbot],[chatbot,stt])
71
+ sub_e = prompt.submit(generate, [prompt, chatbot], [chatbot,stt])
72
+ aud_stream = stt.change(pp.stream_tts,[stt,names,length,noise,width,sen_pause],aud)
73
+ names_change=names.change(load_mod,names,msg)
74
+ stop_b.click(None,None,None, cancels=[sub_b,sub_e,aud_stream,names_change])
75
  iface.queue(default_concurrency_limit=10).launch()