Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import torch
|
|
8 |
from transformers import AutoModelForCausalLM
|
9 |
from transformers import AutoTokenizer
|
10 |
# from next_word_prediction import GPT2
|
|
|
|
|
11 |
|
12 |
### code snippet
|
13 |
gpt2 = AutoModelForCausalLM.from_pretrained("gpt2", return_dict_in_generate=True)
|
@@ -20,6 +22,8 @@ from share_btn import community_icon_html, loading_icon_html, share_js
|
|
20 |
# get gpt2 model
|
21 |
generator = pipeline('text-generation', model='gpt2')
|
22 |
|
|
|
|
|
23 |
|
24 |
# whisper model specification
|
25 |
model = whisper.load_model("tiny")
|
@@ -81,6 +85,23 @@ def inference(audio):
|
|
81 |
return getText, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
82 |
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
|
86 |
css = """
|
|
|
8 |
from transformers import AutoModelForCausalLM
|
9 |
from transformers import AutoTokenizer
|
10 |
# from next_word_prediction import GPT2
|
11 |
+
import time
|
12 |
+
|
13 |
|
14 |
### code snippet
|
15 |
gpt2 = AutoModelForCausalLM.from_pretrained("gpt2", return_dict_in_generate=True)
|
|
|
22 |
# get gpt2 model
|
23 |
generator = pipeline('text-generation', model='gpt2')
|
24 |
|
25 |
+
# get ASR
|
26 |
+
p = pipeline("automatic-speech-recognition")
|
27 |
|
28 |
# whisper model specification
|
29 |
model = whisper.load_model("tiny")
|
|
|
85 |
return getText, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
86 |
|
87 |
|
88 |
+
def transcribe(audio, state=""):
|
89 |
+
time.sleep(1)
|
90 |
+
text = p(audio)["text"]
|
91 |
+
state += text + " "
|
92 |
+
return state, state
|
93 |
+
|
94 |
+
gr.Interface(
|
95 |
+
fn=transcribe,
|
96 |
+
inputs=[
|
97 |
+
gr.inputs.Audio(source="microphone", type="filepath"),
|
98 |
+
"state"
|
99 |
+
],
|
100 |
+
outputs=[
|
101 |
+
"textbox",
|
102 |
+
"state"
|
103 |
+
],
|
104 |
+
live=True).launch()
|
105 |
|
106 |
|
107 |
css = """
|