Update app.py
Browse files
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(
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
# Create Gradio
|
15 |
-
iface = gr.Interface(
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
|
|
|
|
|
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)
|