YingxuHe commited on
Commit
ac3788a
·
verified ·
1 Parent(s): 9ebf82e

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +10 -5
utils.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import io
2
 
3
  import librosa
@@ -57,15 +58,19 @@ def bytes_to_array(audio_bytes):
57
  )
58
  return audio_array
59
 
60
- def start_server(ssh_key, dns_name):
61
- pkey = paramiko.RSAKey.from_private_key(io.StringIO(ssh_key))
 
 
 
62
 
63
  server = SSHTunnelForwarder(
64
- ssh_address_or_host=dns_name,
65
  ssh_username="ec2-user",
66
  ssh_pkey=pkey,
67
- local_bind_address=("127.0.0.1", local_port),
68
  remote_bind_address=("127.0.0.1", 8000)
69
  )
70
-
 
71
  server.start()
 
1
+ import os
2
  import io
3
 
4
  import librosa
 
58
  )
59
  return audio_array
60
 
61
+ def start_server():
62
+ if os.getenv('TUNNEL_STATUS') == "200":
63
+ return
64
+
65
+ pkey = paramiko.RSAKey.from_private_key(io.StringIO(os.getenv('PRIVATE_KEY')))
66
 
67
  server = SSHTunnelForwarder(
68
+ ssh_address_or_host=os.getenv('SERVER_DNS_NAME'),
69
  ssh_username="ec2-user",
70
  ssh_pkey=pkey,
71
+ local_bind_address=("127.0.0.1", int(os.getenv('LOCAL_PORT'))),
72
  remote_bind_address=("127.0.0.1", 8000)
73
  )
74
+
75
+ os.environ['TUNNEL_STATUS'] = "200"
76
  server.start()