Arcypojeb commited on
Commit
506148a
1 Parent(s): cc4bc20

Update pages/NeuralGPT.py

Browse files
Files changed (1) hide show
  1. pages/NeuralGPT.py +42 -30
pages/NeuralGPT.py CHANGED
@@ -15,7 +15,10 @@ st.set_page_config(
15
  initial_sidebar_state="expanded",
16
  )
17
 
 
 
18
  servers = {}
 
19
  inputs = []
20
  outputs = []
21
  used_ports = []
@@ -332,39 +335,47 @@ async def stop_client():
332
  print("Stopping WebSocket client...")
333
 
334
  async def main():
335
- if "server" not in st.session_state:
336
- st.session_state.server = None
 
 
 
 
 
 
 
 
 
 
 
337
  if "servers" not in st.session_state:
338
  st.session_state.servers = None
339
- if "client" not in st.session_state:
340
- st.session_state.client = None
341
- if "server_Ports" not in st.session_state:
342
- st.session_state.server_Ports = None
343
- if "client_Ports" not in st.session_state:
344
- st.session_state.client_Ports = None
345
  if "api_key" not in st.session_state:
346
  st.session_state.api_key = None
347
  if "userID" not in st.session_state:
348
- st.session_state.user_ID = None
349
 
350
- st.sidebar.text("Server ports:")
351
  serverPorts = st.sidebar.container(border=True)
352
- serverPorts.markdown(st.session_state.server_Ports)
353
  st.sidebar.text("Client ports")
354
  clientPorts = st.sidebar.container(border=True)
355
- clientPorts.markdown(st.session_state.client_Ports)
 
356
  user_id = st.sidebar.container(border=True)
357
- user_id.markdown(st.session_state.user_ID)
358
 
359
  c1, c2 = st.columns(2)
360
 
361
  with c1:
362
  serverPorts1 = st.container(border=True)
363
- serverPorts1.markdown(st.session_state.server_Ports)
364
 
365
  with c2:
366
  clientPorts1 = st.container(border=True)
367
- clientPorts1.markdown(st.session_state.client_Ports)
368
 
369
  tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Fireworks", "GPT4Free", "Character.ai", "Chaindesk agent", "Docsbot Wordpress-agent", "Flowise client"])
370
 
@@ -378,13 +389,13 @@ async def main():
378
  websocket_Port = st.number_input("Server port", 1000)
379
  startServer = st.button('Start websocket server 1')
380
  srvr_ports = st.container(border=True)
381
- srvr_ports.markdown(st.session_state.server_Ports)
382
 
383
  with row1_col2:
384
  client_Port = st.number_input("Client port", 1000)
385
  startClient = st.button('Connect client to server 1')
386
  cli_ports = st.container(border=True)
387
- cli_ports.markdown(st.session_state.client_Ports)
388
 
389
  if userInputt:
390
  print(f"User B: {userInputt}")
@@ -399,14 +410,14 @@ async def main():
399
 
400
  if startServer:
401
  fireworks.client.api_key = fireworksAPI
402
- st.session_state.api_key = fireworks.client.api_key
403
- server_ports.append(websocket_Port)
404
- st.session_state.server_Ports = server_ports
405
- serverPorts.markdown(st.session_state.server_Ports)
406
- serverPorts1.markdown(st.session_state.server_Ports)
407
- srvr_ports.markdown(st.session_state.server_Ports)
408
  try:
409
  server = await websockets.serve(handleServer, 'localhost', websocket_Port)
 
410
  print(f"Launching server at port: {websocket_Port}")
411
  while True:
412
  await server.wait_closed()
@@ -415,15 +426,16 @@ async def main():
415
 
416
 
417
  if startClient:
418
- client_ports.append(client_Port)
419
- clientPorts.markdown(client_ports)
420
- clientPorts1.markdown(client_ports)
421
- cli_ports.markdown(client_ports)
422
- await client.authenticate_with_token(fireworksAPI)
 
 
423
  uri = f'ws://localhost:{client_Port}'
424
  async with websockets.connect(uri) as websocket:
425
- while True:
426
- print(f"Connecting to server at port: {client_Port}...")
427
  # Listen for messages from the server
428
  input_message = await websocket.recv()
429
  print(f"Server: {input_message}")
 
15
  initial_sidebar_state="expanded",
16
  )
17
 
18
+ st.session_state.update(st.session_state)
19
+
20
  servers = {}
21
+ clients = {}
22
  inputs = []
23
  outputs = []
24
  used_ports = []
 
335
  print("Stopping WebSocket client...")
336
 
337
  async def main():
338
+
339
+ st.session_state.update(st.session_state)
340
+
341
+ if 'active_page' not in st.session_state:
342
+ st.session_state.active_page = 'NeuralGPT'
343
+ if "sidebar" not in st.session_state:
344
+ st.session_state.sidebar = True
345
+ if "server_ports" not in st.session_state:
346
+ st.session_state['server_ports'] = False
347
+ if "client_ports" not in st.session_state:
348
+ st.session_state['client_ports'] = False
349
+ if "user_id" not in st.session_state:
350
+ st.session_state.user_id = False
351
  if "servers" not in st.session_state:
352
  st.session_state.servers = None
353
+ if "clients" not in st.session_state:
354
+ st.session_state.clients = None
 
 
 
 
355
  if "api_key" not in st.session_state:
356
  st.session_state.api_key = None
357
  if "userID" not in st.session_state:
358
+ st.session_state.userID = None
359
 
360
+ st.text("Server ports:")
361
  serverPorts = st.sidebar.container(border=True)
362
+ serverPorts.markdown(st.session_state['server_ports'])
363
  st.sidebar.text("Client ports")
364
  clientPorts = st.sidebar.container(border=True)
365
+ clientPorts.markdown(st.session_state['client_ports'])
366
+ st.sidebar.text("Charavter.ai ID")
367
  user_id = st.sidebar.container(border=True)
368
+ user_id.markdown(st.session_state.userID)
369
 
370
  c1, c2 = st.columns(2)
371
 
372
  with c1:
373
  serverPorts1 = st.container(border=True)
374
+ serverPorts1.markdown(st.session_state['server_ports'])
375
 
376
  with c2:
377
  clientPorts1 = st.container(border=True)
378
+ clientPorts1.markdown(st.session_state['client_ports'])
379
 
380
  tab1, tab2, tab3, tab4, tab5, tab6 = st.tabs(["Fireworks", "GPT4Free", "Character.ai", "Chaindesk agent", "Docsbot Wordpress-agent", "Flowise client"])
381
 
 
389
  websocket_Port = st.number_input("Server port", 1000)
390
  startServer = st.button('Start websocket server 1')
391
  srvr_ports = st.container(border=True)
392
+ srvr_ports.markdown(st.session_state['server_ports'])
393
 
394
  with row1_col2:
395
  client_Port = st.number_input("Client port", 1000)
396
  startClient = st.button('Connect client to server 1')
397
  cli_ports = st.container(border=True)
398
+ cli_ports.markdown(st.session_state['client_ports'])
399
 
400
  if userInputt:
401
  print(f"User B: {userInputt}")
 
410
 
411
  if startServer:
412
  fireworks.client.api_key = fireworksAPI
413
+ st.session_state.api_key = fireworks.client.api_key
414
+ st.session_state['server_ports'] = server_ports.append(websocket_Port)
415
+ serverPorts.markdown(st.session_state['server_ports'])
416
+ serverPorts1.markdown(st.session_state['server_ports'])
417
+ srvr_ports.markdown(st.session_state['server_ports'])
 
418
  try:
419
  server = await websockets.serve(handleServer, 'localhost', websocket_Port)
420
+ st.session_state.servers = servers[server]
421
  print(f"Launching server at port: {websocket_Port}")
422
  while True:
423
  await server.wait_closed()
 
426
 
427
 
428
  if startClient:
429
+ fireworks.client.api_key = fireworksAPI
430
+ st.session_state.api_key = fireworks.client.api_key
431
+ st.session_state['client_ports'] = client_ports.append(client_Port)
432
+ clientPorts.markdown(st.session_state['client_ports'])
433
+ clientPorts1.markdown(st.session_state['client_ports'])
434
+ cli_ports.markdown(st.session_state['client_ports'])
435
+ print(f"Connecting to server at port: {client_Port}...")
436
  uri = f'ws://localhost:{client_Port}'
437
  async with websockets.connect(uri) as websocket:
438
+ while True:
 
439
  # Listen for messages from the server
440
  input_message = await websocket.recv()
441
  print(f"Server: {input_message}")