Skip to content

Instantly share code, notes, and snippets.

Last active November 18, 2021 19:31
Show Gist options
  • 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 exist, if so lets assume all of this script has been ran already and just execute the demo.
if exist 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 )
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
exit /B
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
REM Deploy Chocolatey ( )
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(''))
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("'','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
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 containing the python code for this demo.
echo from os import system >>
echo from transformers import pipeline >>
echo import json, pyttsx3 >>
echo engine = pyttsx3.init() >>
echo # generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B', device=0) >>
echo generator = pipeline('text-generation', model='EleutherAI/gpt-neo-1.3B', device=-1) >>
echo i = 1 >>
echo while i ^< 6: >>
echo intext = input("\n\nInput text:") >>
echo outjson = generator((intext), do_sample=True, max_length=100) >>
echo outtext = json.loads(json.dumps(outjson[0]))["generated_text"] >>
echo print(outtext) >>
echo engine.say(outtext) >>
echo engine.runAndWait() >>
REM Lets launch the demo, assuming your system is powerful enough to become a non biological intelligence.
Copy link

RchGrav commented Apr 18, 2021

If you would like a longer output search the for "max_length=" and modify it to a larger value.

Copy link

RchGrav commented Apr 20, 2021

Regarding GPU support.. you will need to download CUDA from Nvidia's website here:

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