Spaces:
Sleeping
Sleeping
File size: 6,031 Bytes
dcb405d 2c3e352 dcb405d 2c3e352 fb979a6 2c3e352 fb979a6 2c3e352 fb979a6 2c3e352 dcb405d a38ceac 149362e a38ceac 149362e a38ceac 149362e a38ceac 149362e a38ceac |
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 |
import os
import requests
import ctypes
import streamlit as st
def download_so():
url = "https://github.com/AlineIoste/teste/raw/main/SynapseControl.cpython-38-x86_64-linux-gnu.so"
current_dir = os.path.dirname(os.path.abspath(__file__))
output_path = os.path.join(current_dir, "SynapseControl.cpython-38-x86_64-linux-gnu.so")
# Verifique se o diretório existe, se não, crie-o
os.makedirs(os.path.dirname(output_path), exist_ok=True)
if not os.path.exists(output_path):
response = requests.get(url)
response.raise_for_status() # Para garantir que o download foi bem-sucedido
with open(output_path, 'wb') as f:
f.write(response.content)
st.write(f"Downloaded {url} to {output_path}")
else:
st.write(f"File already exists at {output_path}")
# Execute o download
download_so()
# Verifique se o arquivo foi baixado corretamente
current_dir = os.path.dirname(os.path.abspath(__file__))
output_path = os.path.join(current_dir, "SynapseControl.cpython-38-x86_64-linux-gnu.so")
if os.path.exists(output_path):
st.write("File downloaded successfully.")
else:
st.write("Failed to download the file.")
# Carregar a biblioteca compartilhada usando ctypes
try:
lib = ctypes.CDLL(output_path)
# Verificar e definir as funções
if hasattr(lib, 'Initial_Memory'):
Initial_Memory = lib.Initial_Memory
Initial_Memory.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]
Initial_Memory.restype = ctypes.c_void_p
st.write("Initial_Memory function loaded successfully.")
else:
st.write("Initial_Memory function not found in the library.")
if hasattr(lib, 'Synapses_Active'):
Synapses_Active = lib.Synapses_Active
Synapses_Active.argtypes = [ctypes.c_char_p, ctypes.c_void_p]
Synapses_Active.restype = ctypes.c_void_p
st.write("Synapses_Active function loaded successfully.")
else:
st.write("Synapses_Active function not found in the library.")
if hasattr(lib, 'ExecuteModel'):
ExecuteModel = lib.ExecuteModel
ExecuteModel.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p, ctypes.c_void_p]
ExecuteModel.restype = ctypes.c_char_p
st.write("ExecuteModel function loaded successfully.")
else:
st.write("ExecuteModel function not found in the library.")
except Exception as e:
st.write(f"Error loading library: {e}")
import keys as key
import sys
import os
import streamlit as st
import inspect
import keys as key
st.title("Neurocognitive Structures")
def CienciaComputacao_chat():
st.session_state.clear()
st.session_state["knowleadge_base"] = 'KB_geral.txt'
st.session_state["persona"] = 'Como um Medico americano'
st.session_state["language"] = "Inglês"
st.session_state["human_contact"] = " no telefone do consultório disponivel no site www.drLecun.com.br "
st.session_state["model"] = "gpt-4o-mini" # gpt-4o-mini or sabia-3 gpt-3.5-turbo
st.session_state["company"] = "OpenAI" # OpenAI OR MARITACA
st.session_state["max_token"] = 500
st.session_state["api_key"] = key.OPEN_API_KEY
# Colocar os botões na barra lateral
with st.sidebar:
#st.image('IME.png', caption='Programa de Pós-graduação - IME')
st.write("Escolha o tipo de chat:")
if st.button("Ciência da Computação", on_click=CienciaComputacao_chat):
st.write("O chat do Programa de Pós-graduação de Ciência da Computação iniciado.")
if st.button("Resetar sessão"):
st.session_state.clear()
st.write("Sessão resetada.")
if "knowleadge_base" not in st.session_state:
st.session_state["knowleadge_base"] = ""
if st.session_state["knowleadge_base"] != "":
# Inicialize st.session_state.messages se ainda não estiver definido
if 'messages' not in st.session_state:
st.session_state.messages = []
st.session_state.messages = Initial_Memory(st.session_state.messages,
st.session_state["knowleadge_base"],
st.session_state["persona"],
st.session_state["language"],
st.session_state["human_contact"])
# Função para exibir mensagens ao usuário
def display_messages(messages):
ava= ''
for message in messages:
if message["role"] != "system": # Exibe apenas mensagens não-sistêmicas
if message["role"]=="user":
ava=new_avatar
else:
ava=new_user
with st.chat_message(message["role"]):
st.markdown((message["content"]))
# Exibir mensagens ao usuário
display_messages(st.session_state.messages)
#st.write(st.session_state.messages)
# Capturar entrada do usuário
if prompt := st.chat_input("Como posso te ajudar?"):
acao = Synapses_Active(prompt, st.session_state.messages)
st.session_state.messages = acao
#st.markdown(acao) #retirar depois
with st.chat_message("user"):
st.markdown(prompt)
# Simular a resposta do assistente
with st.chat_message("assistant"):
stream = ExecuteModel(st.session_state["model"],
st.session_state["company"],
st.session_state["max_token"],
st.session_state["api_key"],
st.session_state.messages
)
response = st.write_stream(stream)
st.session_state.messages.append({"role": "assistant", "content": response})
if "END" in response:
st.session_state.clear() |