Spaces:
Sleeping
Sleeping
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() |