Tonic commited on
Commit
5dc0043
·
1 Parent(s): db269a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -139,11 +139,29 @@ def convert_text_to_speech(input_text, source_language, target_language):
139
  api_name="/run" # API name
140
  )
141
 
142
- # Check if result contains files and select the first one
143
  if isinstance(result, list) and len(result) > 1:
144
- # Select the first audio file from the result
145
- original_audio_file = result[1] # Assuming the first element is the audio file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
 
 
 
147
  # Iterate over the result to find the last text item
148
  translated_text = ""
149
  for item in result:
@@ -365,7 +383,6 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
365
  markdown_output = ""
366
  image_text = ""
367
  translated_text = ""
368
- audio_file_path = ""
369
  audio_output = ""
370
  # Debugging print statement
371
  print(f"Image Input Type: {type(image_input)}, Audio Input Type: {type(audio_input)}")
@@ -416,7 +433,7 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
416
 
417
  # Convert translated text to speech and get both audio file and text
418
  target_language = "English" # Set the target language for the speech
419
- audio_file_path, translated_text = convert_text_to_speech(final_response, target_language, input_language)
420
 
421
  # Evaluate hallucination
422
  hallucination_label = evaluate_hallucination(final_response, summary)
 
139
  api_name="/run" # API name
140
  )
141
 
142
+ # Check if result contains files
143
  if isinstance(result, list) and len(result) > 1:
144
+ downloaded_files = []
145
+ for file_path in result[1:]:
146
+ if os.path.isfile(file_path):
147
+ # Download the file
148
+ downloaded_files.append(file_path)
149
+ else:
150
+ print(f"Path is not a file: {file_path}")
151
+
152
+ if downloaded_files:
153
+ # Process only the first file
154
+ original_audio_file = downloaded_files[0]
155
+ new_file_name = f"audio_output_{uuid.uuid4()}.wav"
156
+ new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)
157
+ os.rename(original_audio_file, new_file_path)
158
+ return new_file_path
159
+ else:
160
+ return "No valid audio files were downloaded."
161
 
162
+ else:
163
+ return "No audio files received from the API."
164
+
165
  # Iterate over the result to find the last text item
166
  translated_text = ""
167
  for item in result:
 
383
  markdown_output = ""
384
  image_text = ""
385
  translated_text = ""
 
386
  audio_output = ""
387
  # Debugging print statement
388
  print(f"Image Input Type: {type(image_input)}, Audio Input Type: {type(audio_input)}")
 
433
 
434
  # Convert translated text to speech and get both audio file and text
435
  target_language = "English" # Set the target language for the speech
436
+ audio_output, translated_text = convert_text_to_speech(final_response, target_language, input_language)
437
 
438
  # Evaluate hallucination
439
  hallucination_label = evaluate_hallucination(final_response, summary)