Ath commited on
Commit
18a6160
·
verified ·
1 Parent(s): a306857

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -31,7 +31,9 @@ def chat_and_tts(user_input, history):
31
  # Send the user's input to the chat session
32
  response = chat_session.send_message(user_input)
33
  response_text = response.text
34
-
 
 
35
  # Eleven Labs text-to-speech request payload
36
  payload = {
37
  "text": response_text,
@@ -44,21 +46,24 @@ def chat_and_tts(user_input, history):
44
  "xi-api-key": eleven_labs_api_key,
45
  "Content-Type": "application/json"
46
  }
47
-
48
  # Make the request to Eleven Labs API
49
  tts_response = requests.post(eleven_labs_url, json=payload, headers=headers)
50
-
 
 
51
  # Check if the response is successful and save the audio content to a file
52
  if tts_response.status_code == 200:
53
  audio_path = 'response_audio.mp3'
54
  with open(audio_path, 'wb') as file:
55
  file.write(tts_response.content)
 
56
  else:
57
  audio_path = None
58
-
59
  # Update the chat history
60
  history.append((user_input, response_text))
61
-
62
  return history, history, audio_path
63
 
64
  # Create the Gradio UI
 
31
  # Send the user's input to the chat session
32
  response = chat_session.send_message(user_input)
33
  response_text = response.text
34
+
35
+ print("Response from chat session:", response_text) # Add this line to check the response
36
+
37
  # Eleven Labs text-to-speech request payload
38
  payload = {
39
  "text": response_text,
 
46
  "xi-api-key": eleven_labs_api_key,
47
  "Content-Type": "application/json"
48
  }
49
+
50
  # Make the request to Eleven Labs API
51
  tts_response = requests.post(eleven_labs_url, json=payload, headers=headers)
52
+
53
+ print("TTS API response status code:", tts_response.status_code) # Add this line to check the status code
54
+
55
  # Check if the response is successful and save the audio content to a file
56
  if tts_response.status_code == 200:
57
  audio_path = 'response_audio.mp3'
58
  with open(audio_path, 'wb') as file:
59
  file.write(tts_response.content)
60
+ print("Audio file saved successfully") # Add this line to check if audio file is saved
61
  else:
62
  audio_path = None
63
+
64
  # Update the chat history
65
  history.append((user_input, response_text))
66
+
67
  return history, history, audio_path
68
 
69
  # Create the Gradio UI