wip: add interactive seg model

This commit is contained in:
Qing
2022-11-27 21:25:27 +08:00
parent af87cca643
commit 023306ae40
20 changed files with 820 additions and 46 deletions

View File

@@ -114,3 +114,31 @@ export function modelDownloaded(name: string) {
method: 'GET',
})
}
export async function postInteractiveSeg(
imageFile: File,
maskFile: File | null,
clicks: number[][]
) {
const fd = new FormData()
fd.append('image', imageFile)
fd.append('clicks', JSON.stringify(clicks))
if (maskFile !== null) {
fd.append('mask', maskFile)
}
try {
const res = await fetch(`${API_ENDPOINT}/interactive_seg`, {
method: 'POST',
body: fd,
})
if (res.ok) {
const blob = await res.blob()
return { blob: URL.createObjectURL(blob) }
}
const errMsg = await res.text()
throw new Error(errMsg)
} catch (error) {
throw new Error(`Something went wrong: ${error}`)
}
}