Baghdad99 commited on
Commit
2de6d50
1 Parent(s): 88de73c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -0
app.py CHANGED
@@ -23,17 +23,20 @@ def translate_speech(audio_input):
23
  # Check if the output contains 'text'
24
  if 'text' in output:
25
  transcription = output["text"]
 
26
  else:
27
  print("The output does not contain 'text'")
28
  return
29
 
30
  # Use the translation pipeline to translate the transcription
31
  translated_text = translator(transcription, return_tensors="pt")
 
32
 
33
  # Check if the translated text contains 'generated_token_ids'
34
  if 'generated_token_ids' in translated_text[0]:
35
  # Decode the tokens into text
36
  translated_text_str = translator.tokenizer.decode(translated_text[0]['generated_token_ids'])
 
37
  else:
38
  print("The translated text does not contain 'generated_token_ids'")
39
  return
 
23
  # Check if the output contains 'text'
24
  if 'text' in output:
25
  transcription = output["text"]
26
+ print(f"Transcription: {transcription}") # Print the transcription
27
  else:
28
  print("The output does not contain 'text'")
29
  return
30
 
31
  # Use the translation pipeline to translate the transcription
32
  translated_text = translator(transcription, return_tensors="pt")
33
+ print(f"Translated text: {translated_text}") # Print the translated text
34
 
35
  # Check if the translated text contains 'generated_token_ids'
36
  if 'generated_token_ids' in translated_text[0]:
37
  # Decode the tokens into text
38
  translated_text_str = translator.tokenizer.decode(translated_text[0]['generated_token_ids'])
39
+ print(f"Translated text string: {translated_text_str}") # Print the translated text string
40
  else:
41
  print("The translated text does not contain 'generated_token_ids'")
42
  return