Update app.py
Browse files
app.py
CHANGED
|
@@ -6,11 +6,9 @@ import ssl
|
|
| 6 |
|
| 7 |
print("HI")
|
| 8 |
|
| 9 |
-
# start https server in background
|
| 10 |
def start_https():
|
| 11 |
-
https_port = int(os.getenv("HTTPS_PORT", "
|
| 12 |
httpd = HTTPServer(("0.0.0.0", https_port), SimpleHTTPRequestHandler)
|
| 13 |
-
# requires cert.pem and key.pem in working dir
|
| 14 |
httpd.socket = ssl.wrap_socket(
|
| 15 |
httpd.socket,
|
| 16 |
certfile="cert.pem",
|
|
@@ -23,21 +21,18 @@ def start_https():
|
|
| 23 |
thread = threading.Thread(target=start_https, daemon=True)
|
| 24 |
thread.start()
|
| 25 |
|
| 26 |
-
# get hf space repo id in format "user/space"
|
| 27 |
repo_id = os.getenv("REPO_ID", "spaceslab/thost")
|
| 28 |
user, space = repo_id.split("/")
|
| 29 |
port = int(os.getenv("PORT", "5678"))
|
| 30 |
host = f"{space}.{user}.hf.space"
|
| 31 |
|
| 32 |
-
# print the tcp url
|
| 33 |
print(f"tcp://{host}:{port}")
|
| 34 |
|
| 35 |
-
# setup tcp server
|
| 36 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 37 |
sock.bind(("0.0.0.0", port))
|
| 38 |
sock.listen()
|
| 39 |
-
|
| 40 |
print(f"listening on 0.0.0.0:{port}")
|
|
|
|
| 41 |
while True:
|
| 42 |
conn, addr = sock.accept()
|
| 43 |
print("connection from", addr)
|
|
|
|
| 6 |
|
| 7 |
print("HI")
|
| 8 |
|
|
|
|
| 9 |
def start_https():
|
| 10 |
+
https_port = int(os.getenv("HTTPS_PORT", "8443"))
|
| 11 |
httpd = HTTPServer(("0.0.0.0", https_port), SimpleHTTPRequestHandler)
|
|
|
|
| 12 |
httpd.socket = ssl.wrap_socket(
|
| 13 |
httpd.socket,
|
| 14 |
certfile="cert.pem",
|
|
|
|
| 21 |
thread = threading.Thread(target=start_https, daemon=True)
|
| 22 |
thread.start()
|
| 23 |
|
|
|
|
| 24 |
repo_id = os.getenv("REPO_ID", "spaceslab/thost")
|
| 25 |
user, space = repo_id.split("/")
|
| 26 |
port = int(os.getenv("PORT", "5678"))
|
| 27 |
host = f"{space}.{user}.hf.space"
|
| 28 |
|
|
|
|
| 29 |
print(f"tcp://{host}:{port}")
|
| 30 |
|
|
|
|
| 31 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 32 |
sock.bind(("0.0.0.0", port))
|
| 33 |
sock.listen()
|
|
|
|
| 34 |
print(f"listening on 0.0.0.0:{port}")
|
| 35 |
+
|
| 36 |
while True:
|
| 37 |
conn, addr = sock.accept()
|
| 38 |
print("connection from", addr)
|