shenjingwen commited on
Commit
19e123a
Β·
verified Β·
1 Parent(s): 106819a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from vector_search import HybridVectorSearch
3
+ from whisper_asr import WhisperAutomaticSpeechRecognizer
4
+
5
+ with gr.Blocks() as demo:
6
+ with gr.Tab("Live Mode"):
7
+ full_stream = gr.State()
8
+ transcript = gr.State(value="")
9
+ chats = gr.State(value=[])
10
+
11
+ with gr.Row(variant="panel"):
12
+ audio_input = gr.Audio(sources=["microphone"], streaming=True)
13
+ with gr.Row(variant="panel", equal_height=True):
14
+ with gr.Column(scale=1):
15
+ chatbot = gr.Chatbot(
16
+ bubble_full_width=True, height="65vh", show_copy_button=True
17
+ )
18
+ chat_input = gr.Textbox(
19
+ interactive=True, placeholder="Type Search Query...."
20
+ )
21
+ with gr.Column(scale=1):
22
+ transcript_textbox = gr.Textbox(
23
+ lines=40,
24
+ placeholder="Transcript",
25
+ max_lines=40,
26
+ label="Transcript",
27
+ show_label=True,
28
+ autoscroll=True,
29
+ )
30
+
31
+ chat_input.submit(
32
+ HybridVectorSearch.chat_search, [chat_input, chatbot], [chat_input, chatbot]
33
+ )
34
+ audio_input.stream(
35
+ WhisperAutomaticSpeechRecognizer.transcribe_with_diarization,
36
+ [audio_input, full_stream, transcript],
37
+ [transcript_textbox, full_stream, transcript],
38
+ )
39
+
40
+ with gr.Tab("Offline Mode"):
41
+ full_stream = gr.State()
42
+ transcript = gr.State(value="")
43
+ chats = gr.State(value=[])
44
+
45
+ with gr.Row(variant="panel"):
46
+ audio_input = gr.Audio(sources=["upload"], type="filepath")
47
+ with gr.Row(variant="panel", equal_height=True):
48
+ with gr.Column(scale=1):
49
+ chatbot = gr.Chatbot(
50
+ bubble_full_width=True, height="55vh", show_copy_button=True
51
+ )
52
+ chat_input = gr.Textbox(
53
+ interactive=True, placeholder="Type Search Query...."
54
+ )
55
+ with gr.Column(scale=1):
56
+ transcript_textbox = gr.Textbox(
57
+ lines=35,
58
+ placeholder="Transcripts",
59
+ max_lines=35,
60
+ label="Transcript",
61
+ show_label=True,
62
+ autoscroll=True,
63
+ )
64
+
65
+ chat_input.submit(
66
+ HybridVectorSearch.chat_search, [chat_input, chatbot], [chat_input, chatbot]
67
+ )
68
+ audio_input.upload(
69
+ WhisperAutomaticSpeechRecognizer.transcribe_with_diarization_file,
70
+ [audio_input],
71
+ [transcript_textbox, full_stream, transcript],
72
+ )
73
+
74
+ if __name__ == "__main__":
75
+ demo.launch()
76
+ # demo.launch(server_name="0.0.0.0", server_port=7860, share=True)