dtkne commited on
Commit
aef58c1
·
verified ·
1 Parent(s): d4d41ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -3,19 +3,28 @@ import os
3
  from transformers import pipeline
4
 
5
  # Load ASR pipeline
6
- asr = pipeline(task="automatic-speech-recognition",
7
- model="distil-whisper/distil-small.en")
8
 
9
- # Define function
10
- def transcribe(audio):
11
- out = asr(audio)
12
- return out['text'] # Extract transcribed text
 
 
 
 
 
 
13
 
14
- # Create Gradio Interface
15
- iface = gr.Interface(fn=transcribe,
16
- inputs=gr.Audio(type="filepath"), # Expect an audio file path
17
- outputs="text")
 
 
18
 
19
- # Launch Interface
20
- iface.launch(share=True,
21
- server_port=int(os.environ.get('PORT1', 7860)))
 
 
 
3
  from transformers import pipeline
4
 
5
  # Load ASR pipeline
6
+ asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil-small.en")
 
7
 
8
+ # Define function to process audio input
9
+ def transcribe(audio_file):
10
+ if audio_file is None:
11
+ return "Error: No audio file provided."
12
+
13
+ try:
14
+ result = asr(audio_file) # Process audio
15
+ return result['text'] # Extract the transcribed text
16
+ except Exception as e:
17
+ return f"Error: {str(e)}"
18
 
19
+ # Create Gradio interface
20
+ iface = gr.Interface(
21
+ fn=transcribe,
22
+ inputs=gr.Audio(type="filepath"), # Expect an audio file path
23
+ outputs="text"
24
+ )
25
 
26
+ # Get port safely (default to 7860 if not set)
27
+ port = int(os.environ.get('PORT1', 7860))
28
+
29
+ # Launch Gradio app
30
+ iface.launch(share=True, server_port=port)