Skip to content

Commit

Permalink
CU-8695x1dy9: runs model in background process. Needs some more UI im…
Browse files Browse the repository at this point in the history
…provements to indicate model running is happening and status of the running process also.
  • Loading branch information
tomolopolis committed Sep 23, 2024
1 parent ce04429 commit 0a6e946
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
22 changes: 17 additions & 5 deletions webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ def prepare_documents(request):
'but is still set on the project. To fix remove and reset the '
'cui filter file' % project.cuis_file}, status=500)

if request.data.get('bg_task'):
# execute model infer in bg
job = prep_docs(p_id, d_ids, user.id)
return Response({'bg_job_id': job.id})

try:
for d_id in d_ids:
document = Document.objects.get(id=d_id)
Expand Down Expand Up @@ -294,6 +289,23 @@ def prepare_documents(request):
return Response({'message': 'Documents prepared successfully'})


@api_view(http_method_names=['POST'])
def prepare_documents_bg(request):
user = request.user
# Get project id
p_id = request.data['project_id']
project = ProjectAnnotateEntities.objects.get(id=p_id)
docs = Document.objects.filter(dataset=project.dataset)

# Get annotated entities
d_ids = [d.id for d in docs if len(AnnotatedEntity.objects.filter(document=d).filter(project=project)) > 0 or
d in project.validated_documents.all]

# execute model infer in bg
job = prep_docs(p_id, d_ids, user.id)
return Response({'bg_job_id': job.id})


@api_view(http_method_names=['GET'])
def prepare_docs_bg_tasks(request):
proj_id = int(request.GET['project'])
Expand Down
1 change: 1 addition & 0 deletions webapp/api/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
path('api/anno-conf/', api.views.get_anno_tool_conf),
path('api/search-concepts/', api.views.search_solr),
path('api/prepare-documents/', api.views.prepare_documents),
path('api/prepare-documents-bg/', api.views.prepare_documents_bg),
path('api/prep-docs-bg-tasks/', api.views.prepare_docs_bg_tasks),
path('api/api-token-auth/', auth_views.obtain_auth_token),
path('admin/', admin.site.urls),
Expand Down
16 changes: 0 additions & 16 deletions webapp/frontend/src/components/common/DocumentSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,7 @@ export default {
runningBgTasks: []
}
},
created() {
// this.pollDocPrepStatus(true)
},
methods: {
pollDocPrepStatus (pollInfinite) {
if (this.projId) {
this.$http.get(`/api/prep-docs-bg-tasks/?project=${this.projId}`).then(resp => {
this.runningBgTasks = resp.data.running_tasks.map(d => d.document)
this.completeBgTasks = resp.data.comp_tasks.map(d => d.document)
})
if (pollInfinite) {
setTimeout(this.pollDocPrepStatus, 5000)
}
} else {
setTimeout(this.pollDocPrepStatus, 5000)
}
},
scrollSelectedDocId () {
const el = document.getElementsByClassName('selected-doc')
if (el.length > 0) {
Expand Down
15 changes: 15 additions & 0 deletions webapp/frontend/src/components/common/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
</button>
</div>
</template>
<template #cell(run_model)="data">
<button class="btn btn-outline-primary">
<font-awesome-icon icon="robot" @click="runModel(data.item.id)"></font-awesome-icon>
</button>
</template>
<template #cell(metrics)="data">
<button class="btn"
:class="{'btn-primary': selectedProjects.indexOf(data.item) !== -1, 'btn-outline-primary': selectedProjects.indexOf(data.item) === -1}"
Expand Down Expand Up @@ -198,13 +203,15 @@ export default {
{ key: 'progress', label: 'Progress', formatter: this.progressFormatter },
{ key: 'anno_class', label: 'Annotation Classification', sortable: true },
{ key: 'cdb_search_filter', label: 'Concepts Imported' },
{ key: 'run_model', label: 'Run Model' },
{ key: 'model_loaded', label: 'Model Loaded' },
{ key: 'metrics', label: 'Metrics' },
{ key: 'save_model', label: 'Save Model' }
],
adminOnlyFields: [
'anno_class',
'cdb_search_filter',
'run_model',
'model_loaded',
'save_model'
]
Expand Down Expand Up @@ -282,6 +289,14 @@ export default {
}, 5000)
}
},
runModel (projectId) {
let payload = {
project_id: projectId
}
this.$http.post('/api/prepare-documents-bg/', payload).then(_ => {
// disable the row
})
},
saveModel (projectId) {
let payload = {
project_id: projectId
Expand Down
13 changes: 13 additions & 0 deletions webapp/frontend/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ export default {
this.selectedProjectGroup.items = this.projects.items.filter(p => p.group === this.selectedProjectGroup.id)
}
},
pollDocPrepStatus (pollInfinite) {
if (this.projId) {
this.$http.get(`/api/prep-docs-bg-tasks/?project=${this.projId}`).then(resp => {
this.runningBgTasks = resp.data.running_tasks.map(d => d.document)
this.completeBgTasks = resp.data.comp_tasks.map(d => d.document)
})
if (pollInfinite) {
setTimeout(this.pollDocPrepStatus, 5000)
}
} else {
setTimeout(this.pollDocPrepStatus, 5000)
}
},
}
}
</script>
Expand Down
8 changes: 0 additions & 8 deletions webapp/frontend/src/views/TrainAnnotations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,6 @@ export default {
this.currentEnt = null
this.prepareDoc()
},
prepareDocBg (doc) {
let payload = {
project_id: this.project.id,
document_ids: [doc.id],
bg_task: true
}
this.$http.post('/api/prepare-documents/', payload)
},
prepareDoc () {
this.loadingMsg = "Loading MedCAT model..."
this.$http.get(`/api/cache-model/${this.project.concept_db}/`).then(_ => {
Expand Down

0 comments on commit 0a6e946

Please sign in to comment.