arthoho66 commited on
Commit
af8c3ac
1 Parent(s): 490b518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -74
app.py CHANGED
@@ -1,41 +1,30 @@
1
- from engine.speech2text import Speech2Text
2
- from engine.ner_engine import NERInfer
3
- from engine.audio_chunk import AudioChunk
4
- import glob
5
- import time
6
  import gradio as gr
7
- import os
8
-
9
- audio_chunk = AudioChunk()
10
- speech2text = Speech2Text()
11
- ner_tag = NERInfer()
12
-
 
13
  text = ""
14
- def streaming_process(streaming_audio_file) -> str:
15
- global text
16
- text = speech2text.process_streaming(streaming_audio_file)
17
- # return text
18
-
19
- def output_streaming(text_streaming,text01)-> str:
20
- text_streaming+=text01
21
- return text_streaming
22
-
23
  def recorded_process(recorded_audio_file) -> str:
24
  """
25
  to get both input
26
  and use speech2text for get text
27
  """
28
- text = speech2text.process_microphone(recorded_audio_file)
29
- result = ner_tag.infer(text)
30
- return {"text": text, "entities": result}
31
 
32
 
33
- def uploaded_process(uploaded_audio_file) -> str:
34
- audio_chunk.chunks_audio(uploaded_audio_file)
35
- text = speech2text.process_audio()
36
- result = ner_tag.infer(text)
37
- return {"text": text, "entities": result}
38
 
 
 
 
39
 
40
  def clear_inputs_and_outputs() -> list:
41
  """
@@ -44,23 +33,10 @@ def clear_inputs_and_outputs() -> list:
44
  audio_chunk.remove_chunk()
45
  return [None, None, None, None]
46
 
 
47
  text_streaming = ""
48
 
49
  with gr.Blocks() as demo:
50
- """
51
- buld gradio app
52
-
53
- """
54
- gr.Markdown(
55
- """
56
- ![logo](/file=./image/clicknext_logo2x.png)
57
-
58
- # Automatic Speech Recognition
59
-
60
- ##### Experience real-time, accurate, and multilingual speech-to-text conversion with our cutting-edge ASR technology.
61
- """
62
- )
63
-
64
  with gr.Tab("Record File"):
65
  with gr.Row():
66
  with gr.Column():
@@ -69,7 +45,7 @@ with gr.Blocks() as demo:
69
  clr_btn = gr.Button(value="Clear", variant="secondary")
70
  sub_btn = gr.Button(value="submit")
71
  with gr.Column():
72
- lbl_output = gr.HighlightedText(label="Result")
73
 
74
  clr_btn.click(
75
  fn=clear_inputs_and_outputs,
@@ -100,34 +76,4 @@ with gr.Blocks() as demo:
100
  text_streaming = output_streaming(text_streaming,text)
101
  gr.Textbox(value=text, label="Result", autofocus=True)
102
 
103
- # with gr.Tab("Upload File"):
104
- # with gr.Row():
105
- # with gr.Column():
106
- # upl_input = gr.Audio( type="filepath", label="Upload a file")
107
- # with gr.Row():
108
- # clr_btn = gr.Button(value="Clear", variant="secondary")
109
- # sub_btn = gr.Button(value="submit")
110
- # gr.Examples(examples=[
111
- # os.path.join(os.path.dirname(__file__),"examples/politics.mp3"),
112
- # os.path.join(os.path.dirname(__file__),"examples/law1.mp3"),
113
- # os.path.join(os.path.dirname(__file__),"examples/law2.mp3"),
114
- # os.path.join(os.path.dirname(__file__),"examples/law3.mp3"),
115
- # os.path.join(os.path.dirname(__file__),"examples/economy.mp3"),
116
- # os.path.join(os.path.dirname(__file__),"examples/general.mp3")
117
- # ],
118
- # inputs = upl_input)
119
- # with gr.Column():
120
- # lbl_output = gr.HighlightedText(label="Result")
121
-
122
- # clr_btn.click(
123
- # fn=clear_inputs_and_outputs,
124
- # inputs=[],
125
- # outputs=[upl_input, lbl_output]
126
- # )
127
- # sub_btn.click(
128
- # fn=uploaded_process,
129
- # inputs=[upl_input],
130
- # outputs=[lbl_output]
131
- # )
132
-
133
- demo.launch(server_name="0.0.0.0", server_port=8085)
 
1
+ from transformers import pipeline
 
 
 
 
2
  import gradio as gr
3
+ import time
4
+ p = pipeline(
5
+ task="automatic-speech-recognition",
6
+ model="arthoho66/model_005_2000",
7
+ token="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",
8
+ # device="cuda:0",
9
+ )
10
  text = ""
 
 
 
 
 
 
 
 
 
11
  def recorded_process(recorded_audio_file) -> str:
12
  """
13
  to get both input
14
  and use speech2text for get text
15
  """
16
+ text = p(recorded_audio_file)["text"]
17
+ return text
 
18
 
19
 
20
+ def streaming_process(streaming_audio_file) -> str:
21
+ global text
22
+ text = p(streaming_audio_file)["text"]
23
+ return text
 
24
 
25
+ def output_streaming(text_streaming,text01)-> str:
26
+ text_streaming+=text01
27
+ return text_streaming
28
 
29
  def clear_inputs_and_outputs() -> list:
30
  """
 
33
  audio_chunk.remove_chunk()
34
  return [None, None, None, None]
35
 
36
+
37
  text_streaming = ""
38
 
39
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  with gr.Tab("Record File"):
41
  with gr.Row():
42
  with gr.Column():
 
45
  clr_btn = gr.Button(value="Clear", variant="secondary")
46
  sub_btn = gr.Button(value="submit")
47
  with gr.Column():
48
+ lbl_output = gr.Textbox(label="Result")
49
 
50
  clr_btn.click(
51
  fn=clear_inputs_and_outputs,
 
76
  text_streaming = output_streaming(text_streaming,text)
77
  gr.Textbox(value=text, label="Result", autofocus=True)
78
 
79
+ demo.launch(server_name="0.0.0.0", server_port=8085)