dindizz commited on
Commit
9affff3
·
verified ·
1 Parent(s): 9009a17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -14,6 +14,8 @@ recognizer = sr.Recognizer()
14
 
15
  # Function to convert speech to text
16
  def speech_to_text(audio):
 
 
17
  try:
18
  with sr.AudioFile(audio) as source:
19
  recognizer.adjust_for_ambient_noise(source)
@@ -48,7 +50,7 @@ def text_to_speech(response):
48
  # Gradio function that integrates all components
49
  def chatbot(audio):
50
  user_input = speech_to_text(audio)
51
- if "Sorry" in user_input:
52
  return user_input, None
53
  response = get_gpt_response(user_input)
54
  if response:
@@ -61,7 +63,9 @@ iface = gr.Interface(
61
  fn=chatbot,
62
  inputs=gr.Audio(type="filepath"),
63
  outputs=[gr.Textbox(label="Transcription"), gr.Audio(label="AI Response")],
64
- live=True
 
 
65
  )
66
 
67
  # Launch the Gradio interface
 
14
 
15
  # Function to convert speech to text
16
  def speech_to_text(audio):
17
+ if not audio: # Check if audio is None or empty
18
+ return "No audio input detected. Please provide a valid audio file."
19
  try:
20
  with sr.AudioFile(audio) as source:
21
  recognizer.adjust_for_ambient_noise(source)
 
50
  # Gradio function that integrates all components
51
  def chatbot(audio):
52
  user_input = speech_to_text(audio)
53
+ if "Sorry" in user_input or "No audio input" in user_input:
54
  return user_input, None
55
  response = get_gpt_response(user_input)
56
  if response:
 
63
  fn=chatbot,
64
  inputs=gr.Audio(type="filepath"),
65
  outputs=[gr.Textbox(label="Transcription"), gr.Audio(label="AI Response")],
66
+ live=True,
67
+ title="Conversational Assistant",
68
+ description="Upload an audio file or record your voice to get a response from the AI."
69
  )
70
 
71
  # Launch the Gradio interface