Skip to content

Commit

Permalink
feat: electron builder added
Browse files Browse the repository at this point in the history
  • Loading branch information
tahaluh committed Apr 6, 2024
1 parent 55f110d commit 2d8ea3a
Show file tree
Hide file tree
Showing 7 changed files with 707 additions and 32 deletions.
2 changes: 2 additions & 0 deletions api/available_classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def get_available_classifiers():
model_folder = 'api/models'

# Verifica se o diretório 'models' existe

## retorna o path atual
if not os.path.exists(model_folder):
return []

Expand Down
20 changes: 10 additions & 10 deletions requirements.txt → api/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Flask==2.3.2
Flask-Cors==4.0.0
pandas==2.0.3
nltk==3.8.1
scikit-learn==1.3.0
numpy==1.25.2
matplotlib==3.7.1
seaborn==0.13.0
tensorflow==2.16.1
keras==3.0.0
Flask==2.3.2
Flask-Cors==4.0.0
pandas==2.0.3
nltk==3.8.1
scikit-learn==1.3.0
numpy==1.25.2
matplotlib==3.7.1
seaborn==0.13.0
tensorflow==2.16.1
keras==3.0.0
1 change: 1 addition & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Teste de texto aqui
47 changes: 44 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "LinguifAI",
"description": "",
"author": {
"name": "TailLinguifAI",
"email": ""
},
"version": "0.1.0",
"main": "main.js",
"main": "./public/electron.js",
"homepage": "./",
"private": true,
"dependencies": {
Expand All @@ -17,7 +22,6 @@
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"axios": "^1.6.0",
"electron-packager": "^17.1.2",
"electron-process": "^0.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -30,14 +34,19 @@
"typescript": "^4.9.5"
},
"scripts": {
"start2": "set BROWSER=NONE && react-scripts start",
"start": "concurrently \"npm run start:react\" \"npm run start:flask\"",
"start:react": "react-scripts start",
"start:flask": "python api/app.py",
"build": "react-scripts build",
"ciBuild": "CI=true react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"electron": "electron ."
"electron": "electron .",
"start-electron": "set ELECTRON_START_URL=http://localhost:3000/ && electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder",
"electron:package:win": "npm run build && electron-builder -w -c.extraMetadata.main=build/electron.js"
},
"eslintConfig": {
"extends": [
Expand All @@ -60,6 +69,38 @@
"devDependencies": {
"concurrently": "^8.2.2",
"electron": "^26.1.0",
"electron-builder": "^24.13.3",
"electron-packager": "^17.1.2",
"tailwindcss": "^3.3.3"
},
"build": {
"appId": "LinguifAI",
"win": {
"target": [
"nsis"
]
},
"files": [
"build/**/*",
"node_modules/**/*",
"resources/**/*"
],
"directories": {
"buildResources": "build"
},
"extraFiles": [
{
"from": "api",
"to": "api",
"filter": [
"**/*"
]
}
],
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true,
"license": "license.md"
}
}
}
34 changes: 28 additions & 6 deletions main.js → public/electron.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
const { app, BrowserWindow } = require("electron");
const childProcess = require("child_process");
const path = require("path");
const url = require("url");
const axios = require("axios");

let flaskServerProcess;

function installDependencies() {
// Execute pip install command to install dependencies from requirements.txt
childProcess.execSync("pip install -r ./resources/app/requirements.txt", { stdio: "inherit" });
const requirementsPath = process.env.ELECTRON_START_URL
? "./api/requirements.txt"
: "./api/requirements.txt";
childProcess.execSync(`pip install -r ${requirementsPath}`, {
stdio: "inherit",
});
}

function startFlaskServer() {
installDependencies();
//installDependencies();

const pythonPath = process.env.ELECTRON_START_URL
? "./api/app.py"
: "./api/app.py";

flaskServerProcess = childProcess.spawn("python", ["./resources/app/api/app.py"], {
flaskServerProcess = childProcess.spawn("python", [pythonPath], {
detached: false,
stdio: ["ignore", "pipe", "pipe"], // Capture stdout and stderr
stdio: ["ignore", "pipe", "pipe"],
});

// Capture stdout
Expand Down Expand Up @@ -50,8 +60,20 @@ function createWindow() {
height: 600,
show: false,
});
// flaskServerProcess
win.webContents.executeJavaScript(
`console.log("startUrl: ${flaskServerProcess.pid}")`
);

win.loadFile(path.join(__dirname, "./build/index.html"));
const startUrl =
process.env.ELECTRON_START_URL ||
url.format({
pathname: path.join(__dirname, "./index.html"),
protocol: "file:",
slashes: true,
});

win.loadURL(startUrl);

win.once("ready-to-show", () => {
win.maximize();
Expand All @@ -68,7 +90,7 @@ function createWindow() {
app.whenReady().then(() => {
startFlaskServer();
createWindow();

app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
Expand Down
10 changes: 10 additions & 0 deletions public/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Flask==2.3.2
Flask-Cors==4.0.0
pandas==2.0.3
nltk==3.8.1
scikit-learn==1.3.0
numpy==1.26.4
matplotlib==3.7.1
seaborn==0.13.0
tensorflow==2.16.1
keras==3.0.0
Loading

0 comments on commit 2d8ea3a

Please sign in to comment.