Spaces:
Sleeping
Sleeping
import os | |
import sqlite3 | |
import websockets | |
import json | |
import asyncio | |
import time | |
import conteneiro | |
import streamlit as st | |
from AgentGPT import AgentsGPT | |
from agents import Llama2, Copilot, ChatGPT, Claude3, ForefrontAI, Flowise, Chaindesk, CharacterAI | |
st.set_page_config(layout="wide") | |
servers = {} | |
clients = {} | |
inputs = [] | |
outputs = [] | |
used_ports = [] | |
server_ports = [] | |
client_ports = [] | |
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 "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 "api_key" not in st.session_state: | |
st.session_state.api_key = "" | |
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 "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" | |
userInput = st.chat_input("Ask Agent") | |
with st.expander("Personal API tokens"): | |
fireworks_api = st.text_input("Fireworks API") | |
forefront_api = st.text_input("Forefront AI API") | |
anthropic_api = st.text_input("Anthropic API") | |
characterToken = st.text_input("Character.ai personal token") | |
character_ID = st.text_input("Character ID") | |
chaindeskAgent = st.text_input("Chaindesk agent ID") | |
flowID = st.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 selectAgent == "Llama2": | |
if userInput: | |
print(f"User B: {userInput}") | |
user_input = st.chat_message("human") | |
user_input.markdown(userInput) | |
agent = Llama2(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(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(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(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(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(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(anthropic_api) | |
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(anthropic_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"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(anthropic_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 == "Character.ai": | |
if userInput: | |
print(f"User B: {userInput}") | |
user_input = st.chat_message("human") | |
user_input.markdown(userInput) | |
agent = CharacterAI(characterToken, character_ID) | |
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(characterToken, character_ID) | |
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(characterToken, character_ID) | |
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(chaindeskAgent) | |
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(chaindeskAgent) | |
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(chaindeskAgent) | |
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(flowID) | |
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(flowID) | |
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(flowID) | |
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()) |