kurianbenoy commited on
Commit
1699327
1 Parent(s): 3a35dda

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+ from huggingface_hub import model_info
5
+
6
+ MODEL_NAME = "kurianbenoy/whisper-small-ml-imasc" #this always needs to stay in line 8 :D sorry for the hackiness
7
+ lang = "ml"
8
+
9
+ device = 0 if torch.cuda.is_available() else "cpu"
10
+ pipe = pipeline(
11
+ task="automatic-speech-recognition",
12
+ model=MODEL_NAME,
13
+ chunk_length_s=30,
14
+ device=device,
15
+ batch_size=8,
16
+ )
17
+
18
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
19
+
20
+ def transcribe(microphone=None, file_upload=None):
21
+ warn_output = ""
22
+ if (microphone is not None) and (file_upload is not None):
23
+ warn_output = (
24
+ "WARNING: You've uploaded an audio file and used the microphone. "
25
+ "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
26
+ )
27
+
28
+ elif (microphone is None) and (file_upload is None):
29
+ return "ERROR: You have to either use the microphone or upload an audio file"
30
+
31
+ file = microphone if microphone is not None else file_upload
32
+
33
+ text = pipe(file)["text"]
34
+
35
+ return warn_output + text
36
+
37
+ def transcribe1(file):
38
+ text = pipe(file)["text"]
39
+ print(text)
40
+ return text
41
+
42
+ #print(transcribe(None,"anil.wav"))
43
+
44
+ mf_transcribe = gr.Interface(
45
+ fn=transcribe1,
46
+ inputs=[
47
+ gr.Audio(sources=["upload"], type="filepath")
48
+ ],
49
+ outputs="text",
50
+ title="PALLAKKU - Whisper finetuned",
51
+ )
52
+
53
+ mf_transcribe.launch(debug=True,share=False)