Skip to content

Commit d254cd1

Browse files
authored
Merge pull request #66 from PytorchConnectomics/Inference-keep-going
fixed inference disruption problem
2 parents 30bbe67 + 99d9fc0 commit d254cd1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

client/src/views/ModelInference.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import { startModelInference, stopModelInference } from '../utils/api'
55
import Configurator from '../components/Configurator'
66
import { AppContext } from '../contexts/GlobalContext'
77

8-
function ModelInference () {
8+
function ModelInference ({ isInferring, setIsInferring }) {
99
const context = useContext(AppContext)
10-
const [isInference, setIsInference] = useState(false)
10+
// const [isInference, setIsInference] = useState(false)
1111
const handleStartButton = async () => {
1212
try {
1313
const inferenceConfig = localStorage.getItem('inferenceConfig')
1414

15-
const res = startModelInference(
15+
// const res = startModelInference(
16+
const res = await startModelInference(
1617
context.uploadedYamlFile.name,
1718
inferenceConfig,
1819
context.outputPath,
@@ -22,17 +23,19 @@ function ModelInference () {
2223
} catch (e) {
2324
console.log(e)
2425
} finally {
25-
setIsInference(true)
26+
// setIsInference(true)
27+
setIsInferring(true)
2628
}
2729
}
2830

2931
const handleStopButton = async () => {
3032
try {
31-
stopModelInference()
33+
await stopModelInference()
3234
} catch (e) {
3335
console.log(e)
3436
} finally {
35-
setIsInference(false)
37+
// setIsInference(false)
38+
setIsInferring(false)
3639
}
3740
}
3841

@@ -49,13 +52,13 @@ function ModelInference () {
4952
<Space wrap style={{ marginTop: 12 }} size={componentSize}>
5053
<Button
5154
onClick={handleStartButton}
52-
disabled={isInference} // Disables the button when inference is running
55+
disabled={isInferring} // Disables the button when inference is running
5356
>
5457
Start Inference
5558
</Button>
5659
<Button
5760
onClick={handleStopButton}
58-
disabled={!isInference} // Disables the button when inference is not running
61+
disabled={!isInferring} // Disables the button when inference is not running
5962
>
6063
Stop Inference
6164
</Button>

client/src/views/Views.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import DataLoader from './DataLoader'
33
import Visualization from '../views/Visualization'
44
import ModelTraining from '../views/ModelTraining'
@@ -13,6 +13,7 @@ function Views () {
1313
const [current, setCurrent] = useState('visualization')
1414
const [viewers, setViewers] = useState([])
1515
const [isLoading, setIsLoading] = useState(false)
16+
const [isInferring, setIsInferring] = useState(false)
1617
console.log(viewers)
1718

1819
const onClick = (e) => {
@@ -34,7 +35,7 @@ function Views () {
3435
} else if (current === 'monitoring') {
3536
return <Monitoring />
3637
} else if (current === 'inference') {
37-
return <ModelInference />
38+
return <ModelInference isInferring={isInferring} setIsInferring={setIsInferring} />
3839
}
3940
}
4041

@@ -80,6 +81,12 @@ function Views () {
8081
}
8182
}
8283

84+
useEffect(() => { // This function makes sure that the inferring will continue when current tab changes
85+
if (current === 'inference' && isInferring) {
86+
console.log('Inference process is continuing...')
87+
}
88+
}, [current, isInferring])
89+
8390
return (
8491
<Layout
8592
style={{

0 commit comments

Comments
 (0)