Spaces:
Sleeping
Sleeping
File size: 25,737 Bytes
195cf71 d12621c 195cf71 d12621c 195cf71 d12621c 195cf71 e26a90f 195cf71 d12621c 195cf71 d12621c 195cf71 d12621c 195cf71 d12621c 195cf71 d12621c 195cf71 d12621c 195cf71 d12621c cca3c5c 5de28fb cca3c5c 195cf71 cca3c5c d12621c cca3c5c d12621c 195cf71 cca3c5c 195cf71 cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 7f1092d cca3c5c 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 7f1092d 195cf71 |
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
import os
import sqlite3
import websockets
import json
import asyncio
import time
import conteneiro
import streamlit as st
from io import StringIO
from agents import Llama2, Copilot, ChatGPT, Claude3, ForefrontAI, Flowise, Chaindesk, CharacterAI
st.set_page_config(layout="wide")
servers = []
clients = []
inputs = []
outputs = []
used_ports = []
credentials = []
server_ports = []
client_ports = []
# Set up the SQLite database
db = sqlite3.connect('chat-hub.db')
db.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, message TEXT, timestamp TEXT)')
async def main():
if "googleAPI" not in st.session_state:
st.session_state.googleAPI = ""
if "cseID" not in st.session_state:
st.session_state.cseID = ""
if "api_key" not in st.session_state:
st.session_state.api_key = ""
if "fireworks_api" not in st.session_state:
st.session_state.fireworks_api = ""
if "anthropicAPI" not in st.session_state:
st.session_state.anthropicAPI = ""
if "server_ports" not in st.session_state:
st.session_state['server_ports'] = ""
if "client_ports" not in st.session_state:
st.session_state['client_ports'] = ""
if "servers" not in st.session_state:
st.session_state['servers'] = ""
if "clients" not in st.session_state:
st.session_state['clients'] = ""
if "gradio_Port" not in st.session_state:
st.session_state.gradio_Port = ""
if "server" not in st.session_state:
st.session_state.server = False
if "client" not in st.session_state:
st.session_state.client = False
if "user_ID" not in st.session_state:
st.session_state.user_ID = ""
if "gradio_Port" not in st.session_state:
st.session_state.gradio_Port = ""
if "forefront_api" not in st.session_state:
st.session_state.forefront_api = ""
if "tokenChar" not in st.session_state:
st.session_state.tokenChar = ""
if "charName" not in st.session_state:
st.session_state.charName = ""
if "character_ID" not in st.session_state:
st.session_state.character_ID = ""
if "flow" not in st.session_state:
st.session_state.flow = ""
if "agentID" not in st.session_state:
st.session_state.agentID = ""
if "tokens" not in st.session_state:
st.session_state.tokens = None
if 'credentials' not in st.session_state:
st.session_state.credentials = []
if "server_state" not in st.session_state:
st.session_state.server_state = "complete"
if "client_state" not in st.session_state:
st.session_state.client_state = "complete"
APItokens = {
"APIfireworks": str(st.session_state.fireworks_api),
"APIforefront": str(st.session_state.forefront_api),
"APIanthropic": str(st.session_state.anthropicAPI),
"TokenCharacter": str(st.session_state.tokenChar),
"char_ID": str(st.session_state.character_ID),
"chaindeskID": str(st.session_state.agentID),
"FlowiseID": str(st.session_state.flow)
}
json_credentials = json.dumps(APItokens)
print(json_credentials)
userInput = st.chat_input("Ask Agent")
with st.expander("Personal API tokens"):
uploadAPI = st.file_uploader(label="Upload credentials")
fire = st.empty()
fore = st.empty()
anthro = st.empty()
char = st.empty()
charID = st.empty()
chain = st.empty()
flo = st.empty()
saveAPI = st.download_button(label="Download API tokens",
data=json_credentials,
file_name=f"APItokens.json",
mime="application/json",
help="Click to save your API keys")
if st.session_state.tokens == None:
fireworks_api = fire.text_input("Fireworks API")
forefront_api = fore.text_input("Forefront AI API")
anthropic_api = anthro.text_input("Anthropic API")
characterToken = char.text_input("Character.ai personal token")
character_ID = charID.text_input("Character ID")
chaindeskAgent = chain.text_input("Chaindesk agent ID")
flowID = flo.text_input("Flowise flow ID")
c1, c2 = st.columns(2)
selectAgent = st.selectbox("Select agent", ("Llama2", "Copilot", "ChatGPT", "Forefront AI", "Claude-3", "Character.ai", "Chaindesk", "Flowise"))
with c1:
websocketPort = st.number_input("Websocket server port", min_value=1000, max_value=9999, value=1000)
startServer = st.button("Start server")
stopServer = st.button("Stop server")
st.text("Servers")
serverPorts1 = st.empty()
serverPorts = serverPorts1.status(label="websocket servers", state="complete", expanded=False)
serverPorts.write(conteneiro.servers)
with c2:
clientPort = st.number_input("Websocket client port", min_value=1000, max_value=9999, value=1000)
runClient = st.button("Start client")
stopClient = st.button("Stop client")
st.text("Websocket clients")
clientPorts1 = st.empty()
clientPorts = clientPorts1.status(label="websocket clients", state="complete", expanded=False)
clientPorts.write(conteneiro.clients)
with st.sidebar:
# Wyświetlanie danych, które mogą być modyfikowane na różnych stronach
st.text("Websocket servers")
srv_status = st.empty()
server_status1 = srv_status.status(label="websocket servers", state="complete", expanded=True)
server_status1.write(conteneiro.servers)
if st.session_state.server == True:
st.session_state.server_state = "running"
srv_status.empty()
server_status1 = srv_status.status(label="websocket servers", state=st.session_state.server_state, expanded=True)
server_status1.write(conteneiro.servers)
st.text("Websocket clients")
cli_status = st.empty()
client_status1 = cli_status.status(label="websocket clients", state="complete", expanded=True)
client_status1.write(conteneiro.clients)
if st.session_state.client == True:
st.session_state.client_state = "running"
cli_status.empty()
client_status1 = cli_status.status(label="websocket clients", state=st.session_state.client_state, expanded=True)
client_status1.write(conteneiro.clients)
if uploadAPI is not None:
data = json.load(uploadAPI)
print(data)
st.session_state.fireworks_api = data["APIfireworks"]
if st.session_state.fireworks_api == "":
fireworks_api = fire.text_input("Fireworks API key")
else:
fireworks_api = fire.container(border=True)
fireworks_api.write(str(st.session_state.fireworks_api))
st.session_state.forefront_api = data["APIforefront"]
if st.session_state.forefront_api == "":
forefront_api = fore.text_input("Forefront API key")
else:
forefront_api = fore.container(border=True)
forefront_api.write(str(st.session_state.forefront_api))
st.session_state.anthropicAPI = data["APIanthropic"]
if st.session_state.anthropicAPI == "":
anthropic_api = anthro.text_input("Anthropic API key")
else:
anthropic_api = anthro.container(border=True)
anthropic_api.write(str(st.session_state.anthropicAPI))
st.session_state.tokenChar = data["TokenCharacter"]
if st.session_state.tokenChar == "":
characterToken = char.text_input("Character.ai user token")
else:
characterToken = char.container(border=True)
characterToken.write(str(st.session_state.tokenChar))
st.session_state.character_ID = data["char_ID"]
if st.session_state.character_ID == "":
character_ID = charID.text_input("Your Character ID")
else:
character_ID = charID.container(border=True)
character_ID.write(str(st.session_state.character_ID))
st.session_state.agentID = data["chaindeskID"]
if st.session_state.agentID == "":
chaindeskAgent = chain.text_input("Chaindesk agent ID:")
else:
chaindeskAgent = chain.container(border=True)
chaindeskAgent.write(str(st.session_state.agentID))
st.session_state.flow = data["FlowiseID"]
if st.session_state.flow == "":
flowID = flo.text_input("Flowise flow ID:")
else:
flowID = flo.container(border=True)
flowID.write(str(st.session_state.flow))
if saveAPI:
credentials.clear()
st.session_state.fireworks_api = fireworks_api
credentials.append(st.session_state.fireworks_api)
st.session_state.forefront_api = forefront_api
credentials.append(st.session_state.forefront_api)
st.session_state.anthropicAPI = anthropic_api
credentials.append(st.session_state.anthropicAPI)
st.session_state.tokenChar = characterToken
credentials.append(st.session_state.tokenChar)
st.session_state.character_ID = character_ID
credentials.append(st.session_state.character_ID)
st.session_state.agentID = chaindeskAgent
credentials.append(st.session_state.agentID)
st.session_state.flow = flowID
credentials.append(st.session_state.flow)
if selectAgent == "Llama2":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = Llama2(str(st.session_state.fireworks_api))
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Llama2 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = Llama2(str(st.session_state.fireworks_api))
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Llama2 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = Llama2(str(st.session_state.fireworks_api))
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Copilot":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = Copilot()
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name1 = f"Copilot client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name1, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name1, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = Copilot()
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name1 = f"Copilot server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label="websocket servers", state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label="websocket servers", state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = Copilot()
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "ChatGPT":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = ChatGPT()
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name2 = f"GPT-3,5 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name2, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name2, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = ChatGPT()
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name2 = f"GPT-3,5 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name2, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name2, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = ChatGPT()
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Forefront AI":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = ForefrontAI(str(st.session_state.forefront_api))
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Forefront AI client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = ForefrontAI(str(st.session_state.forefront_api))
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Forefroont AI server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = ForefrontAI(str(st.session_state.forefront_api))
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Claude-3":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = Claude3(str(st.session_state.anthropicAPI))
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Claude-3 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = Claude3(str(st.session_state.anthropicAPI))
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Claude-3 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = Claude3(str(st.session_state.anthropicAPI))
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Character.ai":
usrToken = str(st.session_state.tokenChar)
charID = str(st.session_state.character_ID)
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = CharacterAI(usrToken, charID)
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Claude-3 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = CharacterAI(usrToken, charID)
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Claude-3 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = CharacterAI(usrToken, charID)
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Chaindesk":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = Chaindesk(str(st.session_state.agentID))
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Claude-3 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = Chaindesk(str(st.session_state.agentID))
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Claude-3 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = Chaindesk(str(st.session_state.agentID))
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if selectAgent == "Flowise":
if userInput:
print(f"User B: {userInput}")
user_input = st.chat_message("human")
user_input.markdown(userInput)
agent = Flowise(str(st.session_state.flow))
results = await agent.handleInput(userInput)
print(results)
if runClient:
st.session_state.client = True
cli_name = f"Claude-3 client port: {clientPort}"
cli_status.empty()
client_status1 = cli_status.status(label=cli_name, state="running", expanded=True)
client_status1.write(conteneiro.clients)
clientPorts1.empty()
clientPorts = clientPorts1.status(label=cli_name, state="running", expanded=True)
clientPorts.write(conteneiro.clients)
try:
client = Flowise(str(st.session_state.flow))
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
st.session_state.server = True
srv_name = f"Claude-3 server port: {websocketPort}"
srv_status.empty()
server_status1 = srv_status.status(label=srv_name, state="running", expanded=True)
server_status1.write(conteneiro.servers)
serverPorts1.empty()
serverPorts = serverPorts1.status(label=srv_name, state="running", expanded=True)
serverPorts.write(conteneiro.servers)
try:
server = Flowise(str(st.session_state.flow))
await server.start_server(websocketPort)
print(f"Starting WebSocket server on port {websocketPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
asyncio.run(main()) |