Gapeleon commited on
Commit
1fcca35
·
verified ·
1 Parent(s): 99f2df0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -30,21 +30,28 @@ speech_granite = AutoModelForSpeechSeq2Seq.from_pretrained(
30
  trust_remote_code=True
31
  )
32
  print("Model loaded successfully")
33
-
34
  def transcribe_audio(audio_input):
35
  """Process audio input and return transcription"""
36
  start_time = time.time()
37
 
 
 
38
  if audio_input is None:
39
  return "Error: No audio provided.", 0.0
40
 
41
  try:
42
  # Load audio file
43
  if isinstance(audio_input, tuple): # From microphone
 
44
  sr, wav_np = audio_input
45
  wav = torch.from_numpy(wav_np).float().unsqueeze(0)
46
- else: # From file
 
 
 
 
47
  wav, sr = torchaudio.load(audio_input, normalize=True)
 
48
 
49
  print(f"Original audio: sample rate {sr}Hz, shape {wav.shape}")
50
 
@@ -129,13 +136,14 @@ Upload an audio file or use your microphone to record speech.
129
 
130
  iface = gr.Interface(
131
  fn=transcribe_audio,
132
- inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"),
133
  outputs=[
134
  gr.Textbox(label="Transcription", lines=5),
135
  gr.Number(label="Processing Time (seconds)")
136
  ],
137
  title=title,
138
  description=description,
 
139
  )
140
 
141
  if __name__ == "__main__":
 
30
  trust_remote_code=True
31
  )
32
  print("Model loaded successfully")
 
33
  def transcribe_audio(audio_input):
34
  """Process audio input and return transcription"""
35
  start_time = time.time()
36
 
37
+ print(f"Audio input received: {type(audio_input)}, value: {audio_input}")
38
+
39
  if audio_input is None:
40
  return "Error: No audio provided.", 0.0
41
 
42
  try:
43
  # Load audio file
44
  if isinstance(audio_input, tuple): # From microphone
45
+ print("Processing microphone input")
46
  sr, wav_np = audio_input
47
  wav = torch.from_numpy(wav_np).float().unsqueeze(0)
48
+ else: # From file upload
49
+ print(f"Processing file input: {audio_input}")
50
+ if not os.path.exists(audio_input):
51
+ return f"Error: File does not exist: {audio_input}", 0.0
52
+
53
  wav, sr = torchaudio.load(audio_input, normalize=True)
54
+ print(f"Loaded audio file: {audio_input}")
55
 
56
  print(f"Original audio: sample rate {sr}Hz, shape {wav.shape}")
57
 
 
136
 
137
  iface = gr.Interface(
138
  fn=transcribe_audio,
139
+ inputs=gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or record audio"),
140
  outputs=[
141
  gr.Textbox(label="Transcription", lines=5),
142
  gr.Number(label="Processing Time (seconds)")
143
  ],
144
  title=title,
145
  description=description,
146
+ examples=[["example.wav"]] if os.path.exists("example.wav") else None,
147
  )
148
 
149
  if __name__ == "__main__":