Spaces:
Sleeping
Sleeping
Antoniskaraolis
commited on
Commit
·
d7aa11b
1
Parent(s):
6c1a3af
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,23 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
import torchaudio
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
waveform = resampler(waveform)
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
transcription = tokenizer.batch_decode(predicted_ids)
|
21 |
-
|
22 |
-
return transcription[0]
|
|
|
1 |
+
import whisper
|
2 |
+
import gradio as gr
|
|
|
3 |
|
4 |
+
def transcribe_audio(file_info):
|
5 |
+
model = whisper.load_model("base") # Choose the appropriate model size
|
6 |
+
audio = whisper.load_audio(file_info.name)
|
7 |
+
audio = whisper.pad_or_trim(audio)
|
8 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
9 |
|
10 |
+
_, probs = model.detect_language(mel)
|
11 |
+
language = max(probs, key=probs.get)
|
12 |
+
print(f"Detected language: {language}")
|
13 |
|
14 |
+
result = model.transcribe(mel)
|
15 |
+
return result["text"]
|
|
|
16 |
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=transcribe_audio,
|
19 |
+
inputs=gr.inputs.Audio(source="microphone", type="file"),
|
20 |
+
outputs="text"
|
21 |
+
)
|
22 |
|
23 |
+
iface.launch()
|
|
|
|
|
|