generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(RV-XXXX): Add prettier and prettier run (#434)
- Loading branch information
1 parent
319902d
commit 7d130c2
Showing
92 changed files
with
4,288 additions
and
3,919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,62 @@ | ||
import { ImageToTextArgs, ImageToTextResponse, AlignImageArgs, AlignImageResponse } from "./types/types"; | ||
import { | ||
ImageToTextArgs, | ||
ImageToTextResponse, | ||
AlignImageArgs, | ||
AlignImageResponse, | ||
} from "./types/types"; | ||
|
||
const apiUrl = import.meta.env.VITE_API_URL || "http://localhost:8000/" | ||
const middlewareURL = import.meta.env.VITE_MIDDLEWARE_URL || "http://localhost:8080/"; | ||
const apiUrl = import.meta.env.VITE_API_URL || "http://localhost:8000/"; | ||
const middlewareURL = | ||
import.meta.env.VITE_MIDDLEWARE_URL || "http://localhost:8080/"; | ||
|
||
export const AlignImage = async (args: AlignImageArgs): Promise<AlignImageResponse> => { | ||
const { sourceImage, templateImage } = args; | ||
const form = new URLSearchParams({ | ||
source_image: sourceImage, | ||
segmentation_template: templateImage, | ||
}); | ||
export const AlignImage = async ( | ||
args: AlignImageArgs, | ||
): Promise<AlignImageResponse> => { | ||
const { sourceImage, templateImage } = args; | ||
const form = new URLSearchParams({ | ||
source_image: sourceImage, | ||
segmentation_template: templateImage, | ||
}); | ||
|
||
const alignImageURL = `${apiUrl}image_alignment/` | ||
try { | ||
const response = await fetch(alignImageURL, { | ||
"method": "POST", | ||
"headers": { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
body: form | ||
}) | ||
return await response.json() as AlignImageResponse; | ||
} catch (error) { | ||
console.error(error); | ||
return {result: sourceImage}; | ||
} | ||
} | ||
const alignImageURL = `${apiUrl}image_alignment/`; | ||
try { | ||
const response = await fetch(alignImageURL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: form, | ||
}); | ||
return (await response.json()) as AlignImageResponse; | ||
} catch (error) { | ||
console.error(error); | ||
return { result: sourceImage }; | ||
} | ||
}; | ||
|
||
export const ImageToText = async (args: ImageToTextArgs): Promise<ImageToTextResponse | null> => { | ||
export const ImageToText = async ( | ||
args: ImageToTextArgs, | ||
): Promise<ImageToTextResponse | null> => { | ||
const { sourceImage, templateImage, fieldNames } = args; | ||
const aligned_result = await AlignImage({ sourceImage, templateImage }); | ||
const form = new URLSearchParams({ | ||
source_image: aligned_result["result"], | ||
segmentation_template: templateImage, | ||
labels: JSON.stringify(fieldNames), | ||
}); | ||
|
||
const { sourceImage, templateImage, fieldNames } = args; | ||
const aligned_result = await AlignImage({sourceImage, templateImage}); | ||
const form = new URLSearchParams({ | ||
source_image: aligned_result["result"], | ||
segmentation_template: templateImage, | ||
labels: JSON.stringify(fieldNames), | ||
}); | ||
|
||
const imageToTextURL = `${middlewareURL}api/image_file_to_text` | ||
try { | ||
const response = await fetch(imageToTextURL, { | ||
"method": "POST", | ||
"headers": { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
}, | ||
body: form | ||
}) | ||
return await response.json() as ImageToTextResponse; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
|
||
} | ||
const imageToTextURL = `${middlewareURL}api/image_file_to_text`; | ||
try { | ||
const response = await fetch(imageToTextURL, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: form, | ||
}); | ||
return (await response.json()) as ImageToTextResponse; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.