uasername commited on
Commit
147a1aa
·
verified ·
1 Parent(s): e8e8c34

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +10 -5
Gradio_UI.py CHANGED
@@ -299,13 +299,18 @@ class GradioUI:
299
 
300
  # NEW: Add a helper function to extract audio file path from stored messages
301
  def extract_audio(messages):
 
302
  if not messages:
303
  return None
304
- last_message = messages[-1]
305
- if isinstance(last_message.content, dict):
306
- mime = last_message.content.get("mime_type", "")
307
- if mime.startswith("audio"):
308
- return last_message.content.get("path")
 
 
 
 
309
  return None
310
 
311
  with gr.Blocks(fill_height=True) as demo:
 
299
 
300
  # NEW: Add a helper function to extract audio file path from stored messages
301
  def extract_audio(messages):
302
+ # Iterate backwards over messages until we find one with audio content.
303
  if not messages:
304
  return None
305
+ for msg in reversed(messages):
306
+ # Only process messages that are objects with a "content" attribute.
307
+ if not hasattr(msg, "content"):
308
+ continue
309
+ # If the content is a dict and contains an audio mime type, return the file path.
310
+ if isinstance(msg.content, dict):
311
+ mime = msg.content.get("mime_type", "")
312
+ if mime.startswith("audio"):
313
+ return msg.content.get("path")
314
  return None
315
 
316
  with gr.Blocks(fill_height=True) as demo: