Skip to content

Commit

Permalink
Merge pull request #39 from catalystneuro/feature/use-vame-0.4.0
Browse files Browse the repository at this point in the history
feat: use new vame version
  • Loading branch information
nathan-vm authored Jul 30, 2024
2 parents 50fd929 + 204880a commit 1cf0818
Show file tree
Hide file tree
Showing 52 changed files with 1,015 additions and 944 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/build-and-release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ jobs:
- name: Install dependencies
run: npm install

- name: Build
- name: Build and deploy on Linux(Debian)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run build:linux

- name: Deploy Linux
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run publish -- --publish=always
run: npm run build:linux --publish=always
9 changes: 2 additions & 7 deletions .github/workflows/build-and-release-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ jobs:
p12-file-base64: ${{ secrets.MACOS_CERTIFICATE }}
p12-password: ${{ secrets.MACOS_CERTIFICATE_PWD }}

- name: Build Mac
- name: Build and deploy on MacOS
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run build:mac

- name: Deploy Mac
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run publish -- --publish=always
run: npm run build:mac -- --publish=always
7 changes: 1 addition & 6 deletions .github/workflows/build-and-release-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ jobs:
- name: Build and deploy on Windows
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run build:win

- name: Deploy Windows
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run publish -- --publish=always
run: npm run build:win -- --publish=always
2 changes: 1 addition & 1 deletion .github/workflows/test-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: npm install

- name: Build
run: npm run build:linux
run: npm run build:linux -- --publish=never
2 changes: 1 addition & 1 deletion .github/workflows/test-build-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: npm install

- name: Build and deploy on Mac
run: npm run build:mac
run: npm run build:mac -- --publish=never
2 changes: 1 addition & 1 deletion .github/workflows/test-build-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: npm install

- name: Build and deploy on Windows
run: npm run build:win
run: npm run build:win -- --publish=never
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ A desktop application for the Variational Animal Motion Encoding (VAME) project.
VAME Desktop has been designed to run each step of a VAME project **only once**. This is to ensure that the project is reproducible and that the data is not accidentally overwritten.

## Installation

### Download builded versions:

You can find the builed versions of VAME Desktop on the [release page](https://github.com/catalystneuro/vame-desktop/releases).

## Development mode

### Python
You will need to have [miniconda](https://docs.conda.io/en/latest/miniconda.html) installed on your machine OR [pyenv](https://github.com/pyenv/pyenv).

Expand Down
2 changes: 1 addition & 1 deletion main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]


a = Analysis(
['src/services/main.py'],
['src/services/vameApi/main.py'],
pathex=[],
binaries=binaries,
datas=datas,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vame-desktop",
"main": "./out/main/index.js",
"version": "0.2.0",
"version": "0.3.0",
"description": "An open-source machine learning tool for behavioral segmentation and analyses.",
"license": "GPL-3.0-only",
"author": "Catalyst Neuro <hello@catalystneuro.com>, Nathan Vieira <nathan.v.marcelino@gmail.com>, Garrett Flynn <garrettmflynn@gmail.com>",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ flask-restx==1.3.0
numpy==1.26.4
pyinstaller==6.8.0
pyinstaller-hooks-contrib==2024.6
vame-py==0.3.1
vame-py==0.4.0
6 changes: 1 addition & 5 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ app.whenReady().then(() => {
folderHandler()

if (is.dev) {
backend = runChildProcess("python", [join(__dirname, "..", "..", "src", "services", "main.py")])
backend = runChildProcess("python", [join(__dirname, "..", "..", "src", "services", "vameApi", "main.py")])

backend?.stdout.on("data", (data) => {
if (data?.toString().includes("Flask server started at")) {
Expand Down Expand Up @@ -89,10 +89,6 @@ app.on("window-all-closed", () => {
app.on("before-quit", (event) => {
if (backend && backend.exitCode === null) {
event.preventDefault(); // Prevent the default behavior of quitting immediately
backend.once("exit", (code) => {
console.log(`[electron]: Process exited with code ${code}`)
app.exit(code ?? 0); // Quit the app after the child process exits
});
backend.kill("SIGTERM"); // Send SIGTERM to the child process
} else if (backend && backend.exitCode !== null) {
console.log(`[electron]: Process exited with code ${backend.exitCode}`)
Expand Down
6 changes: 4 additions & 2 deletions src/main/process/runChildProcess.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { app } from "electron";

export function runChildProcess(exec: string, path?: string[]) {
let stdoutChunks = [], stderrChunks = [];
Expand All @@ -9,9 +10,10 @@ export function runChildProcess(exec: string, path?: string[]) {
}
});

child.on('exit', (code) =>
child.on('exit', (code) => {
console.log(`[${exec}]: Process exited with code ${code}`)
);
app.exit(code ?? -1)
});

child.stdout.on('data', (data) => {
console.log(`[${exec}]:`, data.toString());
Expand Down
16 changes: 13 additions & 3 deletions src/renderer/src/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,20 @@ declare global {
assets: {
images: {
evaluation: string[];
visualization: Record<string,string[]>;
visualization: {
hmm: Record<string,string[]>,
kmeans: Record<string,string[]>
};
};
videos: {
community: Record<string,string[]>;
motif: Record<string,string[]>;
community: {
hmm: Record<string,string[]>,
kmeans: Record<string,string[]>
};
motif: {
hmm: Record<string,string[]>,
kmeans: Record<string,string[]>
};
};
};
created_at: string;
Expand Down Expand Up @@ -227,6 +236,7 @@ declare global {
export type EnumProperty = DefaultPropertyAttrs & {
type: "string";
enum: string[];
multiple?: boolean;
default?: string;
};

Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/components/DynamicForm/DynamicInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ const DynamicInput: React.FC<DynamicInputProps> = ({

// Handle select fields
if (type === "enum") {
const enumProperty = property as EnumProperty
return (
<select
{...register(itemKey, { required, disabled: readOnly })}
multiple={enumProperty.multiple}
>
{(property as EnumProperty)!.enum.map((option) => (
<option key={option} value={option}>
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/src/components/DynamicForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
initialValues,
submitText = "Submit",
}) => {
const defaultValues = initialValues && !isEmpty(initialValues) ? initialValues : extractDefaultValues(schema)

const defaultValues = {
...extractDefaultValues(schema),
...initialValues
}

const methods = useForm({
disabled: blockSubmission,
Expand All @@ -31,6 +35,11 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
const properties = Object.entries(schema.properties)
const readOnly = !properties.some(([_,p])=> !p.readOnly)

// const handleSubmit = (data) => {
// console.log(data)
// onFormSubmit(data)
// }

return (
<FormProvider {...methods}>

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/DynamicForm/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ export const FileListItem = styled.li`
align-items: center;
padding: 5px 0;
overflow: auto;
`;
`;
5 changes: 3 additions & 2 deletions src/renderer/src/pages/Project/Tabs/CommunityAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "react"
import DynamicForm from "../../../components/DynamicForm"

import communitySchema from '../../../../../schema/community.schema.json'

import { TabProps } from "./types"
import TerminalModal from "../../../components/TerminalModal"
import { ControlButton } from "@renderer/pages/Home/styles"
Expand All @@ -19,7 +20,7 @@ export const CommunityAnalysis = ({
}: TabProps) => {
const [terminal, setTerminal] = useState(false)

const schema = structuredClone(communitySchema) as Schema
const schema = structuredClone(communitySchema) as unknown as Schema

const communitiesCreated = project.workflow.communities_created
const states = project.states?.["community"]
Expand Down Expand Up @@ -47,7 +48,7 @@ export const CommunityAnalysis = ({
content={blockTooltip}
placement="bottom"
hideOnClick={false}
onShow={() => !blockSubmission as false}
disabled={!blockSubmission || !blockTooltip}
>
<>
<DynamicForm
Expand Down
68 changes: 27 additions & 41 deletions src/renderer/src/pages/Project/Tabs/CommunityVideos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { ControlButton } from "@renderer/pages/Home/styles"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faTerminal } from "@fortawesome/free-solid-svg-icons"

import CommunityVideosSchema from "../../../../../schema/community-videos.schema.json"
import DynamicForm from "@renderer/components/DynamicForm"

const CommunityVideos = ({
project,
onFormSubmit,
Expand All @@ -17,52 +20,20 @@ const CommunityVideos = ({
}: TabProps) => {
const [terminal, setTerminal] = useState(false)

const hasCommunityVideos = project.workflow.community_videos_created

if (!hasCommunityVideos) return (
<PaddedTab>
<span>
Open logs:{" "}
<ControlButton onClick={() => setTerminal(true)}>
<FontAwesomeIcon icon={faTerminal} />
</ControlButton>
</span>

<TerminalModal
projectPath={project.config.project_path}
logName={["community_videos"]}
isOpen={terminal}
onClose={() => setTerminal(false)}
/>

<Tippy
content={blockTooltip}
placement="bottom"
hideOnClick={false}
disabled={!blockSubmission}
>
<span>
<Button
disabled={blockSubmission}
onClick={onFormSubmit}
>
Create Community Videos
</Button>
</span>
</Tippy>
</PaddedTab>
)

const schema = structuredClone(CommunityVideosSchema) as unknown as Schema

const { videos } = project.assets

const communityVideos = videos?.community ?? {}

const organizedVideos = Object.entries(communityVideos).reduce((acc, [label, videos]) => {
acc[label] = videos.map((videoPath: string) => {
const number = videoPath.split('-').pop()?.split('_').pop()?.split('.')[0]
return { path: videoPath, label: `Community ${number}`, idx: Number(number) }
}).sort((a, b) => a.idx - b.idx)
const organizedVideos = Object.entries(communityVideos).reduce((acc, [label, videosObj]) => {
Object.entries(videosObj).forEach(([parametrization, videos]) => {

acc[`${label}-${parametrization}`] = videos.map((videoPath: string) => {
const number = videoPath.split('-').pop()?.split('_').pop()?.split('.')[0]
return { path: videoPath, label: `Community ${number}`, idx: Number(number) }
}).sort((a, b) => a.idx - b.idx)
})

return acc
}, {} as Record<string, VideoType[]>)
Expand All @@ -76,6 +47,21 @@ const CommunityVideos = ({
</ControlButton>
</span>

<Tippy
content={blockTooltip}
placement="bottom"
hideOnClick={false}
disabled={!blockSubmission}
>
<span>
<DynamicForm
schema={schema}
blockSubmission={blockSubmission}
submitText={"Create Community Videos"}
onFormSubmit={onFormSubmit}
/>
</span>
</Tippy>

<TerminalModal
projectPath={project.config.project_path}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/pages/Project/Tabs/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const Model = ({
content={blockTooltip}
placement="bottom"
hideOnClick={false}
onShow={() => !blockSubmission as false}
disabled={!blockSubmission || !blockTooltip}
>
<span>

Expand Down Expand Up @@ -102,7 +102,7 @@ const Model = ({
content={blockTooltip}
placement="bottom"
hideOnClick={false}
onShow={() => !blockSubmission as false}
disabled={!blockSubmission || !blockTooltip}
>
<span>

Expand Down
Loading

0 comments on commit 1cf0818

Please sign in to comment.