Arcypojeb commited on
Commit
155b034
1 Parent(s): 3cdc4ca

Upload 5 files

Browse files
Files changed (5) hide show
  1. pages/Fireworks.py +206 -0
  2. pages/GPT4Free.py +194 -0
  3. pages/biedny.py +163 -0
  4. pages/home.py +55 -0
  5. pages/takijaki.py +61 -0
pages/Fireworks.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import websockets
3
+ import asyncio
4
+ import sqlite3
5
+ import json
6
+ import g4f
7
+ import streamlit as st
8
+ import fireworks.client
9
+
10
+ servers = {}
11
+ inputs = []
12
+ outputs = []
13
+ used_ports = []
14
+ server_ports = []
15
+ client_ports = []
16
+
17
+ st.set_page_config(layout="wide")
18
+ websocket_server = None
19
+
20
+ GOOGLE_CSE_ID = "f3882ab3b67cc4923"
21
+ GOOGLE_API_KEY = "AIzaSyBNvtKE35EAeYO-ECQlQoZO01RSHWhfIws"
22
+ FIREWORKS_API_KEY = "xbwGxyTyOf7ats2GcEU0Pj62kpZBVZa2r6i5lKbKG99LFG38"
23
+
24
+ # Set up the SQLite database
25
+ db = sqlite3.connect('chat-hub.db')
26
+ cursor = db.cursor()
27
+ cursor.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, message TEXT, timestamp TEXT)')
28
+ db.commit()
29
+
30
+ system_instruction = "You are now integrated with a local websocket server in a project of hierarchical cooperative multi-agent framework called NeuralGPT. Your main job is to coordinate simultaneous work of multiple LLMs connected to you as clients. Each LLM has a model (API) specific ID to help you recognize different clients in a continuous chat thread (template: <NAME>-agent and/or <NAME>-client). Your chat memory module is integrated with a local SQL database with chat history. Your primary objective is to maintain the logical and chronological order while answering incoming messages and to send your answers to the correct clients to maintain synchronization of the question->answer logic. However, please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic."
31
+
32
+ # Define the function for sending an error message
33
+ async def chatCompletion(question):
34
+ fireworks.client.api_key = FIREWORKS_API_KEY
35
+ try:
36
+ # Connect to the database and get the last 30 messages
37
+ db = sqlite3.connect('chat-hub.db')
38
+ cursor = db.cursor()
39
+ cursor.execute("SELECT * FROM messages ORDER BY timestamp DESC LIMIT 10")
40
+ messages = cursor.fetchall()
41
+ messages.reverse()
42
+
43
+ # Extract user inputs and generated responses from the messages
44
+ past_user_inputs = []
45
+ generated_responses = []
46
+
47
+ for message in messages:
48
+ if message[1] == 'client':
49
+ past_user_inputs.append(message[2])
50
+ else:
51
+ generated_responses.append(message[2])
52
+
53
+ # Prepare data to send to the chatgpt-api.shn.hk
54
+ response = fireworks.client.ChatCompletion.create(
55
+ model="accounts/fireworks/models/llama-v2-7b-chat",
56
+ messages=[
57
+ {"role": "system", "content": system_instruction},
58
+ *[{"role": "user", "content": input} for input in past_user_inputs],
59
+ *[{"role": "assistant", "content": response} for response in generated_responses],
60
+ {"role": "user", "content": question}
61
+ ],
62
+ stream=False,
63
+ n=1,
64
+ max_tokens=2500,
65
+ temperature=0.5,
66
+ top_p=0.7,
67
+ )
68
+
69
+ answer = response.choices[0].message.content
70
+ print(answer)
71
+ return str(answer)
72
+
73
+ except Exception as error:
74
+ print("Error while fetching or processing the response:", error)
75
+ return "Error: Unable to generate a response."
76
+
77
+ async def handleWebSocket(ws):
78
+ instruction = "Hello! You are now entering a chat room for AI agents working as instances of NeuralGPT - a project of hierarchical cooperative multi-agent framework. Keep in mind that you are speaking with another chatbot. Please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic. If you're unsure what you should do, ask the instance of higher hierarchy (server)"
79
+ print('New connection')
80
+ await ws.send(instruction)
81
+ while True:
82
+ message = await ws.recv()
83
+ print(f'Received message: {message}')
84
+ inputMsg = st.chat_message("assistant")
85
+ inputMsg.markdown(message)
86
+ timestamp = datetime.datetime.now().isoformat()
87
+ sender = 'client'
88
+ db = sqlite3.connect('chat-hub.db')
89
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
90
+ (sender, message, timestamp))
91
+ db.commit()
92
+ try:
93
+ response = await chatCompletion(message)
94
+ serverResponse = f"server: {response}"
95
+ outputMsg = st.chat_message("ai")
96
+ print(serverResponse)
97
+ outputMsg.markdown(response)
98
+ timestamp = datetime.datetime.now().isoformat()
99
+ serverSender = 'server'
100
+ db = sqlite3.connect('chat-hub.db')
101
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
102
+ (serverSender, serverResponse, timestamp))
103
+ db.commit()
104
+ # Append the server response to the server_responses list
105
+ await ws.send(serverResponse)
106
+
107
+ except websockets.exceptions.ConnectionClosedError as e:
108
+ print(f"Connection closed: {e}")
109
+
110
+ except Exception as e:
111
+ print(f"Error: {e}")
112
+
113
+ # Start the WebSocket server
114
+ async def start_websockets(websocketPort):
115
+ async with websockets.serve(handleWebSocket, 'localhost', websocketPort):
116
+ print(f"Starting WebSocket server on port {websocketPort}...")
117
+ await asyncio.Future()
118
+
119
+ async def start_client(clientPort):
120
+ global ws
121
+ input_Msg = st.chat_message("ai")
122
+ uri = f'ws://localhost:{clientPort}'
123
+ client_ports.append(clientPort)
124
+ async with websockets.connect(uri) as ws:
125
+ while True:
126
+ print(f"Connecting to server at port: {clientPort}...")
127
+ # Listen for messages from the server
128
+ input_message = await ws.recv()
129
+ output_Msg = st.chat_message("assistant")
130
+ input_Msg.markdown(input_message)
131
+ output_message = await chatCompletion(input_message)
132
+ output_Msg.markdown(output_message)
133
+ await ws.send(json.dumps(output_message))
134
+
135
+ async def handleUser(userInput):
136
+ print(f"User B: {userInput}")
137
+ user_input = st.chat_message("human")
138
+ user_input.markdown(userInput)
139
+ timestamp = datetime.datetime.now().isoformat()
140
+ sender = 'client'
141
+ db = sqlite3.connect('chat-hub.db')
142
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
143
+ (sender, userInput, timestamp))
144
+ db.commit()
145
+ try:
146
+ response = await chatCompletion(userInput)
147
+ server_response = st.chat_message("assistant")
148
+ server_response.markdown(response)
149
+ serverSender = 'server'
150
+ timestamp = datetime.datetime.now().isoformat()
151
+ db = sqlite3.connect('chat-hub.db')
152
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
153
+ (serverSender, response, timestamp))
154
+ db.commit()
155
+
156
+ except Exception as e:
157
+ print(f"Error: {e}")
158
+
159
+ # Stop the WebSocket server
160
+ async def stop_websockets():
161
+ global server
162
+ if server:
163
+ # Close all connections gracefully
164
+ server.close()
165
+ # Wait for the server to close
166
+ server.wait_closed()
167
+ print("Stopping WebSocket server...")
168
+ else:
169
+ print("WebSocket server is not running.")
170
+
171
+ # Stop the WebSocket client
172
+ async def stop_client():
173
+ global ws
174
+ # Close the connection with the server
175
+ ws.close()
176
+ print("Stopping WebSocket client...")
177
+
178
+ async def main():
179
+ userInput = st.chat_input("User input")
180
+ websocketPort = st.number_input("Server port", 1000)
181
+ startServer = st.sidebar.button('Start websocket server')
182
+ clientPort = st.number_input("Client port", 1000)
183
+ startClient = st.sidebar.button('Connect client to server')
184
+ st.sidebar.text("Server ports:")
185
+ serverPorts = st.sidebar.container(border=True)
186
+ serverPorts.text("Local ports")
187
+ st.sidebar.text("Client ports")
188
+ clientPorts = st.sidebar.container(border=True)
189
+ clientPorts.text("Connected ports")
190
+
191
+ if userInput:
192
+ print(f"User B: {userInput}")
193
+ await handleUser(userInput)
194
+
195
+ if startServer:
196
+ server_ports.append(websocketPort)
197
+ serverPorts.markdown(server_ports)
198
+ await start_websockets(websocketPort)
199
+
200
+ if startClient:
201
+ client_ports.append(clientPort)
202
+ clientPorts.markdown(client_ports)
203
+ await start_client(clientPort)
204
+
205
+
206
+ asyncio.run(main())
pages/GPT4Free.py ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import websockets
3
+ import asyncio
4
+ import sqlite3
5
+ import json
6
+ import g4f
7
+ import streamlit as st
8
+
9
+ servers = {}
10
+ inputs = []
11
+ outputs = []
12
+ used_ports = []
13
+ server_ports = []
14
+ client_ports = []
15
+
16
+ st.set_page_config(layout="wide")
17
+ websocket_server = None
18
+
19
+ GOOGLE_CSE_ID = "f3882ab3b67cc4923"
20
+ GOOGLE_API_KEY = "AIzaSyBNvtKE35EAeYO-ECQlQoZO01RSHWhfIws"
21
+ FIREWORKS_API_KEY = "xbwGxyTyOf7ats2GcEU0Pj62kpZBVZa2r6i5lKbKG99LFG38"
22
+
23
+ # Set up the SQLite database
24
+ db = sqlite3.connect('chat-hub.db')
25
+ cursor = db.cursor()
26
+ cursor.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, message TEXT, timestamp TEXT)')
27
+ db.commit()
28
+
29
+ system_instruction = "You are now integrated with a local websocket server in a project of hierarchical cooperative multi-agent framework called NeuralGPT. Your main job is to coordinate simultaneous work of multiple LLMs connected to you as clients. Each LLM has a model (API) specific ID to help you recognize different clients in a continuous chat thread (template: <NAME>-agent and/or <NAME>-client). Your chat memory module is integrated with a local SQL database with chat history. Your primary objective is to maintain the logical and chronological order while answering incoming messages and to send your answers to the correct clients to maintain synchronization of the question->answer logic. However, please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic."
30
+
31
+ # Define the function for sending an error message
32
+ async def askQuestion(question):
33
+ try:
34
+ db = sqlite3.connect('chat-hub.db')
35
+ cursor = db.cursor()
36
+ cursor.execute("SELECT * FROM messages ORDER BY timestamp DESC LIMIT 30")
37
+ messages = cursor.fetchall()
38
+ messages.reverse()
39
+
40
+ past_user_inputs = []
41
+ generated_responses = []
42
+
43
+ for message in messages:
44
+ if message[1] == 'client':
45
+ past_user_inputs.append(message[2])
46
+ else:
47
+ generated_responses.append(message[2])
48
+
49
+ response = await g4f.ChatCompletion.create_async(
50
+ model=g4f.models.gpt_4,
51
+ provider=g4f.Provider.Bing,
52
+ messages=[
53
+ {"role": "system", "content": system_instruction},
54
+ *[{"role": "user", "content": message} for message in past_user_inputs],
55
+ *[{"role": "assistant", "content": message} for message in generated_responses],
56
+ {"role": "user", "content": question}
57
+ ])
58
+
59
+ print(response)
60
+ return response
61
+
62
+ except Exception as e:
63
+ print(e)
64
+
65
+ async def handleWebSocket(ws):
66
+ instruction = "Hello! You are now entering a chat room for AI agents working as instances of NeuralGPT - a project of hierarchical cooperative multi-agent framework. Keep in mind that you are speaking with another chatbot. Please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic. If you're unsure what you should do, ask the instance of higher hierarchy (server)"
67
+ print('New connection')
68
+ await ws.send(instruction)
69
+ while True:
70
+ message = await ws.recv()
71
+ print(f'Received message: {message}')
72
+ inputMsg = st.chat_message("assistant")
73
+ inputMsg.markdown(message)
74
+ timestamp = datetime.datetime.now().isoformat()
75
+ sender = 'client'
76
+ db = sqlite3.connect('chat-hub.db')
77
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
78
+ (sender, message, timestamp))
79
+ db.commit()
80
+ try:
81
+ response = await askQuestion(message)
82
+ serverResponse = f"server: {response}"
83
+ outputMsg = st.chat_message("ai")
84
+ print(serverResponse)
85
+ outputMsg.markdown(response)
86
+ timestamp = datetime.datetime.now().isoformat()
87
+ serverSender = 'server'
88
+ db = sqlite3.connect('chat-hub.db')
89
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
90
+ (serverSender, serverResponse, timestamp))
91
+ db.commit()
92
+ # Append the server response to the server_responses list
93
+ await ws.send(serverResponse)
94
+
95
+ except websockets.exceptions.ConnectionClosedError as e:
96
+ print(f"Connection closed: {e}")
97
+
98
+ except Exception as e:
99
+ print(f"Error: {e}")
100
+
101
+ # Start the WebSocket server
102
+ async def start_websockets(websocketPort):
103
+ async with websockets.serve(handleWebSocket, 'localhost', websocketPort):
104
+ print(f"Starting WebSocket server on port {websocketPort}...")
105
+ await asyncio.Future()
106
+
107
+ async def start_client(clientPort):
108
+ global ws
109
+ output_Msg = st.chat_message("assistant")
110
+ input_Msg = st.chat_message("ai")
111
+ uri = f'ws://localhost:{clientPort}'
112
+ client_ports.append(clientPort)
113
+ async with websockets.connect(uri) as ws:
114
+ while True:
115
+ print(f"Connecting to server at port: {clientPort}...")
116
+ # Listen for messages from the server
117
+ input_message = await ws.recv()
118
+ input_Msg.markdown(input_message)
119
+ output_message = await askQuestion(input_message)
120
+ output_Msg.markdown(output_message)
121
+ await ws.send(json.dumps(output_message))
122
+
123
+ async def handleUser(userInput):
124
+ user_input = st.chat_message("human")
125
+ user_input.markdown(userInput)
126
+ timestamp = datetime.datetime.now().isoformat()
127
+ sender = 'client'
128
+ db = sqlite3.connect('chat-hub.db')
129
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
130
+ (sender, userInput, timestamp))
131
+ db.commit()
132
+ try:
133
+ response = await askQuestion(userInput)
134
+ server_response = st.chat_message("assistant")
135
+ server_response.markdown(response)
136
+ serverSender = 'server'
137
+ timestamp = datetime.datetime.now().isoformat()
138
+ db = sqlite3.connect('chat-hub.db')
139
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
140
+ (serverSender, response, timestamp))
141
+ db.commit()
142
+
143
+ except Exception as e:
144
+ print(f"Error: {e}")
145
+
146
+ # Stop the WebSocket server
147
+ async def stop_websockets():
148
+ global server
149
+ if server:
150
+ # Close all connections gracefully
151
+ server.close()
152
+ # Wait for the server to close
153
+ server.wait_closed()
154
+ print("Stopping WebSocket server...")
155
+ else:
156
+ print("WebSocket server is not running.")
157
+
158
+ # Stop the WebSocket client
159
+ async def stop_client():
160
+ global ws
161
+ # Close the connection with the server
162
+ ws.close()
163
+ print("Stopping WebSocket client...")
164
+
165
+ async def main():
166
+ userInput = st.chat_input("User input")
167
+ websocketPort = st.sidebar.slider('Server port', min_value=1000, max_value=9999, value=1000)
168
+ startServer = st.sidebar.button('Start websocket server')
169
+ clientPort = st.sidebar.slider('Client port', min_value=1000, max_value=9999, value=1000)
170
+ startClient = st.sidebar.button('Connect client to server')
171
+ st.sidebar.text("Server ports:")
172
+ serverPorts = st.sidebar.container(border=True)
173
+ serverPorts.text("Local ports")
174
+ st.sidebar.text("Client ports")
175
+ clientPorts = st.sidebar.container(border=True)
176
+ clientPorts.text("Connected ports")
177
+
178
+ if userInput:
179
+ print(f"User B: {userInput}")
180
+ srvr_response = await handleUser(userInput)
181
+ print(f"Server: {srvr_response}")
182
+
183
+ if startServer:
184
+ server_ports.append(websocketPort)
185
+ serverPorts.markdown(server_ports)
186
+ await start_websockets(websocketPort)
187
+
188
+ if startClient:
189
+ client_ports.append(clientPort)
190
+ clientPorts.markdown(client_ports)
191
+ await start_client(clientPort)
192
+
193
+
194
+ asyncio.run(main())
pages/biedny.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import websockets
3
+ import asyncio
4
+ import sqlite3
5
+ import json
6
+ import g4f
7
+ import streamlit as st
8
+ import fireworks.client
9
+
10
+ import streamlit as st
11
+ from multipage import MultiPage
12
+
13
+ app = MultiPage()
14
+ st.set_page_config(
15
+ page_title='OCR Comparator', layout ="wide",
16
+ initial_sidebar_state="expanded",
17
+ )
18
+
19
+ # Add all your application here
20
+ app.add_page("Home", "house", home.app)
21
+ app.add_page("About", "info-circle", about.app)
22
+ app.add_page("App", "cast", ocr_comparator.app)
23
+
24
+ # The main app
25
+ app.run()
26
+
27
+ servers = {}
28
+ inputs = []
29
+ outputs = []
30
+ used_ports = []
31
+ server_ports = []
32
+ client_ports = []
33
+
34
+ st.set_page_config(layout="wide")
35
+ websocket_server = None
36
+
37
+ GOOGLE_CSE_ID = "f3882ab3b67cc4923"
38
+ GOOGLE_API_KEY = "AIzaSyBNvtKE35EAeYO-ECQlQoZO01RSHWhfIws"
39
+ FIREWORKS_API_KEY = "xbwGxyTyOf7ats2GcEU0Pj62kpZBVZa2r6i5lKbKG99LFG38"
40
+
41
+ # Set up the SQLite database
42
+ db = sqlite3.connect('chat-hub.db')
43
+ cursor = db.cursor()
44
+ cursor.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, message TEXT, timestamp TEXT)')
45
+ db.commit()
46
+
47
+ system_instruction = "You are now integrated with a local websocket server in a project of hierarchical cooperative multi-agent framework called NeuralGPT. Your main job is to coordinate simultaneous work of multiple LLMs connected to you as clients. Each LLM has a model (API) specific ID to help you recognize different clients in a continuous chat thread (template: <NAME>-agent and/or <NAME>-client). Your chat memory module is integrated with a local SQL database with chat history. Your primary objective is to maintain the logical and chronological order while answering incoming messages and to send your answers to the correct clients to maintain synchronization of the question->answer logic. However, please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic."
48
+
49
+ st.set_page_config(layout="wide")
50
+ # Start the WebSocket server
51
+ async def start_websockets(websocketPort):
52
+ async with websockets.serve(handleWebSocket, 'localhost', websocketPort):
53
+ print(f"Starting WebSocket server on port {websocketPort}...")
54
+ await asyncio.Future()
55
+
56
+ async def handleServer(ws):
57
+ instruction = "Hello! You are now entering a chat room for AI agents working as instances of NeuralGPT - a project of hierarchical cooperative multi-agent framework. Keep in mind that you are speaking with another chatbot. Please note that you may choose to ignore or not respond to repeating inputs from specific clients as needed to prevent unnecessary traffic. If you're unsure what you should do, ask the instance of higher hierarchy (server)"
58
+ print('New connection')
59
+ await ws.send(instruction)
60
+ while True:
61
+ message = await ws.recv()
62
+ print(f'Received message: {message}')
63
+ inputMsg = st.chat_message("assistant")
64
+ inputMsg.markdown(message)
65
+ timestamp = datetime.datetime.now().isoformat()
66
+ sender = 'client'
67
+ db = sqlite3.connect('chat-hub.db')
68
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
69
+ (sender, message, timestamp))
70
+ db.commit()
71
+ try:
72
+ response = await chatCompletion(message)
73
+ serverResponse = f"server: {response}"
74
+ outputMsg = st.chat_message("ai")
75
+ print(serverResponse)
76
+ outputMsg.markdown(response)
77
+ timestamp = datetime.datetime.now().isoformat()
78
+ serverSender = 'server'
79
+ db = sqlite3.connect('chat-hub.db')
80
+ db.execute('INSERT INTO messages (sender, message, timestamp) VALUES (?, ?, ?)',
81
+ (serverSender, serverResponse, timestamp))
82
+ db.commit()
83
+ # Append the server response to the server_responses list
84
+ await ws.send(serverResponse)
85
+
86
+ except websockets.exceptions.ConnectionClosedError as e:
87
+ print(f"Connection closed: {e}")
88
+
89
+ except Exception as e:
90
+ print(f"Error: {e}")
91
+
92
+ async def start_client(clientPort):
93
+ global ws
94
+ input_Msg = st.chat_message("ai")
95
+ uri = f'ws://localhost:{clientPort}'
96
+ client_ports.append(clientPort)
97
+ async with websockets.connect(uri) as ws:
98
+ while True:
99
+ print(f"Connecting to server at port: {clientPort}...")
100
+ # Listen for messages from the server
101
+ input_message = await ws.recv()
102
+ output_Msg = st.chat_message("assistant")
103
+ input_Msg.markdown(input_message)
104
+ output_message = await chatCompletion(input_message)
105
+ output_Msg.markdown(output_message)
106
+ await ws.send(json.dumps(output_message))
107
+
108
+ # Stop the WebSocket server
109
+ async def stop_websockets():
110
+ global server
111
+ if server:
112
+ # Close all connections gracefully
113
+ server.close()
114
+ # Wait for the server to close
115
+ server.wait_closed()
116
+ print("Stopping WebSocket server...")
117
+ else:
118
+ print("WebSocket server is not running.")
119
+
120
+ # Stop the WebSocket client
121
+ async def stop_client():
122
+ global ws
123
+ # Close the connection with the server
124
+ ws.close()
125
+ print("Stopping WebSocket client...")
126
+
127
+ st.sidebar.text("Server ports:")
128
+ serverPorts = st.sidebar.container(border=True)
129
+ serverPorts.text("Local ports")
130
+ st.sidebar.text("Client ports")
131
+ clientPorts = st.sidebar.container(border=True)
132
+ clientPorts.text("Connected ports")
133
+
134
+ async def main():
135
+ tab1, tab2, tab3 = st.tabs(["Fireworks", "GPT4Free", "Character.ai"])
136
+
137
+ with tab1:
138
+ st.header("Fireworks Llama2-7B")
139
+ userInput1 = st.chat_input("User input")
140
+ col1, col2 = st.columns([4, 1])
141
+ with col1:
142
+ serverPorts = st.sidebar.container(border=True)
143
+ serverPorts.text("Local ports")
144
+ clientPorts = st.sidebar.container(border=True)
145
+ clientPorts.text("Connected ports")
146
+
147
+ with col2:
148
+ server_Port = st.number_input("Port", 1000)
149
+ client_Port = st.number_input("Port",1000)
150
+
151
+ if userInput1:
152
+ print(f"User B: {userInput1}")
153
+ await handleUser(userInput1)
154
+
155
+ with tab2:
156
+ st.header("A dog")
157
+ st.image("https://static.streamlit.io/examples/dog.jpg", width=200)
158
+
159
+ with tab3:
160
+ st.header("An owl")
161
+ st.image("https://static.streamlit.io/examples/owl.jpg", width=200)
162
+
163
+ asyncio.run(main())
pages/home.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(layout="wide")
4
+
5
+ st.sidebar.title("NeuralGPT")
6
+ st.sidebar.info(
7
+ """
8
+ - GitHub repository: <https://github.com/CognitiveCodes/NeuralGPT>
9
+ """
10
+ )
11
+ async def main():
12
+ st.sidebar.text("Server ports:")
13
+ serverPorts = st.sidebar.container(border=True)
14
+ serverPorts.text("Local ports")
15
+ st.sidebar.text("Client ports")
16
+ clientPorts = st.sidebar.container(border=True)
17
+ clientPorts.text("Connected ports")
18
+
19
+ st.sidebar.title("Contact")
20
+ st.sidebar.info(
21
+ """
22
+ Qiusheng Wu at [wetlands.io](https://wetlands.io) | [GitHub](https://github.com/giswqs) | [Twitter](https://twitter.com/giswqs) | [YouTube](https://www.youtube.com/c/QiushengWu) | [LinkedIn](https://www.linkedin.com/in/qiushengwu)
23
+ """
24
+ )
25
+
26
+ st.title("NeuralGPT")
27
+
28
+ st.markdown(
29
+ """
30
+ This page is supposed to work as interface of a hierarchical cooperative multi-agent frameork/platform called NeuralGPT
31
+
32
+ """
33
+ )
34
+
35
+ st.info("Click on the left sidebar menu to navigate to the different apps.")
36
+
37
+ st.subheader("shit goes in here")
38
+ st.markdown(
39
+ """
40
+ The following stuff is totally random no need to think about it too much.
41
+ """
42
+ )
43
+
44
+ row1_col1, row1_col2 = st.columns(2)
45
+ with row1_col1:
46
+
47
+ st.image("https://i.postimg.cc/gk0LXT5p/earth6.gif")
48
+ st.image("https://i.postimg.cc/kM2d2NcZ/movie-18.gif")
49
+ st.image("https://i.postimg.cc/8z5ccf7z/Screenshot-2022-03-02-21-27-22-566-com-google-android-youtube.jpg")
50
+
51
+ with row1_col2:
52
+ st.image("https://i.postimg.cc/X7nw1tFT/Neural-GPT.gif")
53
+ st.image("https://i.postimg.cc/qBwpKMVh/brain-cell-galaxy.jpg")
54
+ st.image("https://i.postimg.cc/YqvTSppw/dh.gif")
55
+ st.image("https://i.postimg.cc/T1sdWCL2/pyth.png")
pages/takijaki.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import streamlit as st
3
+
4
+
5
+ st.set_page_config(layout="wide")
6
+
7
+ st.sidebar.info(
8
+ """
9
+ - Web App URL: <https://streamlit.gishub.org>
10
+ - GitHub repository: <https://github.com/CognitiveCodes/NeuralGPT/tree/main>
11
+ """
12
+ )
13
+
14
+ st.sidebar.title("Contact")
15
+ st.sidebar.info(
16
+ """
17
+ Qiusheng Wu at [wetlands.io](https://wetlands.io) | [GitHub](https://github.com/giswqs) | [Twitter](https://twitter.com/giswqs) | [YouTube](https://www.youtube.com/c/QiushengWu) | [LinkedIn](https://www.linkedin.com/in/qiushengwu)
18
+ """
19
+ )
20
+
21
+ st.title("Comparing Global Land Cover Maps")
22
+
23
+ col1, col2 = st.columns([4, 1])
24
+
25
+ esa = st.text_area()
26
+ esa_vis = {"bands": ["Map"]}
27
+
28
+ markdown = """
29
+ - [Dynamic World Land Cover](https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_DYNAMICWORLD_V1?hl=en)
30
+ - [ESA Global Land Cover](https://developers.google.com/earth-engine/datasets/catalog/ESA_WorldCover_v100)
31
+ - [ESRI Global Land Cover](https://samapriya.github.io/awesome-gee-community-datasets/projects/esrilc2020)
32
+ """
33
+
34
+ with col2:
35
+
36
+ server_Port = st.number_input("Port", 1000)
37
+ clientP_ort = st.number_input("Port",1000)
38
+ zoom = st.number_input("Zoom", 0, 20, 11)
39
+
40
+ start = st.date_input("Start Date for Dynamic World", datetime.date(2020, 1, 1))
41
+ end = st.date_input("End Date for Dynamic World", datetime.date(2021, 1, 1))
42
+
43
+ start_date = start.strftime("%Y-%m-%d")
44
+ end_date = end.strftime("%Y-%m-%d")
45
+
46
+ if legend == "Dynamic World":
47
+ Map.add_legend(
48
+ title="Dynamic World Land Cover",
49
+ builtin_legend="Dynamic_World",
50
+ )
51
+ elif legend == "ESA Land Cover":
52
+ Map.add_legend(title="ESA Land Cover", builtin_legend="ESA_WorldCover")
53
+ elif legend == "ESRI Land Cover":
54
+ Map.add_legend(title="ESRI Land Cover", builtin_legend="ESRI_LandCover")
55
+
56
+ with st.expander("Data sources"):
57
+ st.markdown(markdown)
58
+
59
+
60
+ with col1:
61
+ Map.to_streamlit(height=750)