Skip to content

Instantly share code, notes, and snippets.

@RchGrav
Last active November 18, 2021 19:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RchGrav/8bb3769a825540a4587e73ce6ea26053 to your computer and use it in GitHub Desktop.
Save RchGrav/8bb3769a825540a4587e73ce6ea26053 to your computer and use it in GitHub Desktop.
Setup Neural Net
@echo off
REM Does generate.py exist, if so lets assume all of this script has been ran already and just execute the demo.
if exist %~dp0generate.py goto launch
REM If this script wasn't run in the context needed to install needed components lets prompt the user for their permission to do so.
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
REM Deploy Chocolatey ( https://chocolatey.org/install )
powershell.exe Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
REM Download and install VC Runtime, debugged this script in a 100% clean VM and this was a prereq, it would be rare that you dont have this but it won't hurt.
powershell.exe $client = new-object System.Net.WebClient; $client.DownloadFile("'https://aka.ms/vs/16/release/vc_redist.x64.exe','vc_redist.x64.exe'")
vc_redist.x64.exe /passive /norestart
del vc_redist.x64.exe
REM Some jiggery pokery to reload the environment paths etc without closing and relaunching shell after deploying chocolatey.
echo Set oShell = WScript.CreateObject("WScript.Shell") > %~dp0resetvars.vbs
echo filename = oShell.ExpandEnvironmentStrings("%TEMP%\resetvars.bat") >> %~dp0resetvars.vbs
echo Set objFileSystem = CreateObject("Scripting.fileSystemObject") >> %~dp0resetvars.vbs
echo Set oFile = objFileSystem.CreateTextFile(filename, TRUE) >> %~dp0resetvars.vbs
echo. >> %~dp0resetvars.vbs
echo set oEnv=oShell.Environment("System") >> %~dp0resetvars.vbs
echo for each sitem in oEnv >> %~dp0resetvars.vbs
echo oFile.WriteLine("SET " ^& sitem) >> %~dp0resetvars.vbs
echo next >> %~dp0resetvars.vbs
echo path = oEnv("PATH") >> %~dp0resetvars.vbs
echo. >> %~dp0resetvars.vbs
echo set oEnv=oShell.Environment("User") >> %~dp0resetvars.vbs
echo for each sitem in oEnv >> %~dp0resetvars.vbs
echo oFile.WriteLine("SET " ^& sitem) >> %~dp0resetvars.vbs
echo next >> %~dp0resetvars.vbs
echo. >> %~dp0resetvars.vbs
echo path = path ^& ";" ^& oEnv("PATH") >> %~dp0resetvars.vbs
echo oFile.WriteLine("SET PATH=" ^& path) >> %~dp0resetvars.vbs
echo oFile.Close >> %~dp0resetvars.vbs
%~dp0resetvars.vbs
call "%temp%\resetvars.bat"
REM Using chocolatey to install miniconda3
choco install miniconda3 -y
REM Configure the python base env under miniconda3
SET PATH=C:\tools\miniconda3;C:\tools\miniconda3\Library\mingw-w64\bin;C:\tools\miniconda3\Library\usr\bin;C:\tools\miniconda3\Library\bin;C:\tools\miniconda3\Scripts;C:\tools\miniconda3\bin;C:\tools\miniconda3\condabin;%PATH%
pip install torch transformers pyttsx3 pytz python-dateutil --use-feature=2020-resolver
REM Create a file named generate.py containing the python code for this demo.
echo from os import system >> %~dp0generate.py
echo from transformers import pipeline >> %~dp0generate.py
echo import json, pyttsx3 >> %~dp0generate.py
echo engine = pyttsx3.init() >> %~dp0generate.py
echo # generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B', device=0) >> %~dp0generate.py
echo generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B', device=-1) >> %~dp0generate.py
echo i = 1 >> %~dp0generate.py
echo while i ^< 6: >> %~dp0generate.py
echo intext = input("\n\nInput text:") >> %~dp0generate.py
echo outjson = generator((intext), do_sample=True, max_length=100) >> %~dp0generate.py
echo outtext = json.loads(json.dumps(outjson[0]))["generated_text"] >> %~dp0generate.py
echo print(outtext) >> %~dp0generate.py
echo engine.say(outtext) >> %~dp0generate.py
echo engine.runAndWait() >> %~dp0generate.py
:launch
REM Lets launch the demo, assuming your system is powerful enough to become a non biological intelligence.
C:\tools\miniconda3\python %~dp0generate.py
@RchGrav
Copy link
Author

RchGrav commented Apr 20, 2021

Regarding GPU support.. you will need to download CUDA from Nvidia's website here: https://developer.nvidia.com/cuda-downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment