uasername commited on
Commit
df2f5c8
·
verified ·
1 Parent(s): 953e326

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +13 -8
Gradio_UI.py CHANGED
@@ -194,16 +194,21 @@ def stream_to_gradio(
194
  content={"path": final_answer.to_string(), "mime_type": "image/png"},
195
  )
196
  elif isinstance(final_answer, AgentAudio):
197
- # Assuming your AgentAudio object stores the raw MP3 bytes in an attribute called "value"
198
- audio_bytes = final_answer.value
199
- # Convert MP3 bytes to a numpy array using our helper function
200
- audio_np = mp3_bytes_to_numpy(audio_bytes)
201
- print("DEBUG audio_np type:", type(audio_np), "shape:", audio_np.shape)
 
 
 
 
 
 
202
  yield gr.ChatMessage(
203
  role="assistant",
204
- content={"path": final_answer.to_string(), "mime_type": "audio/mpeg"},
205
  )
206
- print("DEBUG AgentAudio attributes:", vars(final_answer))
207
 
208
  else:
209
  yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
@@ -353,7 +358,7 @@ class GradioUI:
353
  )
354
 
355
  # NEW: Add a dedicated audio player component below the chatbot.
356
- audio_player = gr.Audio(label="Audio Pronunciation", type="numpy")
357
 
358
  if self.file_upload_folder is not None:
359
  upload_file = gr.File(label="Upload a file")
 
194
  content={"path": final_answer.to_string(), "mime_type": "image/png"},
195
  )
196
  elif isinstance(final_answer, AgentAudio):
197
+ # Get the file path from the AgentAudio object (assuming it returns a string path)
198
+ local_path = final_answer.to_string() # e.g. "/tmp/response.mp3"
199
+
200
+ # Define a public folder to serve audio files
201
+ public_folder = "public_audio"
202
+ os.makedirs(public_folder, exist_ok=True)
203
+
204
+ # Copy the file from /tmp to the public folder
205
+ public_path = os.path.join(public_folder, os.path.basename(local_path))
206
+ shutil.copy(local_path, public_path)
207
+
208
  yield gr.ChatMessage(
209
  role="assistant",
210
+ content={"path": public_path, "mime_type": "audio/mpeg"},
211
  )
 
212
 
213
  else:
214
  yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
 
358
  )
359
 
360
  # NEW: Add a dedicated audio player component below the chatbot.
361
+ audio_player = gr.Audio(label="Audio Pronunciation", type="filepath")
362
 
363
  if self.file_upload_folder is not None:
364
  upload_file = gr.File(label="Upload a file")