Baghdad99 commited on
Commit
cd0ec84
·
1 Parent(s): e2984ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -10,7 +10,12 @@ pipe = pipeline(
10
  model="DrishtiSharma/whisper-large-v2-hausa",
11
  tokenizer="DrishtiSharma/whisper-large-v2-hausa"
12
  )
13
- translator = pipeline("text2text-generation", model="Baghdad99/saad-hausa-text-to-english-text")
 
 
 
 
 
14
  tts = pipeline("text-to-speech", model="Baghdad99/english_voice_tts")
15
 
16
  # Define the function to translate speech
@@ -51,9 +56,16 @@ def translate_speech(audio_file):
51
  print("The translated text does not contain 'generated_token_ids'")
52
  return
53
 
 
 
 
 
 
 
 
 
54
  # Use the text-to-speech pipeline to synthesize the translated text
55
  synthesised_speech = tts(translated_text_str)
56
- print(f"Synthesised speech: {synthesised_speech}") # Print the synthesised speech to see what it contains
57
 
58
  # Check if the synthesised speech contains 'audio'
59
  if 'audio' in synthesised_speech:
@@ -71,7 +83,6 @@ def translate_speech(audio_file):
71
  return 16000, synthesised_speech
72
 
73
 
74
-
75
  # Define the Gradio interface
76
  iface = gr.Interface(
77
  fn=translate_speech,
 
10
  model="DrishtiSharma/whisper-large-v2-hausa",
11
  tokenizer="DrishtiSharma/whisper-large-v2-hausa"
12
  )
13
+
14
+ # Load the new translation model and tokenizer
15
+ model_name = 'jbochi/madlad400-3b-mt'
16
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
17
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
18
+
19
  tts = pipeline("text-to-speech", model="Baghdad99/english_voice_tts")
20
 
21
  # Define the function to translate speech
 
56
  print("The translated text does not contain 'generated_token_ids'")
57
  return
58
 
59
+ # Use the new translation model to translate the transcription
60
+ text = "translate Hausa to English: " + transcription
61
+ input_ids = tokenizer.encode(text, return_tensors="pt")
62
+ outputs = model.generate(input_ids=input_ids)
63
+
64
+ # Decode the tokens into text
65
+ translated_text_str = tokenizer.decode(outputs[0], skip_special_tokens=True)
66
+
67
  # Use the text-to-speech pipeline to synthesize the translated text
68
  synthesised_speech = tts(translated_text_str)
 
69
 
70
  # Check if the synthesised speech contains 'audio'
71
  if 'audio' in synthesised_speech:
 
83
  return 16000, synthesised_speech
84
 
85
 
 
86
  # Define the Gradio interface
87
  iface = gr.Interface(
88
  fn=translate_speech,