Jaward commited on
Commit
d4318d7
·
verified ·
1 Parent(s): a0024f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -163,12 +163,21 @@ def translate_speech(audio_file, target_language):
163
  print(f"File not found: {output_file}")
164
  return None
165
 
166
- DESCRIPTION = """ # <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>"""
 
 
 
 
 
 
 
 
 
167
 
168
- with gr.Blocks(css="style.css") as demo:
169
- gr.Markdown(DESCRIPTION)
170
 
171
- with gr.Tabs():
172
  with gr.TabItem("Voice Assistant"):
173
  select = gr.Dropdown([
174
  'Llama 3B Service',
@@ -193,14 +202,6 @@ with gr.Blocks(css="style.css") as demo:
193
  interactive=False,
194
  autoplay=True,
195
  elem_classes="audio")
196
- clear_button = gr.Button("Clear Conversation History")
197
-
198
- def clear_history():
199
- global conversation_history
200
- conversation_history = []
201
- return "Conversation history cleared."
202
-
203
- clear_button.click(fn=clear_history, inputs=[], outputs=gr.Textbox())
204
 
205
  gr.Interface(
206
  fn=respond,
@@ -228,5 +229,15 @@ with gr.Blocks(css="style.css") as demo:
228
  live=True
229
  )
230
 
 
 
 
 
 
 
 
 
 
 
231
  if __name__ == "__main__":
232
  demo.queue(max_size=200).launch()
 
163
  print(f"File not found: {output_file}")
164
  return None
165
 
166
+ def clear_history():
167
+ global conversation_history
168
+ conversation_history = []
169
+ return None, None
170
+
171
+ def update_description(tab):
172
+ if tab == "Voice Assistant":
173
+ return "# <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>"
174
+ elif tab == "Speech Translation":
175
+ return "# <center><b>Hear how you sound in another language</b></center>"
176
 
177
+ with gr.Blocks(css="style.css") as demo:
178
+ description = gr.Markdown("# <center><b>Hello, I am Optimus Prime your personal AI voice assistant</b></center>")
179
 
180
+ with gr.Tabs() as tabs:
181
  with gr.TabItem("Voice Assistant"):
182
  select = gr.Dropdown([
183
  'Llama 3B Service',
 
202
  interactive=False,
203
  autoplay=True,
204
  elem_classes="audio")
 
 
 
 
 
 
 
 
205
 
206
  gr.Interface(
207
  fn=respond,
 
229
  live=True
230
  )
231
 
232
+ clear_button = gr.Button("Clear")
233
+ clear_button.click(
234
+ fn=clear_history,
235
+ inputs=[],
236
+ outputs=[input, output],
237
+ api_name="clear"
238
+ )
239
+
240
+ tabs.change(fn=update_description, inputs=[tabs], outputs=[description])
241
+
242
  if __name__ == "__main__":
243
  demo.queue(max_size=200).launch()