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
|
#!/bin/bash
|
||||||
set -e
|
|
||||||
|
|
||||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
@@ -21,42 +20,21 @@ if [ -z "$PYTHON" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
VENV_DIR="$DIR/venv"
|
VENV_DIR="$DIR/venv"
|
||||||
VENV_OK=false
|
|
||||||
|
|
||||||
# Verifica se o venv existe e e funcional
|
# Verifica se o venv e funcional
|
||||||
if [ -f "$VENV_DIR/bin/activate" ]; then
|
if [ -f "$VENV_DIR/bin/activate" ] && $PYTHON -c "import flask" 2>/dev/null; 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
|
|
||||||
echo "[1/3] Ambiente virtual funcional."
|
echo "[1/3] Ambiente virtual funcional."
|
||||||
|
source "$VENV_DIR/bin/activate"
|
||||||
else
|
else
|
||||||
# Verifica se podemos criar venv
|
echo "[1/2] Instalando dependencias..."
|
||||||
if $PYTHON -m venv --help &>/dev/null 2>&1; then
|
$PYTHON -m pip install --upgrade pip -q 2>/dev/null || true
|
||||||
if $PYTHON -m venv "$VENV_DIR" 2>/dev/null; then
|
$PYTHON -m pip install -r "$DIR/requirements.txt" -q --break-system-packages 2>/dev/null || \
|
||||||
source "$VENV_DIR/bin/activate"
|
$PYTHON -m pip install -r "$DIR/requirements.txt" -q 2>/dev/null || {
|
||||||
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 "[!] Erro ao instalar dependencias."
|
echo "[!] Erro ao instalar dependencias."
|
||||||
|
echo " Tente: pip install -r requirements.txt"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
echo "[2/2] Dependencias instaladas globalmente."
|
echo "[2/2] Dependencias instaladas."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[4/4] Iniciando aplicacao Flask..."
|
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() {
|
async function endChat() {
|
||||||
appendMessage('user', '/encerrar');
|
appendMessage('user', '/encerrar');
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/end', { method: 'POST' });
|
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;
|
|
||||||
} catch (err) {
|
} 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();
|
input.focus();
|
||||||
|
|||||||
Reference in New Issue
Block a user