File size: 958 Bytes
6e1eccf ddf7ac7 17e09e4 ddf7ac7 17e09e4 ddf7ac7 6e1eccf ddf7ac7 6e1eccf |
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 28 29 30 31 32 |
# WarServer - replace HOST with 'localhost' for local testing
import socket
import WarBot
import warnings
warnings.filterwarnings("ignore")
model,tokenizer,model_punct = WarBot.initialize()
HOST = '10.0.0.125'
PORT = 5000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket:
server_socket.bind((HOST, PORT))
server_socket.listen()
print(f'Server is listening on port {PORT}')
while True:
conn, addr = server_socket.accept()
with conn:
print(f'Connected by {addr}')
data = conn.recv(1024)
received_string = data.decode()
print(f'Received string from client: {received_string}')
response = ""
while not response:
response = WarBot.get_response(quote, model, tokenizer, model_punct, temperature=0.2)
response_string = response
conn.sendall(response_string.encode())
conn.close() |