KingNish commited on
Commit
be5bdad
·
verified ·
1 Parent(s): 6fb5a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -135,9 +135,9 @@ def transcribe(audio_path):
135
  def model(text, web_search):
136
  if web_search is True:
137
  """Performs a web search, feeds the results to a language model, and returns the answer."""
138
- web_results = search(input)
139
  web2 = ' '.join([f"Link: {res['link']}\nText: {res['text']}\n\n" for res in web_results])
140
- formatted_prompt = system_instructions1 + input + "[WEB]" + str(web2) + "[ANSWER]"
141
  stream = client1.text_generation(formatted_prompt, max_new_tokens=512, stream=True, details=True, return_full_text=False)
142
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
143
  else:
@@ -145,9 +145,9 @@ def model(text, web_search):
145
  stream = client1.text_generation(formatted_prompt, max_new_tokens=512, stream=True, details=True, return_full_text=False)
146
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
147
 
148
- async def respond(audio):
149
  user = transcribe(audio)
150
- reply = model(user)
151
  communicate = edge_tts.Communicate(reply)
152
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
153
  tmp_path = tmp_file.name
@@ -158,7 +158,6 @@ with gr.Blocks() as demo:
158
  with gr.Row():
159
  web_search = gr.Checkbox(label="Web Search", value=False)
160
  input = gr.Audio(label="Voice Chat (BETA)", sources="microphone", type="filepath", waveform_options=False)
161
- with gr.Row():
162
  output = gr.Audio(label="JARVIS", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
163
  gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
164
 
 
135
  def model(text, web_search):
136
  if web_search is True:
137
  """Performs a web search, feeds the results to a language model, and returns the answer."""
138
+ web_results = search(text)
139
  web2 = ' '.join([f"Link: {res['link']}\nText: {res['text']}\n\n" for res in web_results])
140
+ formatted_prompt = system_instructions1 + text + "[WEB]" + str(web2) + "[ANSWER]"
141
  stream = client1.text_generation(formatted_prompt, max_new_tokens=512, stream=True, details=True, return_full_text=False)
142
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
143
  else:
 
145
  stream = client1.text_generation(formatted_prompt, max_new_tokens=512, stream=True, details=True, return_full_text=False)
146
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
147
 
148
+ async def respond(audio, web_search):
149
  user = transcribe(audio)
150
+ reply = model(user, web_search)
151
  communicate = edge_tts.Communicate(reply)
152
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
153
  tmp_path = tmp_file.name
 
158
  with gr.Row():
159
  web_search = gr.Checkbox(label="Web Search", value=False)
160
  input = gr.Audio(label="Voice Chat (BETA)", sources="microphone", type="filepath", waveform_options=False)
 
161
  output = gr.Audio(label="JARVIS", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
162
  gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
163