qqc1989 commited on
Commit
3db535e
·
verified ·
1 Parent(s): ff70a9c

Update python/gradio_demo.py

Browse files
Files changed (1) hide show
  1. python/gradio_demo.py +24 -1
python/gradio_demo.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  import os
 
 
3
  from SenseVoiceAx import SenseVoiceAx
4
  import numpy as np
5
 
@@ -41,6 +43,19 @@ def speech_to_text(audio_input, lang):
41
  return asr_res
42
 
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  def main():
45
  with gr.Blocks() as demo:
46
  with gr.Row():
@@ -59,9 +74,17 @@ def main():
59
  audio_input.change(
60
  fn=speech_to_text, inputs=[audio_input, lang_dropdown], outputs=output_text
61
  )
 
 
 
 
 
 
 
62
 
63
  demo.launch(
64
- server_name="0.0.0.0",
 
65
  ssl_certfile="./cert.pem",
66
  ssl_keyfile="./key.pem",
67
  ssl_verify=False,
 
1
  import gradio as gr
2
  import os
3
+ import re
4
+ import subprocess
5
  from SenseVoiceAx import SenseVoiceAx
6
  import numpy as np
7
 
 
43
  return asr_res
44
 
45
 
46
+ def get_all_local_ips():
47
+ result = subprocess.run(['ip', 'a'], capture_output=True, text=True)
48
+ output = result.stdout
49
+
50
+ # 匹配所有IPv4
51
+ ips = re.findall(r'inet (\d+\.\d+\.\d+\.\d+)', output)
52
+
53
+ # 过滤掉回环地址
54
+ real_ips = [ip for ip in ips if not ip.startswith('127.')]
55
+
56
+ return real_ips
57
+
58
+
59
  def main():
60
  with gr.Blocks() as demo:
61
  with gr.Row():
 
74
  audio_input.change(
75
  fn=speech_to_text, inputs=[audio_input, lang_dropdown], outputs=output_text
76
  )
77
+
78
+ # 启动
79
+ ips = get_all_local_ips()
80
+ port = 7861
81
+ for ip in ips:
82
+ print(f"* Running on local URL: https://{ip}:{port}")
83
+ ip = "0.0.0.0"
84
 
85
  demo.launch(
86
+ server_name=ip,
87
+ server_port=port,
88
  ssl_certfile="./cert.pem",
89
  ssl_keyfile="./key.pem",
90
  ssl_verify=False,