leenag commited on
Commit
cb0a694
·
verified ·
1 Parent(s): b1133a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -4
app.py CHANGED
@@ -1,5 +1,37 @@
1
  import gradio as gr
2
- import os
3
- gr.load("models/vasista22/whisper-tamil-medium", examples = [
4
- [os.path.join(os.path.abspath(''),"./sample1.wav")]
5
- ]).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import torch
3
+ import soundfile as sf
4
+ from transformers import pipeline
5
+
6
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
+ pipe = pipeline(
8
+ "automatic-speech-recognition",
9
+ model="models/vasista22/whisper-tamil-medium",
10
+ chunk_length_s=30,
11
+ device=device,
12
+ )
13
+
14
+ def transcribe(audio):
15
+ """Transcribes Tamil speech from an audio file."""
16
+ if audio is None:
17
+ return "Please record or upload an audio file."
18
+
19
+ audio_data, sample_rate = sf.read(audio)
20
+ transcription = pipe(
21
+ {"array": audio_data, "sampling_rate": sample_rate},
22
+ chunk_length_s=30,
23
+ batch_size=8,
24
+ return_timestamps=True,
25
+ )["text"]
26
+
27
+ return transcription
28
+
29
+ iface = gr.Interface(
30
+ fn=transcribe,
31
+ inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
32
+ outputs="text",
33
+ title="Tamil Speech Recognition",
34
+ description="Record or upload Tamil speech and get the transcribed text.",
35
+ )
36
+
37
+ iface.launch()