@echo off
cd /d "%~dp0"
SET PYTHON_VERSION=3.11.6
SET PYTHON_EXE=%LocalAppData%\Programs\Python\Python311\python.exe

echo ==========================================
echo Verification de Python
echo ==========================================

REM Vérifier si python.exe existe dans le bon dossier
if exist "%PYTHON_EXE%" (
    echo Python trouve : %PYTHON_EXE%
) else (
    echo Python %PYTHON_VERSION% non trouve, telechargement...

    powershell -Command "Invoke-WebRequest https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe -OutFile python_installer.exe"

    echo Installation de Python...
    python_installer.exe /quiet InstallAllUsers=0 PrependPath=1
    del python_installer.exe

    REM Vérifier encore une fois après installation
    if not exist "%PYTHON_EXE%" (
        echo ERREUR : Python ne s'est pas installe correctement.
        pause
        exit /b 1
    )
)

echo.
echo ==========================================
echo Creation de l'environnement virtuel
echo ==========================================

if not exist venv (
    "%PYTHON_EXE%" -m venv venv
)

echo.
echo ==========================================
echo Activation de l'environnement
echo ==========================================

call venv\Scripts\activate

echo.
echo ==========================================
echo Installation des dependances
echo ==========================================


REM ---- INSTALLATION ET MISE A JOUR DE PIP ----
python -m pip install --upgrade pip

REM ---- INSTALLATION DES AUTRES LIBS ----
pip install -r requirements.txt

pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126


echo ==========================================
echo Lancement jupyter notebook
echo ==========================================

jupyter notebook

pause