Skip to content

Commit b53cfba

Browse files
committed
powershell scripts
1 parent f4c38cb commit b53cfba

File tree

8 files changed

+79
-35
lines changed

8 files changed

+79
-35
lines changed

scripts/run.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Write-Output "Welcome to TensorFlow-GUI"
2+
conda activate tfgui
3+
Set-Location .\..\src\
4+
npm start
5+
Set-Location .\..\scripts\
6+
conda deactivate
7+
Write-Output "Bye"

scripts/setup.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86_64.exe
3+
# https://nodejs.org/dist/v12.16.1/node-v12.16.1-x64.msi
4+
5+
Write-Output "Setting up enviroment for TensorFlow-GUI"
6+
7+
conda create -n tfgui python=3.5
8+
conda activate tfgui
9+
conda install --file .\..\requirements.txt
10+
conda install -c menpo opencv
11+
conda deactivate
12+
13+
Set-Location .\..\src\
14+
npm install
15+
Set-Location .\..\scripts\
16+
mkdir -p .\..\testing\Projects\;
17+
Write-Output "Completed!";

src/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function createWindow() {
1212
win = new BrowserWindow({
1313
width: 1280,
1414
height: 720,
15-
nodeIntegration: true
15+
darkTheme: true,
16+
webPreferences: { nodeIntegration: true},
1617
});
1718
win.loadFile('modules/index.html')
1819
win.on('closed', () => {
@@ -46,8 +47,13 @@ function createWindow() {
4647
app.on('ready', createWindow);
4748

4849
app.on('window-all-closed', () => {
49-
let killtensorboard = childprocess.spawn('killall', ["-9", "tensorboard"]);
50-
// let killpython = childprocess.spawn('killall', ["-9", "python3"]);
50+
let killtensorboard;
51+
if (process.platform == 'win32') {
52+
killtensorboard = childprocess.spawn('taskkill', ['/f','/im', 'tensorboard'])
53+
}else{
54+
killtensorboard = childprocess.spawn('killall', ["-9", "tensorboard"]);
55+
}
56+
5157
if (process.platform !== 'darwin') {
5258
killtensorboard.on('close', (code) => {
5359
app.quit()

src/modules/codeeditor/codeeditor.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
const print = console.log;
2-
// const CodeMirror = require("../../lib/codemirror.js");
3-
// require("../../lib/matchbrackets.js");
4-
// require("../../lib/python.js");
5-
// require("../../lib/show-hint.js");
6-
// require("../../lib/python-hint.js");
72
const swal = require('sweetalert');
83
const global = require("../../lib/global.js")
94
const childprocess = require('child_process');
@@ -19,8 +14,8 @@ $("#project-name").text(global.projectDetails.name);
1914
$("#project-details").text(global.projectDetails.details.substr(0, 20) + "...");
2015

2116
let dir = global.projectDetails.name;
22-
let basepath = process.cwd() + "/../testing/Projects/";
23-
global.editorText = fs.readFileSync(basepath + dir + "/editor.py", "utf8");
17+
let basepath = path.join(process.cwd(), "/../testing/Projects/");
18+
global.editorText = fs.readFileSync(path.join(basepath, dir, "editor.py"), "utf8");
2419

2520
function uriFromPath(_path) {
2621
var pathName = path.resolve(_path).replace(/\\/g, '/');
@@ -48,15 +43,17 @@ amdRequire(['vs/editor/editor.main'], () => {
4843
}
4944

5045
function testPython() {
51-
let codepath = basepath + dir + '/editor.py';
46+
let codepath = path.join(basepath, dir, "editor.py");
5247
try {
5348
fs.writeFileSync(codepath, codeeditor.getValue(), 'utf-8');
5449
} catch (e) {
5550
console.log('Failed to save the file !');
5651
}
5752

5853
var env = Object.create(process.env);
59-
var pythonprocess = childprocess.spawn('python3', ['-m', 'py_compile', codepath], {
54+
console.log(env);
55+
var pythoncmd = process.platform == "win32"? path.join(env['CONDA_PREFIX'],'python.exe'): 'python3';
56+
var pythonprocess = childprocess.spawn(pythoncmd, ['-m', 'py_compile', codepath], {
6057
env: env
6158
});
6259

@@ -74,7 +71,7 @@ amdRequire(['vs/editor/editor.main'], () => {
7471

7572
function saveProject(isShow) {
7673
global.editorText = codeeditor.getValue();
77-
fs.writeFile(basepath + dir + "/editor.py", global.editorText, 'utf-8', err => {
74+
fs.writeFile(path.join(basepath, dir, "editor.py"), global.editorText, 'utf-8', err => {
7875
if (err) {
7976
swal("Saving Project", "Failed to save project.", "error");
8077
print("Error writing file", err);

src/modules/project/project.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const global = require('../../lib/global');
22
var rimraf = require("rimraf");
33
const swal = require('sweetalert');
4+
const path = require('path');
45

56
function loadPage(page_path) {
67
$("#main-content").html('');
@@ -17,7 +18,7 @@ $("#project-name").val(global.projectDetails.name);
1718
$("#project-description").val(global.projectDetails.details);
1819

1920
$(".deletebuttons").click((value) => {
20-
let basepath = process.cwd() + "/../testing/Projects/";
21+
let basepath = path.join(process.cwd(), "/../testing/Projects/");
2122
let pdosi = $(value.target).siblings();
2223
swal({
2324
title: "Are you sure?",
@@ -28,7 +29,7 @@ $(".deletebuttons").click((value) => {
2829
}).then((willDelete) => {
2930
if (willDelete) {
3031
try {
31-
rimraf.sync(basepath + "/" + global.projectDetails.name);
32+
rimraf.sync(path.join(basepath,global.projectDetails.name));
3233
swal(`Your project '${global.projectDetails.name}' has been deleted!`, {
3334
icon: "success",
3435
});

src/modules/training/training.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const childprocess = require('child_process');
44
const print = console.log;
55
var fs = require('fs');
66
const swal = require('sweetalert');
7+
const path = require('path');
78

89
let intervalid;
910
let pythonprocess;
@@ -41,9 +42,11 @@ function runPython() {
4142
}
4243

4344
var env = Object.create(process.env);
44-
pythonprocess = childprocess.spawn('python3', [codepath], {
45+
var pythoncmd = process.platform == "win32"? path.join(env['CONDA_PREFIX'],'python.exe'): 'python3';
46+
pythonprocess = childprocess.spawn(pythoncmd, [codepath], {
4547
env: env
4648
});
49+
4750
setTimeout(() => {
4851
$("#training-status").text("Training...");
4952
}, 3000);
@@ -59,7 +62,7 @@ function runPython() {
5962

6063
pythonprocess.on('close', (code) => {
6164
pythonclosed = true;
62-
if (code == 1) {
65+
if (code != 0) {
6366
$("#training-status").text("Training Failed.");
6467
swal("Error", `${processError}`, "error");
6568
} else {

src/modules/user/user.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const fs = require('fs');
33
const global = require('../../lib/global');
44
const print = console.log;
55
const childprocess = require('child_process');
6+
const path = require('path');
7+
68

79
function loadPage(page_path) {
810
$("#main-content").html('');
@@ -20,9 +22,9 @@ $("#user-create-project-button").click(() => {
2022
swal("Error", "Projet Name can't be empty.", "error");
2123
} else if (value) {
2224
let dir = value.replace(/[^a-z0-9]/gi, '_').toLowerCase();
23-
let basepath = process.cwd() + "/../testing/Projects/";
24-
if (!fs.existsSync(process.cwd() + "/../testing")) {
25-
fs.mkdirSync(process.cwd() + "/../testing");
25+
let basepath = path.join(process.cwd(), "/../testing/Projects/");
26+
if (!fs.existsSync(path.join(process.cwd() , "/../testing"))) {
27+
fs.mkdirSync(path.join(process.cwd() , "/../testing"));
2628
}
2729
if (!fs.existsSync(basepath)) {
2830
fs.mkdirSync(basepath);
@@ -43,7 +45,7 @@ $("#user-create-project-button").click(() => {
4345
print("Error creating folder", err);
4446
}
4547
});
46-
fs.mkdirSync(basepath + dir + "/logs");
48+
fs.mkdirSync(path.join(basepath,dir,"logs"));
4749
let data = {
4850
name: dir,
4951
details: value,
@@ -64,7 +66,7 @@ import numpy as np
6466
Do not remove tensorboard initialization.
6567
Also, don't forget to add tensorboard as callback in your model.
6668
'''
67-
tensorboard = TensorBoard(log_dir="../testing/Projects/${dir}/logs/{}".format(asctime()), histogram_freq=0,write_graph=True,write_grads=True,write_images=True)
69+
tensorboard = TensorBoard(log_dir="../testing/Projects/${dir}/logs/{}".format(asctime()).replace(":"."-"), histogram_freq=0,write_graph=True,write_grads=True,write_images=True)
6870
6971
7072
def getTrainingData():
@@ -94,9 +96,9 @@ def train():
9496
train()
9597
9698
`
97-
fs.writeFileSync(basepath + dir + "/graph.json", JSON.stringify(initgraph));
98-
fs.writeFileSync(basepath + dir + "/editor.py", initeditor);
99-
fs.writeFile(basepath + dir + "/info.json", JSON.stringify(data), 'utf-8', err => {
99+
fs.writeFileSync(path.join(basepath, dir, "graph.json"), JSON.stringify(initgraph));
100+
fs.writeFileSync(path.join(basepath, dir, "editor.py"), initeditor);
101+
fs.writeFile(path.join(basepath, dir, "info.json"), JSON.stringify(data), 'utf-8', err => {
100102
if (err) {
101103
print("Error writing file", err);
102104
} else {
@@ -128,22 +130,33 @@ function openProject(value, page) {
128130
global.projectDetails.name = pdosi[0].innerText;
129131
global.projectDetails.details = pdosi[1].innerText;
130132

131-
let killtensorboard = childprocess.spawn('killall', ["-9", "tensorboard"]);
132-
133+
134+
let killtensorboard;
135+
if(process.platform == "win32"){
136+
killtensorboard = childprocess.spawn('taskkill', ['/f','/im', 'tensorboard.exe'])
137+
}else{
138+
killtensorboard = childprocess.spawn('killall', ["-9", "tensorboard"]);
139+
}
140+
141+
var tensorbaord;
133142
var env = Object.create(process.env);
134143
killtensorboard.on('close', (code) => {
135-
let tensorbaord = childprocess.spawn('tensorboard', ["--logdir=../testing/Projects/" + global.projectDetails.name + "/logs/"], {
144+
let tensorbaordcmd = process.platform == "win32"? path.join(env['CONDA_PREFIX'], 'Scripts','tensorboard.exe'): 'tensorboard';
145+
tensorbaord = childprocess.spawn(tensorbaordcmd, ["--logdir="+path.join("../testing/Projects/", global.projectDetails.name, "logs"),"--host=127.0.0.1"], {
136146
env: env
137147
});
138148

139-
console.log(`child process exited with code ${code}`);
149+
tensorbaord.on('close', (code)=>{
150+
console.log(code);
151+
});
152+
// console.log(`child process exited with code ${code}`);
140153
});
141154

142155
loadPage(page);
143156
}
144157

145158
function loadProjects() {
146-
let basepath = process.cwd() + "/../testing/Projects/";
159+
let basepath = path.join(process.cwd(), "/../testing/Projects/");
147160
let dirlist = getDirectories(basepath)
148161

149162
if (dirlist.length != 0) {
@@ -152,7 +165,7 @@ function loadProjects() {
152165

153166
$("#user-projects-card-row").empty();
154167
for (let dir in dirlist) {
155-
fs.readFile(basepath + dirlist[dir] + "/info.json", (err, fileData) => {
168+
fs.readFile(path.join(basepath, dirlist[dir], "info.json"), (err, fileData) => {
156169
if (err) {
157170
return print("Error in reading all projects", err)
158171
}

src/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)