freddyaboulton HF staff commited on
Commit
4a0236d
1 Parent(s): 5075bfa
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -68,21 +68,21 @@ def generate_response(audio):
68
  gr.Info("Transcribing Audio", duration=5)
69
  question = client.automatic_speech_recognition(audio).text
70
 
71
- messages = [{"role": "sytem", "content": ("You are a magic 8 ball."
72
  "Someone will present to you a situation or question and your job "
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
- {"role": "user", "content": f"Please tell me what to do about {question}"}]
 
76
 
77
- response = client.chat_completion(messages, max_tokens=128, seed=random.randint(1, 5000))
78
  response = response.choices[0].message.content
79
- return response, gr.Textbox(visible=True)
80
-
81
 
82
  @spaces.GPU
83
  def generate_base(answer):
84
 
85
- play_steps_in_s = 1.0
86
  play_steps = int(frame_rate * play_steps_in_s)
87
 
88
  description = "Jenny speaks at an average pace with a calm delivery in a very confined sounding environment with clear audio quality."
@@ -121,13 +121,13 @@ with gr.Blocks() as block:
121
  )
122
  with gr.Group():
123
  with gr.Row():
124
- audio_out = gr.Audio(visible=False, streaming=True, autoplay=True)
125
- answer = gr.Textbox(visible=False, label="Answer")
126
  state = gr.State()
127
 
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, answer]).then(fn=generate_base, inputs=state, outputs=[answer, audio_out])
132
 
133
  block.launch()
 
68
  gr.Info("Transcribing Audio", duration=5)
69
  question = client.automatic_speech_recognition(audio).text
70
 
71
+ messages = [{"role": "system", "content": ("You are a magic 8 ball."
72
  "Someone will present to you a situation or question and your job "
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):
84
 
85
+ play_steps_in_s = 2.0
86
  play_steps = int(frame_rate * play_steps_in_s)
87
 
88
  description = "Jenny speaks at an average pace with a calm delivery in a very confined sounding environment with clear audio quality."
 
121
  )
122
  with gr.Group():
123
  with gr.Row():
124
+ audio_out = gr.Audio(visible=True, streaming=True, autoplay=True)
125
+ answer = gr.Textbox(visible=True, label="Answer")
126
  state = gr.State()
127
 
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()