Spaces:
Sleeping
Sleeping
Enable clustering
Browse files- Dockerfile +5 -1
- processes.json +8 -0
- src/lib/helper.ts +8 -0
- src/lib/marrow-cells/data.ts +3 -2
- src/server.ts +3 -2
Dockerfile
CHANGED
|
@@ -13,6 +13,9 @@ RUN apt-get update && apt-get install -y \
|
|
| 13 |
# Install kaggle silently
|
| 14 |
RUN yes | pip3 install kaggle --exists-action i --break-system-packages
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
# Switch to the "user" user
|
| 17 |
USER user
|
| 18 |
|
|
@@ -43,4 +46,5 @@ RUN --mount=type=secret,id=KAGGLE_USERNAME,mode=0444,required=true \
|
|
| 43 |
kaggle datasets download -d andrewmvd/bone-marrow-cell-classification --unzip -p $HOME/app/dist/app/marrow-cell-data
|
| 44 |
|
| 45 |
EXPOSE 7860
|
| 46 |
-
CMD [ "npm", "run", "start" ]
|
|
|
|
|
|
| 13 |
# Install kaggle silently
|
| 14 |
RUN yes | pip3 install kaggle --exists-action i --break-system-packages
|
| 15 |
|
| 16 |
+
# Install pm2
|
| 17 |
+
RUN npm install pm2 -g
|
| 18 |
+
|
| 19 |
# Switch to the "user" user
|
| 20 |
USER user
|
| 21 |
|
|
|
|
| 46 |
kaggle datasets download -d andrewmvd/bone-marrow-cell-classification --unzip -p $HOME/app/dist/app/marrow-cell-data
|
| 47 |
|
| 48 |
EXPOSE 7860
|
| 49 |
+
# CMD [ "npm", "run", "start" ]
|
| 50 |
+
CMD ["pm2-runtime", "processes.json"]
|
processes.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"script": "dist/server.js",
|
| 4 |
+
"instances": "max",
|
| 5 |
+
"exec_mode": "cluster",
|
| 6 |
+
"node_args": "--experimental-specifier-resolution=node"
|
| 7 |
+
}
|
| 8 |
+
]
|
src/lib/helper.ts
CHANGED
|
@@ -56,3 +56,11 @@ export function wrap(
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
};
|
| 58 |
}
|
| 59 |
+
|
| 60 |
+
export function log(...args: unknown[]) {
|
| 61 |
+
console.log(`[${process.env.pm_id ?? ''}]`, ...args);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export function warn(...args: unknown[]) {
|
| 65 |
+
console.warn(`[${process.env.pm_id ?? ''}]`, ...args);
|
| 66 |
+
}
|
src/lib/marrow-cells/data.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import fs from 'fs/promises';
|
| 2 |
import { CellTypes } from '../../marrow-cell-types';
|
| 3 |
import { Glob } from 'glob';
|
|
|
|
| 4 |
|
| 5 |
const DATA_DIR = 'dist/app/marrow-cell-data/';
|
| 6 |
|
|
@@ -8,7 +9,7 @@ export let cellTypes: CellTypes;
|
|
| 8 |
export let cellImages: { [key: string]: string[] };
|
| 9 |
|
| 10 |
export async function readData(): Promise<void> {
|
| 11 |
-
|
| 12 |
|
| 13 |
cellTypes = {};
|
| 14 |
const data = await fs.readFile(DATA_DIR + 'abbreviations.csv', {
|
|
@@ -22,7 +23,7 @@ export async function readData(): Promise<void> {
|
|
| 22 |
cellTypes[key] = description;
|
| 23 |
});
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
cellImages = {};
|
| 28 |
const directories = (
|
|
|
|
| 1 |
import fs from 'fs/promises';
|
| 2 |
import { CellTypes } from '../../marrow-cell-types';
|
| 3 |
import { Glob } from 'glob';
|
| 4 |
+
import { log } from '../helper';
|
| 5 |
|
| 6 |
const DATA_DIR = 'dist/app/marrow-cell-data/';
|
| 7 |
|
|
|
|
| 9 |
export let cellImages: { [key: string]: string[] };
|
| 10 |
|
| 11 |
export async function readData(): Promise<void> {
|
| 12 |
+
log('Marrow cells: Reading labels');
|
| 13 |
|
| 14 |
cellTypes = {};
|
| 15 |
const data = await fs.readFile(DATA_DIR + 'abbreviations.csv', {
|
|
|
|
| 23 |
cellTypes[key] = description;
|
| 24 |
});
|
| 25 |
|
| 26 |
+
log('Marrow cells: Indexing images');
|
| 27 |
|
| 28 |
cellImages = {};
|
| 29 |
const directories = (
|
src/server.ts
CHANGED
|
@@ -6,6 +6,7 @@ import cors from 'cors';
|
|
| 6 |
import { isBoom } from '@hapi/boom';
|
| 7 |
import { fileURLToPath } from 'url';
|
| 8 |
import { dirname, join } from 'path';
|
|
|
|
| 9 |
|
| 10 |
const __filename = fileURLToPath(import.meta.url);
|
| 11 |
const __dirname = dirname(__filename);
|
|
@@ -44,7 +45,7 @@ app.get('*', (_req, res) => {
|
|
| 44 |
Promise.all([
|
| 45 |
(async () => {
|
| 46 |
await readData();
|
| 47 |
-
|
| 48 |
`Marrow cells: ${
|
| 49 |
Object.keys(cellImages).length
|
| 50 |
} cell types and ${Object.values(cellImages).reduce(
|
|
@@ -55,6 +56,6 @@ Promise.all([
|
|
| 55 |
})(),
|
| 56 |
]).then(() => {
|
| 57 |
app.listen(PORT, () => {
|
| 58 |
-
|
| 59 |
});
|
| 60 |
});
|
|
|
|
| 6 |
import { isBoom } from '@hapi/boom';
|
| 7 |
import { fileURLToPath } from 'url';
|
| 8 |
import { dirname, join } from 'path';
|
| 9 |
+
import { log } from './lib/helper';
|
| 10 |
|
| 11 |
const __filename = fileURLToPath(import.meta.url);
|
| 12 |
const __dirname = dirname(__filename);
|
|
|
|
| 45 |
Promise.all([
|
| 46 |
(async () => {
|
| 47 |
await readData();
|
| 48 |
+
log(
|
| 49 |
`Marrow cells: ${
|
| 50 |
Object.keys(cellImages).length
|
| 51 |
} cell types and ${Object.values(cellImages).reduce(
|
|
|
|
| 56 |
})(),
|
| 57 |
]).then(() => {
|
| 58 |
app.listen(PORT, () => {
|
| 59 |
+
log(`Server listening at http://localhost:${PORT}`);
|
| 60 |
});
|
| 61 |
});
|