VTechAI commited on
Commit
5a10bfe
1 Parent(s): 5e825a2
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,13 +1,19 @@
 
1
  import gradio as gr
2
  import os
 
3
 
4
  from gradio_client import Client
5
 
6
- link = os.environ['link']
7
- client = Client(link)
 
 
8
 
 
 
9
 
10
- def s2t(source, mic, fi, lang):
11
  if source == 'file':
12
  in_file = fi
13
  else:
@@ -22,6 +28,25 @@ def s2t(source, mic, fi, lang):
22
  print(result)
23
  return result
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def update_audio_ui(audio_source: str, input_audio_mic, input_audio_file):
27
  mic = audio_source == "microphone"
@@ -34,7 +59,7 @@ with gr.Blocks() as demo:
34
  with gr.Group():
35
  with gr.Row() as audio_box:
36
  with gr.Column():
37
- input_lang = gr.Dropdown(['auto','vi', 'ja', 'en-us', 'cn', 'ko'], label='Language?', value='auto', interactive=True)
38
  audio_source = gr.Radio(
39
  label="Audio source",
40
  choices=["file", "microphone"],
@@ -69,6 +94,7 @@ with gr.Blocks() as demo:
69
  api_name=False,
70
  )
71
 
 
72
  btn.click(fn=s2t, inputs=[audio_source, input_audio_mic, input_audio_file, input_lang], outputs=[js])
73
 
74
  if __name__ == "__main__":
 
1
+ import requests
2
  import gradio as gr
3
  import os
4
+ import urllib.request
5
 
6
  from gradio_client import Client
7
 
8
+ hf_link = os.environ['link']
9
+ client = Client(hf_link)
10
+ local_link = os.environ['local_link']
11
+ local_api = os.environ['local_api']
12
 
13
+ local_code = requests.head(local_link).status_code
14
+ print(local_code)
15
 
16
+ def s2t_hf(source, mic, fi, lang):
17
  if source == 'file':
18
  in_file = fi
19
  else:
 
28
  print(result)
29
  return result
30
 
31
+ def s2t_local(source, mic, fi, lang):
32
+ if source == 'file':
33
+ in_file = fi
34
+ else:
35
+ in_file = mic
36
+
37
+ form_data = {"language": lang}
38
+ files = {'input_file': open(in_file, 'rb')}
39
+ print(files)
40
+
41
+ response = requests.post(local_api, files=files, data=form_data, timeout=10000)
42
+
43
+ return response.json()
44
+
45
+ def s2t(source, mic, fi, lang):
46
+ if local_code==200:
47
+ return s2t_local(source, mic, fi, lang)
48
+ else:
49
+ return s2t_hf(source, mic, fi, lang)
50
 
51
  def update_audio_ui(audio_source: str, input_audio_mic, input_audio_file):
52
  mic = audio_source == "microphone"
 
59
  with gr.Group():
60
  with gr.Row() as audio_box:
61
  with gr.Column():
62
+ input_lang = gr.Dropdown(['auto','vi', 'ja', 'en', 'cn', 'ko'], label='Language?', value='en', interactive=True)
63
  audio_source = gr.Radio(
64
  label="Audio source",
65
  choices=["file", "microphone"],
 
94
  api_name=False,
95
  )
96
 
97
+
98
  btn.click(fn=s2t, inputs=[audio_source, input_audio_mic, input_audio_file, input_lang], outputs=[js])
99
 
100
  if __name__ == "__main__":