Browse Source

Update frontend to handle image auto labeling

pull/1413/head
Hironsan 3 years ago
parent
commit
dbb90d13a2
8 changed files with 51 additions and 9 deletions
  1. 3
      frontend/components/configAutoLabeling/ConfigCreationForm.vue
  2. 32
      frontend/components/configAutoLabeling/form/ConfigParameters.vue
  3. 2
      frontend/domain/models/autoLabeling/configRepository.ts
  4. 9
      frontend/domain/models/project/project.ts
  5. 4
      frontend/domain/models/tasks/annotationRepository.ts
  6. 4
      frontend/repositories/autoLabeling/config/apiConfigRepository.ts
  7. 4
      frontend/services/application/autoLabeling/configApplicationService.ts
  8. 2
      frontend/services/application/project/projectData.ts

3
frontend/components/configAutoLabeling/ConfigCreationForm.vue

@ -119,8 +119,9 @@ export default Vue.extend({
})
},
testParameters(text: string) {
const projectId = this.$route.params.id
const item = ConfigItem.parseFromUI(this.fields)
const promise = this.$services.config.testParameters(item, text)
const promise = this.$services.config.testParameters(projectId, item, text)
this.testConfig(promise, 'parameter')
},
testTemplate() {

32
frontend/components/configAutoLabeling/form/ConfigParameters.vue

@ -36,10 +36,20 @@
Please input sample text and press the <strong>Test</strong> button.
</p>
<v-text-field
v-if="project.isTextProject"
v-model="sampleText"
outlined
label="Sample Text"
/>
<v-file-input
v-else
v-model="file"
label="File input"
prepend-icon=""
prepend-inner-icon="$file"
outlined
@change="onChange"
/>
<v-alert
v-for="(error, index) in errorMessages"
:key="index"
@ -128,7 +138,27 @@ export default Vue.extend({
data() {
return {
sampleText: ''
sampleText: '',
file: null,
project: {}
}
},
async created() {
this.project = await this.$services.project.findById(this.$route.params.id)
},
methods: {
onChange() {
const reader = new FileReader()
if(this.file) {
reader.onload = () => {
// @ts-ignore
this.sampleText = reader.result.split(',').pop()
}
// @ts-ignore
reader.readAsDataURL(this.file)
}
}
}
})

2
frontend/domain/models/autoLabeling/configRepository.ts

@ -16,7 +16,7 @@ export interface ConfigRepository {
testConfig(projectId: string, item: ConfigItem, text: string): Promise<ConfigTestResponse>
testParameters(item: ConfigItem, text: string): Promise<ConfigTestResponse>
testParameters(projectId: string, item: ConfigItem, text: string): Promise<ConfigTestResponse>
testTemplate(projectId: string, response: any, item: ConfigItem): Promise<ConfigTestResponse>

9
frontend/domain/models/project/project.ts

@ -106,6 +106,15 @@ export class ProjectReadItem {
return allowedProjectTypes.includes(this.project_type)
}
get isTextProject() {
const allowedProjectTypes = [
'DocumentClassification',
'SequenceLabeling',
'Seq2seq'
]
return allowedProjectTypes.includes(this.project_type)
}
toObject(): Object {
return {
id: this.id,

4
frontend/domain/models/tasks/annotationRepository.ts

@ -31,11 +31,11 @@ export abstract class AnnotationRepository<T extends AnnotationModel> {
}
public async autoLabel(projectId: string, docId: number): Promise<void> {
const url = `/projects/${projectId}/docs/${docId}/auto-labeling`
const url = `/projects/${projectId}/examples/${docId}/auto-labeling`
await this.request.post(url, {})
}
protected baseUrl(projectId: string, docId: number): string {
return `/projects/${projectId}/docs/${docId}/annotations`
return `/projects/${projectId}/examples/${docId}/annotations`
}
}

4
frontend/repositories/autoLabeling/config/apiConfigRepository.ts

@ -61,8 +61,8 @@ export class APIConfigRepository implements ConfigRepository {
return responseItem
}
async testParameters(item: ConfigItem, text: string) {
const url = 'auto-labeling-parameter-testing'
async testParameters(projectId: string, item: ConfigItem, text: string) {
const url = `/projects/${projectId}/auto-labeling-parameter-testing`
const response = await this.request.post(url, {...item.toAPI(), text})
const responseItem: ConfigTestResponse = response.data
return responseItem

4
frontend/services/application/autoLabeling/configApplicationService.ts

@ -37,8 +37,8 @@ export class ConfigApplicationService {
})
}
public testParameters(item: ConfigItem, text: string) {
return this.configRepository.testParameters(item, text)
public testParameters(projectId: string, item: ConfigItem, text: string) {
return this.configRepository.testParameters(projectId, item, text)
.then((value) => {
return value
})

2
frontend/services/application/project/projectData.ts

@ -16,6 +16,7 @@ export class ProjectDTO {
tags: Object[]
canDefineLabel: Boolean
canDefineRelation: Boolean
isTextProject: Boolean
constructor(item: ProjectReadItem) {
this.id = item.id
@ -33,6 +34,7 @@ export class ProjectDTO {
this.tags = item.tags
this.canDefineLabel = item.canDefineLabel
this.canDefineRelation = item.canDefineRelation
this.isTextProject = item.isTextProject
}
}

Loading…
Cancel
Save