freddyaboulton HF staff commited on
Commit
84a59c3
1 Parent(s): cc76c21
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -109,29 +109,32 @@ def response(audio: tuple[int, np.ndarray], lepton_conversation: list[dict],
109
  else:
110
  yield AdditionalOutputs(lepton_conversation, gradio_conversation)
111
 
 
112
  def set_api_key(api_key):
113
  if not api_key:
114
  raise gr.Error("Please enter a valid API key.")
115
  client = create_client(api_key)
116
- return client
 
117
 
118
 
119
  with gr.Blocks() as demo:
120
  with gr.Group():
121
  with gr.Row():
122
  chatbot = gr.Chatbot(label="Conversation", type="messages")
123
- with gr.Row():
124
- with gr.Column():
125
  format_dropdown = gr.Dropdown(choices=["mp3", "opus"], value="mp3", label="Output Audio Format")
126
  api_key_input = gr.Textbox(type="password", label="Enter your Lepton API Key")
127
- with gr.Column():
 
128
  audio = WebRTC(modality="audio", mode="send-receive",
129
- label="Audio Stream")
130
-
131
  client_state = gr.State(None)
132
  lepton_conversation = gr.State([])
133
 
134
- api_key_input.submit(set_api_key, inputs=[api_key_input], outputs=[client_state])
135
 
136
  audio.stream(
137
  ReplyOnPause(response),
 
109
  else:
110
  yield AdditionalOutputs(lepton_conversation, gradio_conversation)
111
 
112
+
113
  def set_api_key(api_key):
114
  if not api_key:
115
  raise gr.Error("Please enter a valid API key.")
116
  client = create_client(api_key)
117
+ gr.Info("Set API Key Successfully")
118
+ return client, gr.skip()
119
 
120
 
121
  with gr.Blocks() as demo:
122
  with gr.Group():
123
  with gr.Row():
124
  chatbot = gr.Chatbot(label="Conversation", type="messages")
125
+ with gr.Row(equal_height=True):
126
+ with gr.Column(scale=1):
127
  format_dropdown = gr.Dropdown(choices=["mp3", "opus"], value="mp3", label="Output Audio Format")
128
  api_key_input = gr.Textbox(type="password", label="Enter your Lepton API Key")
129
+ set_key_button = gr.Button("Set API Key", variant="primary")
130
+ with gr.Column(scale=3):
131
  audio = WebRTC(modality="audio", mode="send-receive",
132
+ label="Audio Stream")
133
+
134
  client_state = gr.State(None)
135
  lepton_conversation = gr.State([])
136
 
137
+ set_key_button.click(set_api_key, inputs=[api_key_input], outputs=[client_state, set_key_button])
138
 
139
  audio.stream(
140
  ReplyOnPause(response),