-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
27 lines (22 loc) · 719 Bytes
/
server.py
File metadata and controls
27 lines (22 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import socket
import generateGPT2 as gpt2
isSelected = False
HOST = '127.0.0.1'
PORT = 65432
with socket.socket(socket.AF_INET,socket.SOCK_STREAM) as server:
server.bind((HOST,PORT))
server.listen()
print("Server is running...")
conn, addr = server.accept()
with conn:
print("Client Address is:",addr)
isConnected = True
while isConnected:
data = conn.recv(1024)
if not data:
break
input = data.decode(encoding="utf-8")
print(f"Received: {input}")
output = str(gpt2.generate(input))
conn.sendall(output.encode(encoding="utf-8"))
print(f"Sent: {output}")