Spaces:
Runtime error
Runtime error
fix app.py
Browse files- app.py +40 -19
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,22 +1,43 @@
|
|
1 |
from transformers import pipeline
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
return
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import numpy as np
|
3 |
import gradio as gr
|
4 |
|
5 |
+
def respond(message, chat_history):
|
6 |
+
bot_message = message
|
7 |
+
chat_history.append((message, bot_message))
|
8 |
+
return "", chat_history
|
9 |
+
|
10 |
+
def transcribe(audio):
|
11 |
+
sr, y = audio
|
12 |
+
y = y.astype(np.float32)
|
13 |
+
y /= np.max(np.abs(y))
|
14 |
+
result = asr_model({"sampling_rate": sr, "raw": y})["text"]
|
15 |
+
return result
|
16 |
+
|
17 |
+
asr_model_id = "openai/whisper-small.en"
|
18 |
+
asr_model = pipeline("automatic-speech-recognition", model=asr_model_id)
|
19 |
+
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
with gr.Column():
|
22 |
+
gr.Markdown(
|
23 |
+
"""
|
24 |
+
# HKU Canteen VA
|
25 |
+
""")
|
26 |
+
va = gr.Chatbot(container=False)
|
27 |
+
|
28 |
+
with gr.Row(): # text input
|
29 |
+
text_input = gr.Textbox(placeholder="Ask me anything...", container=False, scale=1)
|
30 |
+
submit_btn = gr.Button("Submit", scale=0)
|
31 |
+
|
32 |
+
# with gr.Row(): # audio input
|
33 |
+
# recording = gr.Microphone(show_download_button=False, container=False)
|
34 |
+
|
35 |
+
with gr.Row(): # button toolbar
|
36 |
+
clear = gr.ClearButton([text_input, va])
|
37 |
+
|
38 |
+
text_input.submit(respond, [text_input, va], [text_input, va], queue=False)
|
39 |
+
submit_btn.click(respond, [text_input, va], [text_input, va], queue=False)
|
40 |
+
# recording.stop_recording(transcribe, [recording], [text_input]).then(respond, [text_input, va], [text_input, va], queue=False)
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
torch
|
2 |
-
transformers
|
|
|
|
1 |
torch
|
2 |
+
transformers
|
3 |
+
numpy
|