Skip to content

Commit

Permalink
Chore: add janky sigma validation(will clean up later)
Browse files Browse the repository at this point in the history
  • Loading branch information
avivash committed Nov 14, 2023
1 parent b853b86 commit 6feb9bb
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 12 deletions.
14 changes: 14 additions & 0 deletions src/lib/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { homestar } from '$lib/rpc'

export const subscribNetworkEvents = async (): Promise<void> => {
await homestar.networkEvents(result => {
console.log('result', result)
if (result.error) {
console.error(result.error)
} else {
console.log('result', result)
}
})
}

export default subscribNetworkEvents
18 changes: 11 additions & 7 deletions src/lib/workflows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const prepareWorkflow = async (payload: any, dataUrl: string) => {
/**
* Run a workflow
*/
export const runWorkflow = async (workflowId: string, uploadedImage: string, runPayload = null, runStatus = null): Promise<void> => {
export const runWorkflow = async (workflowId: string, uploadedImage: string, runPayload = null, runStatus = null, originalPayload = null): Promise<void> => {
try {
const workflows = getStore(workflowsStore)
const matchingWorkflow = workflows.workflows.find(
Expand All @@ -163,29 +163,33 @@ export const runWorkflow = async (workflowId: string, uploadedImage: string, run
status: 'running',
runs:
runStatus === 'ready'
// If a run is ready, modify it in place
? workflow.runs.map((r, i) => {
? // If a run is ready, modify it in place
workflow.runs.map((r, i) => {
if (i === 0) {
return {
...r,
status: 'running',
payload: {
...r.payload,
...rawPayloadToRun,
...(originalPayload
? { ...originalPayload }
: { ...rawPayloadToRun }),
name: runName
}
}
}
return r
})
// If a run has already been executed, add it to the top of the list
: [
: // If a run has already been executed, add it to the top of the list
[
{
name: runName,
label: `run ${runIndex}`,
status: 'running',
payload: {
...rawPayloadToRun,
...(originalPayload
? { ...originalPayload }
: { ...rawPayloadToRun }),
name: runName
},
receipts: []
Expand Down
2 changes: 2 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { onDestroy, onMount } from 'svelte'
import '../global.css'
import subscribNetworkEvents from '$lib/network'
import { addNotification } from '$lib/notifications'
import { appDescription, appImageURL, appName, appURL } from '$lib/app-info'
import { sessionStore, themeStore } from '$lib/stores'
Expand Down Expand Up @@ -47,6 +48,7 @@
onMount(() => {
subscribeRPC()
subscribNetworkEvents()
})
onDestroy(() => {
Expand Down
62 changes: 59 additions & 3 deletions src/routes/workflows/components/graph/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,36 @@
// Invoke run
const handleInvokeRun = async (): Promise<void> => {
let payload = selectedRun?.payload
// @ts-ignore-next-line
const originalPayload = JSON.parse(JSON.stringify(selectedRun?.payload))
// Ensure blur params are always sent as float
// @ts-ignore-next-line
const blurTask = payload?.workflow?.tasks?.filter(t => t?.run?.input?.func?.includes('blur'))
if (blurTask) {
// @ts-ignore-next-line
payload.workflow.tasks = payload?.workflow?.tasks.map((t) => {
// @ts-ignore-next-line
if (t?.run?.input?.func?.includes('blur') && String(t?.run?.input?.args[1]).split('.')?.length === 1) {
return {
...t,
run: {
...t.run,
input: {
...t.run.input,
args: [t.run.input.args[0], t.run.input.args[1] + 0.0001]
}
}
}
}
return t
})
}
if (workflow?.runs?.length > 0) {
await runWorkflow(workflow?.id, uploadedImage, selectedRun?.payload, selectedRun?.status)
await runWorkflow(workflow?.id, uploadedImage, payload, selectedRun?.status, originalPayload)
} else {
await runWorkflow(workflow?.id, uploadedImage)
}
Expand Down Expand Up @@ -150,8 +178,36 @@
try {
await handleSaveRun()
if ($unsavedRunStore?.payload) {
await runWorkflow(workflow?.id, uploadedImage, $unsavedRunStore?.payload, $unsavedRunStore?.status)
let payload = $unsavedRunStore?.payload
// @ts-ignore-next-line
const originalPayload = JSON.parse(JSON.stringify($unsavedRunStore?.payload))
// Ensure blur params are always sent as float
// @ts-ignore-next-line
const blurTask = payload?.workflow?.tasks?.filter(t => t?.run?.input?.func?.includes('blur'))
if (blurTask) {
// @ts-ignore-next-line
payload.workflow.tasks = payload?.workflow?.tasks.map((t) => {
// @ts-ignore-next-line
if (t?.run?.input?.func?.includes('blur') && String(t?.run?.input?.args[1]).split('.')?.length === 1) {
return {
...t,
run: {
...t.run,
input: {
...t.run.input,
args: [t.run.input.args[0], t.run.input.args[1] + 0.0001]
}
}
}
}
return t
})
}
if (payload) {
await runWorkflow(workflow?.id, uploadedImage, payload, $unsavedRunStore?.status, originalPayload)
} else {
await runWorkflow(workflow?.id, uploadedImage)
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/workflows/components/graph/Node.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// Save the updated params to the unsavedRunStore to be referenced in Actions
const errorClass = 'input-error'
const handleParamChange = (event, param, index: number): void => {
const updatedArg = Number(event?.target?.value)
let updatedArg = Number(event?.target?.value)
const invalid =
updatedArg < 0 ||
(param?.max && updatedArg > param.max) ||
Expand Down
2 changes: 1 addition & 1 deletion src/routes/workflows/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const STATUS_COLOURS = {
}

export const BLUR_PARAMS = [
{ name: 'sigma', type: 'number', min: 0.1, max: 0.99, note: 'float < 1', default: 0.1 }
{ name: 'sigma', type: 'number', min: 0.1, max: 100, default: 0.1 }
]
export const CROP_PARAMS = [
{ name: 'x', type: 'number', default: 50 },
Expand Down

0 comments on commit 6feb9bb

Please sign in to comment.