Ferdlance's picture
Initial commit for the DevSecOps bot
62a0596
raw
history blame
4.26 kB
#!/bin/bash
# --- Couleurs pour l'affichage ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# --- Fonctions d'affichage ---
step() { echo -e "${GREEN}[ÉTAPE]${NC} $1"; }
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
warning() { echo -e "${YELLOW}[AVERTISSEMENT]${NC} $1"; }
error() { echo -e "${RED}[ERREUR]${NC} $1"; }
# Vérifier si on est root
if [[ $EUID -eq 0 ]]; then
error "Ne pas exécuter ce script en tant que root. Veuillez utiliser un utilisateur normal."
exit 1
fi
# Supprimer l'arborescence et l'environnement existants pour une installation propre
step "Suppression de l'environnement existant et de l'arborescence..."
rm -rf data logs config server scripts models .kaggle venv
info "Nettoyage terminé."
# --- Étape 1 : Création de l'arborescence du projet ---
step "Création de l'arborescence du projet..."
mkdir -p data/devsecops/qa
mkdir -p data/security/qa
mkdir -p data/development/qa
mkdir -p data/data_analysis/qa
mkdir -p logs
mkdir -p config
mkdir -p server
mkdir -p scripts
mkdir -p models
mkdir -p llama.cpp # Ajout du dossier pour llama.cpp
mkdir -p .kaggle
info "Arborescence créée."
# --- Étape 2 : Installation des dépendances système ---
step "Installation des dépendances système (peut nécessiter votre mot de passe)..."
sudo apt update
sudo apt install -y python3 python3-pip python3-venv cmake build-essential git aria2
info "Dépendances système installées."
# --- Étape 3 : Création et activation de l'environnement virtuel ---
step "Création de l'environnement virtuel..."
python3 -m venv venv
info "Environnement virtuel créé."
source venv/bin/activate
info "Environnement virtuel activé."
# --- Étape 4 : Création du fichier requirements.txt et installation des dépendances ---
step "Génération et installation des dépendances Python..."
# Note : j'ai ajouté 'python-dotenv' pour gérer les variables d'environnement
cat << EOF > requirements.txt
streamlit
pandas
plotly
beautifulsoup4
html2text
requests
kaggle
python-dotenv
lxml
matplotlib
EOF
pip install -r requirements.txt
info "Dépendances Python installées."
# --- Étape 5 : Création des fichiers de configuration ---
step "Création du fichier de configuration 'config/app_config.py'..."
cat << EOF > config/app_config.py
# app_config.py
import os
from pathlib import Path
import streamlit as st
from dotenv import load_dotenv
def setup_dotenv():
env_dir = Path("config")
env_dir.mkdir(exist_ok=True)
env_path = env_dir / ".env"
if not env_path.exists():
with open(env_path, 'w') as f:
f.write("# Configuration du serveur LLM et des clés API\n")
f.write("LLM_SERVER_URL=http://localhost:8080/completion\n")
f.write("GITHUB_API_TOKEN=\n")
f.write("HUGGINGFACE_API_TOKEN=\n")
f.write("NVD_API_KEY=\n")
f.write("STACK_EXCHANGE_API_KEY=\n")
load_dotenv(dotenv_path=env_path)
setup_dotenv()
LLM_SERVER_URL = os.getenv('LLM_SERVER_URL', 'http://localhost:8080/completion')
def init_session_state():
if 'bot_status' not in st.session_state:
st.session_state.bot_status = "Arrêté"
if 'server_status' not in st.session_state:
st.session_state.server_status = "Inactif"
if 'total_qa_pairs' not in st.session_state:
st.session_state.total_qa_pairs = 0
if 'logs' not in st.session_state:
st.session_state.logs = []
if 'qa_data' not in st.session_state:
st.session_state.qa_data = []
if 'enable_enrichment' not in st.session_state:
st.session_state.enable_enrichment = True
if 'min_relevance' not in st.session_state:
st.session_state.min_relevance = 70
if 'num_queries' not in st.session_state:
st.session_state.num_queries = 5
if 'temperature' not in st.session_state:
st.session_state.temperature = 0.7
if 'n_predict' not in st.session_state:
st.session_state.n_predict = 512
REQUEST_COUNT = 0
MAX_REQUESTS_BEFORE_PAUSE = 15
MIN_PAUSE = 2
MAX_PAUSE = 5
USE_API_KEYS = True
EOF
info "Fichier de configuration créé."
# --- Étape 6 : Lancement de l'application Streamlit ---
step "Lancement de l'application app.py..."
./venv/bin/streamlit run app.py