Create home.py
Browse files
home.py
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import asyncio
|
3 |
+
import http.server
|
4 |
+
import socketserver
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
servers = []
|
8 |
+
clients = []
|
9 |
+
inputs = []
|
10 |
+
outputs = []
|
11 |
+
states = []
|
12 |
+
used_ports = []
|
13 |
+
connections = []
|
14 |
+
server_ports = []
|
15 |
+
client_ports = []
|
16 |
+
|
17 |
+
st.set_page_config(layout="wide")
|
18 |
+
|
19 |
+
if "http_server" not in st.session_state:
|
20 |
+
|
21 |
+
PORT = 8001
|
22 |
+
Handler = http.server.SimpleHTTPRequestHandler
|
23 |
+
st.session_state.http_server = PORT
|
24 |
+
|
25 |
+
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
26 |
+
print("serving at port", PORT)
|
27 |
+
httpd.serve_forever()
|
28 |
+
|
29 |
+
if "client_state" not in st.session_state:
|
30 |
+
st.session_state.client_state = "complete"
|
31 |
+
if "server_state" not in st.session_state:
|
32 |
+
st.session_state.server_state = "complete"
|
33 |
+
|
34 |
+
# Wy艣wietlanie danych, kt贸re mog膮 by膰 modyfikowane na r贸偶nych stronach
|
35 |
+
server_status1 = st.status(label="websocket servers", state=st.session_state.server_state, expanded=False)
|
36 |
+
server_status = st.sidebar.status(label="websocket servers", state=st.session_state.server_state, expanded=False)
|
37 |
+
server_status1.write(servers)
|
38 |
+
server_status.write(servers)
|
39 |
+
|
40 |
+
client_status1 = st.status(label="websocket clients", state=st.session_state.client_state, expanded=False)
|
41 |
+
client_status = st.sidebar.status(label="websocket clients", state=st.session_state.client_state, expanded=False)
|
42 |
+
client_status1.write(clients)
|
43 |
+
client_status.write(clients)
|
44 |
+
|
45 |
+
async def main():
|
46 |
+
|
47 |
+
# Inicjalizacja danych w st.session_state
|
48 |
+
if "server_ports" not in st.session_state:
|
49 |
+
st.session_state['server_ports'] = ""
|
50 |
+
if "client_ports" not in st.session_state:
|
51 |
+
st.session_state["client_ports"] = ""
|
52 |
+
if "servers" not in st.session_state:
|
53 |
+
st.session_state['servers'] = servers
|
54 |
+
if "clients" not in st.session_state:
|
55 |
+
st.session_state["clients"] = clients
|
56 |
+
if "user_ID" not in st.session_state:
|
57 |
+
st.session_state.user_ID = ""
|
58 |
+
if "gradio_Port" not in st.session_state:
|
59 |
+
st.session_state.gradio_Port = ""
|
60 |
+
if "googleAPI" not in st.session_state:
|
61 |
+
st.session_state.googleAPI = ""
|
62 |
+
if "cseID" not in st.session_state:
|
63 |
+
st.session_state.cseID = ""
|
64 |
+
if "server" not in st.session_state:
|
65 |
+
st.session_state.server = False
|
66 |
+
if "client" not in st.session_state:
|
67 |
+
st.session_state.client = False
|
68 |
+
if "client_state" not in st.session_state:
|
69 |
+
st.session_state.client_state = "complete"
|
70 |
+
if "server_state" not in st.session_state:
|
71 |
+
st.session_state.server_state = "complete"
|
72 |
+
|
73 |
+
|
74 |
+
st.title("NeuralGPT")
|
75 |
+
|
76 |
+
c1, c2 = st.columns(2)
|
77 |
+
|
78 |
+
with c1:
|
79 |
+
st.text("Server ports")
|
80 |
+
srv_state = st.empty()
|
81 |
+
server_status1 = srv_state.status(label="active servers", state=st.session_state.client_state, expanded=False)
|
82 |
+
if st.session_state.server == True:
|
83 |
+
st.session_state.server_state = "running"
|
84 |
+
server_status1.update(state=st.session_state.client_state, expanded=True)
|
85 |
+
server_status1.write(servers)
|
86 |
+
|
87 |
+
with c2:
|
88 |
+
st.text("Client ports")
|
89 |
+
cli_state = st.empty()
|
90 |
+
client_status1 = cli_state.status(label="active clients", state=st.session_state.client_state, expanded=False)
|
91 |
+
if st.session_state.client == True:
|
92 |
+
st.session_state.client_state = "running"
|
93 |
+
client_status1.update(state=st.session_state.client_state, expanded=True)
|
94 |
+
client_status1.write(clients)
|
95 |
+
|
96 |
+
with st.sidebar:
|
97 |
+
|
98 |
+
srv_sidebar = st.empty()
|
99 |
+
cli_sidebar = st.empty()
|
100 |
+
server_status = srv_sidebar.status(label="los serveros", state=st.session_state.client_state, expanded=True)
|
101 |
+
client_status = cli_sidebar.status(label="los clientos", state=st.session_state.client_state, expanded=False)
|
102 |
+
server_status.write(servers)
|
103 |
+
client_status.write(clients)
|
104 |
+
|
105 |
+
if st.session_state.server == True:
|
106 |
+
srv_sidebar.empty()
|
107 |
+
st.session_state.server_state = "running"
|
108 |
+
server_status = srv_sidebar.status(label="servers", state=st.session_state.client_state, expanded=True)
|
109 |
+
server_status.write(servers)
|
110 |
+
|
111 |
+
if st.session_state.client == True:
|
112 |
+
cli_sidebar.empty()
|
113 |
+
st.session_state.client_state = "running"
|
114 |
+
client_status = cli_sidebar.status(label="clients", state=st.session_state.client_state, expanded=True)
|
115 |
+
client_status.write(clients)
|
116 |
+
|
117 |
+
# Uruchomienie aplikacji
|
118 |
+
asyncio.run(main())
|