Spaces:
Build error
Build error
Commit
·
a66dfeb
1
Parent(s):
bb1acbb
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,37 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import whisper
|
3 |
-
import numpy as np
|
4 |
|
|
|
5 |
model = whisper.load_model("base")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
audio = whisper.pad_or_trim(audio)
|
11 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
options = whisper.DecodingOptions()
|
13 |
result = whisper.decode(model, mel, options)
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
import whisper
|
|
|
4 |
|
5 |
+
# Load the Whisper model
|
6 |
model = whisper.load_model("base")
|
7 |
|
8 |
+
# Function to process the uploaded audio file and perform transcription
|
9 |
+
def process_audio(upload):
|
10 |
+
# Save the uploaded audio file
|
11 |
+
file_path = "uploaded_audio.mp3"
|
12 |
+
upload.save(file_path)
|
13 |
+
|
14 |
+
# Load the audio file and perform preprocessing
|
15 |
+
audio = whisper.load_audio(file_path)
|
16 |
audio = whisper.pad_or_trim(audio)
|
17 |
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
18 |
+
|
19 |
+
# Detect the spoken language
|
20 |
+
_, probs = model.detect_language(mel)
|
21 |
+
detected_language = max(probs, key=probs.get)
|
22 |
+
|
23 |
+
# Perform transcription using Whisper ASR
|
24 |
options = whisper.DecodingOptions()
|
25 |
result = whisper.decode(model, mel, options)
|
26 |
+
transcription = result.text
|
27 |
+
|
28 |
+
return transcription
|
29 |
|
30 |
+
# Create an audio input component for uploading the audio file
|
31 |
+
audio_input = gr.inputs.Audio(label="Upload Audio", type="file")
|
32 |
+
|
33 |
+
# Create a text output component for displaying the transcription
|
34 |
+
text_output = gr.outputs.Textbox(label="Transcription")
|
35 |
+
|
36 |
+
# Create a Gradio interface
|
37 |
+
gr.Interface(fn=process_audio, inputs=audio_input, outputs=text_output, title="Audio Transcription").launch()
|