panamabananaman commited on
Commit
931f0c7
·
verified ·
1 Parent(s): 4c0d71c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -1,8 +1,30 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
3
 
4
- # Load the speech-to-text model
5
- transcriber = pipeline("automatic-speech-recognition", model="NCAIR1/NigerianAccentedEnglish")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def transcribe_audio(audio):
8
  if audio is None:
@@ -17,8 +39,8 @@ demo = gr.Interface(
17
  fn=transcribe_audio,
18
  inputs=gr.Audio(type="filepath", label="Upload Audio"),
19
  outputs=gr.Textbox(label="Transcript"),
20
- title="Nigerian Accented English Speech-to-Text",
21
- description="Upload an audio file to transcribe Nigerian accented English speech using the NCAIR1/NigerianAccentedEnglish model."
22
  )
23
 
24
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from huggingface_hub import login
4
+ import os
5
 
6
+ # Note: This model (NCAIR1/NigerianAccentedEnglish) is a gated model
7
+ # For demo purposes, we're using openai/whisper-small as a fallback
8
+ # To use the NCAIR model, you need to:
9
+ # 1. Accept the model terms at: https://huggingface.co/NCAIR1/NigerianAccentedEnglish
10
+ # 2. Add your HF token as a secret named HF_TOKEN in Space settings
11
+
12
+ try:
13
+ # Try to use authentication if available
14
+ token = os.getenv("HF_TOKEN")
15
+ if token:
16
+ login(token=token)
17
+ transcriber = pipeline("automatic-speech-recognition", model="NCAIR1/NigerianAccentedEnglish")
18
+ model_name = "NCAIR1/NigerianAccentedEnglish (Nigerian Accented English)"
19
+ else:
20
+ # Fallback to open model
21
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
22
+ model_name = "OpenAI Whisper Small (General English)"
23
+ except Exception as e:
24
+ # Fallback to open model if gated model fails
25
+ print(f"Error loading NCAIR model: {e}")
26
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
27
+ model_name = "OpenAI Whisper Small (General English - Fallback)"
28
 
29
  def transcribe_audio(audio):
30
  if audio is None:
 
39
  fn=transcribe_audio,
40
  inputs=gr.Audio(type="filepath", label="Upload Audio"),
41
  outputs=gr.Textbox(label="Transcript"),
42
+ title="Nigerian Accented English Speech-to-Text Demo",
43
+ description=f"Upload an audio file to transcribe speech to text.\n\nCurrently using: **{model_name}**\n\nNote: To use the NCAIR1/NigerianAccentedEnglish model, accept terms at https://huggingface.co/NCAIR1/NigerianAccentedEnglish and add your HF token."
44
  )
45
 
46
  if __name__ == "__main__":