Spaces:
Sleeping
Sleeping
File size: 3,322 Bytes
fa6badb |
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 |
import json
import datetime
import sqlite3
import asyncio
import requests
import conteneiro
import websockets
import streamlit as st
from agentLangchain import langchainAgent
servers = []
clients = []
inputs = []
outputs = []
messagess = []
intentios = []
used_ports = []
server_ports = []
client_ports = []
db = sqlite3.connect('chat-hub.db')
cursor = db.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS messages (id INTEGER PRIMARY KEY AUTOINCREMENT, sender TEXT, message TEXT, timestamp TEXT)')
db.commit()
async def main():
userInput = st.chat_input("Ask Agent")
c1, c2 = st.columns(2)
fireAPI = st.text_input("Fireworks API")
with c1:
stat1 = st.empty()
state1 = stat1.status(label="Langchain", state="complete", expanded=False)
state1.write(conteneiro.servers)
websocketPort = st.number_input("Websocket servers", min_value=1000, max_value=9999, value=1000)
startServer = st.button("Start server")
stopServer = st.button("Stop server")
with c2:
stat2 = st.empty()
state2 = stat2.status(label="Langchain", state="complete", expanded=False)
state2.write(conteneiro.clients)
clientPort = st.number_input("Websocket clients", min_value=1000, max_value=9999, value=1000)
start_Client = st.button("Start client")
stopClient = st.button("Stop client")
with st.sidebar:
cont = st.empty()
status = cont.status(label="Langchain", state="complete", expanded=False)
if userInput:
user_input = st.chat_message("human")
user_input.markdown(userInput)
messagess.append(user_input)
agent = langchainAgent(fireAPI)
response = await agent.askQuestion(userInput)
outputMsg = st.chat_message("ai")
outputMsg.markdown(response)
await agent.handleInput(response)
if start_Client:
voiceCli = f"Langchain client port: {clientPort}"
stat2.empty()
state2 = stat2.status(label=voiceCli, state="running", expanded=True)
state2.write(conteneiro.clients)
cont.empty()
status = cont.status(label=voiceCli, state="running", expanded=True)
status.write(conteneiro.servers)
try:
client = langchainAgent(fireAPI)
await client.startClient(clientPort)
print(f"Connecting client on port {clientPort}...")
await asyncio.Future()
except Exception as e:
print(f"Error: {e}")
if startServer:
vooiceSrv = f"Langchain server pport: {websocketPort}"
stat1.empty()
state1 = stat1.status(label=vooiceSrv, state="running", expanded=False)
state1.write(conteneiro.clients)
cont.empty()
status = cont.status(label=vooiceSrv, state="running", expanded=False)
status.write(conteneiro.clients)
try:
server = langchainAgent(fireAPI)
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()) |