Staticaliza commited on
Commit
752afed
·
verified ·
1 Parent(s): 64b5885

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -1,7 +1,27 @@
1
- print("HI")
2
-
3
  import os
4
  import socket
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # get hf space repo id in format "user/space"
7
  repo_id = os.getenv("REPO_ID", "spaceslab/thost")
 
 
 
1
  import os
2
  import socket
3
+ import threading
4
+ from http.server import HTTPServer, SimpleHTTPRequestHandler
5
+ 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", "443"))
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",
17
+ keyfile="key.pem",
18
+ server_side=True
19
+ )
20
+ print(f"https listening on 0.0.0.0:{https_port}")
21
+ httpd.serve_forever()
22
+
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")