Spaces:
Sleeping
Sleeping
HarshitJoshi
commited on
Commit
•
bd7df7f
1
Parent(s):
294ff0d
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,19 @@
|
|
|
|
1 |
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
def transcribe_speech(
|
9 |
output = pipe(
|
10 |
-
|
11 |
max_new_tokens=256,
|
12 |
generate_kwargs={
|
13 |
"task": "transcribe",
|
@@ -19,36 +25,18 @@ def transcribe_speech(audio):
|
|
19 |
return output["text"]
|
20 |
|
21 |
example_folder = "./examples"
|
22 |
-
example_files = [f for f in os.listdir(example_folder) if f.endswith('.wav') or f.endswith('.mp3')]
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
transcribe_button.click(
|
38 |
-
fn=transcribe_speech,
|
39 |
-
inputs=audio_input,
|
40 |
-
outputs=output_text
|
41 |
-
)
|
42 |
-
|
43 |
-
with gr.Tab("Examples"):
|
44 |
-
example_dropdown = gr.Dropdown(choices=example_files, label="Select an example")
|
45 |
-
example_audio = gr.Audio(label="Audio Playback")
|
46 |
-
example_transcription = gr.Textbox(label="Transcription")
|
47 |
-
|
48 |
-
example_dropdown.change(
|
49 |
-
fn=play_and_transcribe,
|
50 |
-
inputs=example_dropdown,
|
51 |
-
outputs=[example_audio, example_transcription]
|
52 |
-
)
|
53 |
|
54 |
demo.launch(debug=True)
|
|
|
1 |
+
import torch
|
2 |
from transformers import pipeline
|
3 |
import gradio as gr
|
4 |
import os
|
5 |
|
6 |
+
MODEL_NAME = "HarshitJoshi/whisper-small-Hindi"
|
7 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
8 |
+
pipe = pipeline(
|
9 |
+
task="automatic-speech-recognition",
|
10 |
+
model=MODEL_NAME,
|
11 |
+
device=device,
|
12 |
+
)
|
13 |
|
14 |
+
def transcribe_speech(filepath):
|
15 |
output = pipe(
|
16 |
+
filepath,
|
17 |
max_new_tokens=256,
|
18 |
generate_kwargs={
|
19 |
"task": "transcribe",
|
|
|
25 |
return output["text"]
|
26 |
|
27 |
example_folder = "./examples"
|
|
|
28 |
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=transcribe_speech,
|
31 |
+
inputs=gr.Audio(label="Audio Input", type="filepath"),
|
32 |
+
outputs=gr.Textbox(label="Transcription"),
|
33 |
+
title="Hindi Speech Transcription",
|
34 |
+
description=(
|
35 |
+
"Upload an audio file or record using your microphone to transcribe Hindi speech."
|
36 |
+
),
|
37 |
+
examples=example_folder,
|
38 |
+
cache_examples=True,
|
39 |
+
allow_flagging="never",
|
40 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
demo.launch(debug=True)
|