Update app.py
Browse files
app.py
CHANGED
@@ -3,24 +3,26 @@ from pydub import AudioSegment
|
|
3 |
from faster_whisper import WhisperModel
|
4 |
import os
|
5 |
|
|
|
6 |
model = WhisperModel("openai/whisper-large-v3-turbo", compute_type="int8")
|
7 |
|
8 |
-
def convert_to_wav(
|
9 |
-
audio = AudioSegment.from_file(
|
10 |
audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
|
11 |
-
|
12 |
-
audio.export(
|
13 |
-
return
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
segments, info = model.transcribe(
|
18 |
transcript = "\n".join([seg.text for seg in segments])
|
19 |
-
return f"π Language: {info.language}\n\nπ Transcript:\n{transcript}"
|
20 |
|
21 |
-
gr.Interface(
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
).launch()
|
|
|
3 |
from faster_whisper import WhisperModel
|
4 |
import os
|
5 |
|
6 |
+
# Load model from Hugging Face (it will download & cache automatically)
|
7 |
model = WhisperModel("openai/whisper-large-v3-turbo", compute_type="int8")
|
8 |
|
9 |
+
def convert_to_wav(input_path):
|
10 |
+
audio = AudioSegment.from_file(input_path)
|
11 |
audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
|
12 |
+
output_path = input_path.replace(".", "_ready.")
|
13 |
+
audio.export(output_path, format="wav")
|
14 |
+
return output_path
|
15 |
|
16 |
+
def transcribe_and_detect_lang(file_path):
|
17 |
+
wav_path = convert_to_wav(file_path)
|
18 |
+
segments, info = model.transcribe(wav_path)
|
19 |
transcript = "\n".join([seg.text for seg in segments])
|
20 |
+
return f"π Detected Language: {info.language}\n\nπ Transcript:\n{transcript}"
|
21 |
|
22 |
+
gr.Interface(
|
23 |
+
fn=transcribe_and_detect_lang,
|
24 |
+
inputs=gr.Audio(type="filepath", label="π§ Upload Audio File"),
|
25 |
+
outputs=gr.Textbox(label="π Output"),
|
26 |
+
title="π Whisper Language Identifier",
|
27 |
+
description="Upload an audio file in any language (Tamil, Hindi, English, etc.) and detect its language + get transcription."
|
28 |
).launch()
|