THost / app.py
Staticaliza's picture
Update app.py
0fb68a4 verified
raw
history blame
648 Bytes
print("HI")
import os
import socket
# get hf space repo id in format "user/space"
repo_id = os.getenv("REPO_ID", "spaceslab/thost")
user, space = repo_id.split("/")
port = int(os.getenv("PORT", "5678"))
host = f"{space}.{user}.hf.space"
# print the tcp url
print(f"tcp://{host}:{port}")
# setup tcp server
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", port))
sock.listen()
print(f"listening on 0.0.0.0:{port}")
while True:
conn, addr = sock.accept()
print("connection from", addr)
data = conn.recv(1024)
if not data:
conn.close()
continue
conn.sendall(data)
conn.close()