Spaces:
Running
on
Zero
Running
on
Zero
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from faster_whisper import WhisperModel
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Load model on CPU (large-v2 multilingual)
|
6 |
+
model = WhisperModel("large-v2", device="cpu", compute_type="int8")
|
7 |
+
|
8 |
+
LANG_CODES = {
|
9 |
+
"Tamil": "ta",
|
10 |
+
"Malayalam": "ml"
|
11 |
+
}
|
12 |
+
|
13 |
+
def transcribe(audio, language_choice):
|
14 |
+
if audio is None:
|
15 |
+
return "No audio provided."
|
16 |
+
|
17 |
+
# Whisper transcription with minimal correction
|
18 |
+
segments, info = model.transcribe(
|
19 |
+
audio,
|
20 |
+
language=LANG_CODES[language_choice],
|
21 |
+
task="transcribe",
|
22 |
+
beam_size=1,
|
23 |
+
condition_on_previous_text=False,
|
24 |
+
initial_prompt=""
|
25 |
+
)
|
26 |
+
|
27 |
+
# Combine raw text from segments
|
28 |
+
full_text = "".join([seg.text for seg in segments])
|
29 |
+
return full_text.strip()
|
30 |
+
|
31 |
+
# Gradio UI
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("# 🎙 Whisper Large-v2 Raw Transcription\nMinimal correction, Tamil & Malayalam")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
|
37 |
+
lang_choice = gr.Dropdown(choices=list(LANG_CODES.keys()), value="Tamil", label="Language")
|
38 |
+
|
39 |
+
output_text = gr.Textbox(label="Transcription")
|
40 |
+
|
41 |
+
submit_btn = gr.Button("Transcribe")
|
42 |
+
submit_btn.click(transcribe, inputs=[audio_input, lang_choice], outputs=output_text)
|
43 |
+
|
44 |
+
demo.launch()
|