Arcypojeb commited on
Commit
2b61a68
1 Parent(s): a916afb

Delete pages/biedny.py

Browse files
Files changed (1) hide show
  1. pages/biedny.py +0 -163
pages/biedny.py DELETED
@@ -1,163 +0,0 @@
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())