freddyaboulton HF staff commited on
Commit
7bd176a
1 Parent(s): 4a0236d
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -65,6 +65,7 @@ frame_rate = model.audio_encoder.config.frame_rate
65
 
66
 
67
  def generate_response(audio):
 
68
  gr.Info("Transcribing Audio", duration=5)
69
  question = client.automatic_speech_recognition(audio).text
70
 
@@ -73,11 +74,11 @@ def generate_response(audio):
73
  "is to answer with a cryptic addage or proverb such as "
74
  "'curiosity killed the cat' or 'The early bird gets the worm'."
75
  "Keep your answers short.")},
76
- {"role": "user", "content": f"Magic 8 ball, please tell me what to do about {question}"}]
77
 
78
  response = client.chat_completion(messages, max_tokens=64, seed=random.randint(1, 5000))
79
  response = response.choices[0].message.content
80
- return response
81
 
82
  @spaces.GPU
83
  def generate_base(answer):
@@ -106,7 +107,7 @@ def generate_base(answer):
106
 
107
  for new_audio in streamer:
108
  print(f"Sample of length: {round(new_audio.shape[0] / sampling_rate, 2)} seconds")
109
- yield gr.Textbox(value=answer, visible=True), numpy_to_mp3(new_audio, sampling_rate=sampling_rate)
110
 
111
  css=""".my-group {max-width: 600px !important; max-height: 600 !important;}
112
  .my-column {display: flex !important; justify-content: center !important; align-items: center !important};"""
@@ -128,6 +129,6 @@ with gr.Blocks() as block:
128
  with gr.Row():
129
  audio_in = gr.Audio(label="Speak you question", sources="microphone", type="filepath")
130
 
131
- audio_in.stop_recording(generate_response, audio_in, [state]).then(fn=generate_base, inputs=state, outputs=[answer, audio_out])
132
 
133
  block.launch()
 
65
 
66
 
67
  def generate_response(audio):
68
+ yield None, None
69
  gr.Info("Transcribing Audio", duration=5)
70
  question = client.automatic_speech_recognition(audio).text
71
 
 
74
  "is to answer with a cryptic addage or proverb such as "
75
  "'curiosity killed the cat' or 'The early bird gets the worm'."
76
  "Keep your answers short.")},
77
+ {"role": "user", "content": f"Please tell me what to do about {question}"}]
78
 
79
  response = client.chat_completion(messages, max_tokens=64, seed=random.randint(1, 5000))
80
  response = response.choices[0].message.content
81
+ yield response, None
82
 
83
  @spaces.GPU
84
  def generate_base(answer):
 
107
 
108
  for new_audio in streamer:
109
  print(f"Sample of length: {round(new_audio.shape[0] / sampling_rate, 2)} seconds")
110
+ yield answer, numpy_to_mp3(new_audio, sampling_rate=sampling_rate)
111
 
112
  css=""".my-group {max-width: 600px !important; max-height: 600 !important;}
113
  .my-column {display: flex !important; justify-content: center !important; align-items: center !important};"""
 
129
  with gr.Row():
130
  audio_in = gr.Audio(label="Speak you question", sources="microphone", type="filepath")
131
 
132
+ audio_in.stop_recording(generate_response, audio_in, state).then(fn=generate_base, inputs=state, outputs=[answer, audio_out])
133
 
134
  block.launch()