Baghdad99 commited on
Commit
cca146f
1 Parent(s): 12baf3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -5,24 +5,28 @@ from pydub import AudioSegment
5
  import io
6
 
7
  # Define the Hugging Face Inference API URLs and headers
 
8
  TTS_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/english_voice_tts"
9
  TRANSLATION_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/saad-hausa-text-to-english-text"
10
  headers = {"Authorization": "Bearer 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"}
11
 
12
- # Load the Gradio model for speech recognition
13
- asr_model = gr.load("models/Baghdad99/saad-speech-recognition-hausa-audio-to-text")
14
-
15
  # Define the function to query the Hugging Face Inference API
16
- def query(api_url, payload):
17
- response = requests.post(api_url, headers=headers, json=payload)
 
 
 
18
  return response.json()
19
 
20
  # Define the function to translate speech
21
  def translate_speech(audio_file):
22
  print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
23
 
24
- # Use the ASR model to transcribe the audio
25
- transcription = asr_model.predict(audio_file.name) # Change this line
 
 
 
26
 
27
  # Use the translation pipeline to translate the transcription
28
  translated_text = query(TRANSLATION_API_URL, {"inputs": transcription})
 
5
  import io
6
 
7
  # Define the Hugging Face Inference API URLs and headers
8
+ ASR_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/saad-speech-recognition-hausa-audio-to-text"
9
  TTS_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/english_voice_tts"
10
  TRANSLATION_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/saad-hausa-text-to-english-text"
11
  headers = {"Authorization": "Bearer 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"}
12
 
 
 
 
13
  # Define the function to query the Hugging Face Inference API
14
+ def query(api_url, payload=None, data=None):
15
+ if data is not None:
16
+ response = requests.post(api_url, headers=headers, data=data)
17
+ else:
18
+ response = requests.post(api_url, headers=headers, json=payload)
19
  return response.json()
20
 
21
  # Define the function to translate speech
22
  def translate_speech(audio_file):
23
  print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
24
 
25
+ # Use the ASR pipeline to transcribe the audio
26
+ with open(audio_file.name, "rb") as f: # Change this line
27
+ data = f.read()
28
+ output = query(ASR_API_URL, data=data)
29
+ transcription = output["text"]
30
 
31
  # Use the translation pipeline to translate the transcription
32
  translated_text = query(TRANSLATION_API_URL, {"inputs": transcription})