refactor(scripts): simplifica lógica de inicialização e adapta encerramento de chat
Simplifica o script de inicialização removendo detecção complexa de venv e lógica de fallback, mantendo apenas o fluxo essencial de verificação e instalação de dependências. Adapta a interface de encerramento de chat para não aguardar resposta do servidor, considerando que o mesmo é desligado após o término da conversa.
This commit is contained in:
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+9
-31
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
@@ -21,42 +20,21 @@ if [ -z "$PYTHON" ]; then
|
||||
fi
|
||||
|
||||
VENV_DIR="$DIR/venv"
|
||||
VENV_OK=false
|
||||
|
||||
# Verifica se o venv existe e e funcional
|
||||
if [ -f "$VENV_DIR/bin/activate" ]; then
|
||||
source "$VENV_DIR/bin/activate" 2>/dev/null || true
|
||||
if $PYTHON -c "import flask" 2>/dev/null; then
|
||||
VENV_OK=true
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$VENV_OK" = true ]; then
|
||||
# Verifica se o venv e funcional
|
||||
if [ -f "$VENV_DIR/bin/activate" ] && $PYTHON -c "import flask" 2>/dev/null; then
|
||||
echo "[1/3] Ambiente virtual funcional."
|
||||
source "$VENV_DIR/bin/activate"
|
||||
else
|
||||
# Verifica se podemos criar venv
|
||||
if $PYTHON -m venv --help &>/dev/null 2>&1; then
|
||||
if $PYTHON -m venv "$VENV_DIR" 2>/dev/null; then
|
||||
source "$VENV_DIR/bin/activate"
|
||||
echo "[1/4] Ambiente virtual criado."
|
||||
echo "[2/4] Instalando dependencias..."
|
||||
pip install --upgrade pip -q 2>/dev/null || true
|
||||
pip install -r "$DIR/requirements.txt" -q
|
||||
echo "[3/4] Dependencias instaladas."
|
||||
VENV_OK=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$VENV_OK" = false ]; then
|
||||
echo "[!] Ambiente virtual indisponivel (sem python3-venv ou permissao negada)."
|
||||
echo "[1/2] Instalando dependencias globalmente..."
|
||||
$PYTHON -m pip install -r "$DIR/requirements.txt" -q 2>/dev/null || \
|
||||
$PYTHON -m pip install -r "$DIR/requirements.txt" -q --break-system-packages 2>/dev/null || {
|
||||
echo "[1/2] Instalando dependencias..."
|
||||
$PYTHON -m pip install --upgrade pip -q 2>/dev/null || true
|
||||
$PYTHON -m pip install -r "$DIR/requirements.txt" -q --break-system-packages 2>/dev/null || \
|
||||
$PYTHON -m pip install -r "$DIR/requirements.txt" -q 2>/dev/null || {
|
||||
echo "[!] Erro ao instalar dependencias."
|
||||
echo " Tente: pip install -r requirements.txt"
|
||||
exit 1
|
||||
}
|
||||
echo "[2/2] Dependencias instaladas globalmente."
|
||||
echo "[2/2] Dependencias instaladas."
|
||||
fi
|
||||
|
||||
echo "[4/4] Iniciando aplicacao Flask..."
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+7
-8
@@ -960,16 +960,15 @@ async function clearChat() {
|
||||
async function endChat() {
|
||||
appendMessage('user', '/encerrar');
|
||||
try {
|
||||
const res = await fetch('/end', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
chatEl.innerHTML = '';
|
||||
appendMessage('ai', data.reply || 'Chat encerrado. Recarregue a página para começar novamente.');
|
||||
input.value = '';
|
||||
input.disabled = true;
|
||||
sendBtn.disabled = true;
|
||||
await fetch('/end', { method: 'POST' });
|
||||
} catch (err) {
|
||||
appendMessage('system', 'Erro ao encerrar.');
|
||||
// servidor encerrado - esperado
|
||||
}
|
||||
chatEl.innerHTML = '';
|
||||
appendMessage('ai', 'Chat encerrado. Recarregue a página ou inicie o servidor novamente.');
|
||||
input.value = '';
|
||||
input.disabled = true;
|
||||
sendBtn.disabled = true;
|
||||
}
|
||||
|
||||
input.focus();
|
||||
|
||||
Reference in New Issue
Block a user