Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Jan 30, 2024
2 parents aff3724 + b42823c commit 3d94a61
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chirpity-Electron
# Chirpity

Electron app to identify the calls of nocturnal migrants from audio files.

Expand All @@ -13,6 +13,11 @@ First, clone the project and install all dependencies:
```
git clone https://github.com/Mattk70/Chirpity-Electron
cd Chirpity-Electron
```

Chirpity depends on <i><a href="https://nodejs.org/en/download">Node.js</a></i>, follow the link for the download and installation instructions.
Once installed, run:
```
npm install
```

Expand All @@ -24,21 +29,21 @@ npm start

## Development setup

Setting up the project requires <i>Node.js</i>, which we need to install first.

After that, we can initialize the source directory with:

Initialize the source directory with:

```
npm init
```

Now, we need to install project dependencoies with:
Now, install project dependencoies with:

```
npm install --save-dev
```

After that, we can build a windows msi installer with:
After that, build a windows msi installer with:

```
npm run export
Expand Down
Binary file added img/icon/chirpity_logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ window.onload = async () => {
speciesThreshold: config.speciesThreshold
});
loadModel();
worker.postMessage({ action: 'clear-cache' })
//worker.postMessage({ action: 'clear-cache' })
// New users - show the tour
if (!config.seenTour) {
setTimeout(prepTour, 2000)
Expand Down Expand Up @@ -2191,7 +2191,7 @@ speciesThreshold.addEventListener('change', () =>{
worker.postMessage({ action: 'update-list', list: config.list })
})

const loadModel = () => {
const loadModel = ({clearCache = true} = {}) => {
t0_warmup = Date.now();
worker.postMessage({
action: 'load-model',
Expand All @@ -2200,7 +2200,8 @@ const loadModel = () => {
batchSize: config[config.backend].batchSize,
warmup: config.warmup,
threads: config[config.backend].threads,
backend: config.backend
backend: config.backend,
clearCache: clearCache
});
}

Expand Down Expand Up @@ -2253,7 +2254,7 @@ const handleBackendChange = (e) => {
updatePrefs();
// restart wavesurfer regions to set new maxLength
initRegion();
loadModel();
loadModel({clearCache: false});
}

const backend = document.getElementsByName('backend');
Expand Down Expand Up @@ -3472,7 +3473,7 @@ batchSizeSlider.addEventListener('input', (e) => {
})
batchSizeSlider.addEventListener('change', (e) => {
config[config.backend].batchSize = BATCH_SIZE_LIST[e.target.value];
loadModel();
loadModel({clearCache: false});
updatePrefs();
// Reset region maxLength
initRegion();
Expand Down Expand Up @@ -3960,7 +3961,7 @@ ThreadSlider.addEventListener('input', () => {
});
ThreadSlider.addEventListener('change', () => {
config[config.backend].threads = ThreadSlider.valueAsNumber;
loadModel();
loadModel({clearCache: false});
updatePrefs();
});

Expand Down
15 changes: 10 additions & 5 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ const clearCache = async (fileCache, sizeLimitInGB) => {
const requiredSpace = sizeLimitInGB * 1024 ** 3;
// If Full, clear at least 25% of cache, so we're not doing this too frequently
if (size > requiredSpace) {
// while (size > requiredSpace && canBeRemovedFromCache.length) {
while (canBeRemovedFromCache.length > 1) {
const file = canBeRemovedFromCache.shift();
const proxy = metadata[file].proxy;
Expand Down Expand Up @@ -251,9 +250,10 @@ break;
case "chart": {await onChartRequest(args);
break;
}
case "clear-cache": {CACHE_LOCATION = p.join(TEMP, "chirpity");
fs.existsSync(CACHE_LOCATION) || fs.mkdirSync(CACHE_LOCATION);
await clearCache(CACHE_LOCATION, 0);
case "clear-cache": {
CACHE_LOCATION = p.join(TEMP, "chirpity");
fs.existsSync(CACHE_LOCATION) || fs.mkdirSync(CACHE_LOCATION);
await clearCache(CACHE_LOCATION, 0);
break;
}
case "convert-dataset": {convertSpecsFromExistingSpecs();
Expand Down Expand Up @@ -314,7 +314,12 @@ break;
event: "spawning"
});
sampleRate = args.model === "v2.4" ? 48_000 : 24_000;

// Since models have different sample rates, we need to clear the cache of
// files that have been resampled for a different model, and reset metadata
CACHE_LOCATION = p.join(TEMP, "chirpity");
DEBUG && console.log('clear cache', args.clearCache, 'location', CACHE_LOCATION)
args.clearCache && ipcRenderer.invoke('clear-cache', CACHE_LOCATION)
metadata = {}
BATCH_SIZE = parseInt(args.batchSize);
setAudioContext(sampleRate);
memoryDB = undefined;
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,9 @@ ipcMain.handle('saveFile', (event, arg) => {
});
mainWindow.webContents.send('saveFile', { message: 'file saved!' });
});

ipcMain.handle('clear-cache', (event, filePath) => {
// console.log("cache location:", event, filePath);
// return
clearCache(filePath)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chirpity",
"version": "0.11.0",
"version": "0.11.1",
"description": "Chirpity Nocmig",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contextBridge.exposeInMainWorld('electron', {
getPath: () => ipcRenderer.invoke('getPath'),
getTemp: () => ipcRenderer.invoke('getTemp'),
getVersion: () => ipcRenderer.invoke('getVersion'),
getAudio: () => ipcRenderer.invoke('getAudio'),
getAudio: () => ipcRenderer.invoke('getAudio')
});

contextBridge.exposeInMainWorld('module', {
Expand Down

0 comments on commit 3d94a61

Please sign in to comment.