Skip to content

Commit

Permalink
chore(RV-XXXX): Add prettier and prettier run (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
knguyenrise8 authored Nov 27, 2024
1 parent 319902d commit 7d130c2
Show file tree
Hide file tree
Showing 92 changed files with 4,288 additions and 3,919 deletions.
66 changes: 35 additions & 31 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,45 @@ to the the app in dev mode
npm run dev
```


# E2E common commands

Inside that directory, you can run several commands:

Runs the end-to-end tests.
```shell
npx playwright test
```
Runs the end-to-end tests.

```shell
npx playwright test
```

Starts the interactive UI mode.

```shell
npx playwright test --ui
```

Runs the tests only on Desktop Chrome.

Starts the interactive UI mode.
```shell
npx playwright test --ui
```
```shell
npx playwright test --project=chromium
```

Runs the tests only on Desktop Chrome.
```shell
npx playwright test --project=chromium
```
Runs the tests in a specific file.

Runs the tests in a specific file.
```shell
npx playwright test example
```
```shell
npx playwright test example
```

Runs the tests in debug mode.
```shell
npx playwright test --debug
```
Runs the tests in debug mode.

Auto generate tests with Codegen.
```shell
npx playwright codegen
```
```shell
npx playwright test --debug
```

Auto generate tests with Codegen.

```shell
npx playwright codegen
```

# React + TypeScript + Vite

Expand All @@ -68,11 +72,11 @@ export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
tsconfigRootDir: import.meta.dirname,
},
},
})
});
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
Expand All @@ -81,11 +85,11 @@ export default tseslint.config({

```js
// eslint.config.js
import react from 'eslint-plugin-react'
import react from "eslint-plugin-react";

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
settings: { react: { version: "18.3" } },
plugins: {
// Add the react plugin
react,
Expand All @@ -94,7 +98,7 @@ export default tseslint.config({
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...react.configs["jsx-runtime"].rules,
},
})
});
```
106 changes: 57 additions & 49 deletions frontend/api/api.ts
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;
}
};
54 changes: 27 additions & 27 deletions frontend/api/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { Field } from "../../src/contexts/FilesContext";

export interface Label {
color: string;
label: string;
type: string;
color: string;
label: string;
type: string;
}

export type Labels = Label[];

export type ImageToTextResponse = {
[key: string]: [string, number];
[key: string]: [string, number];
};

export type AlignImageResponse = {
[key: string]: string;
[key: string]: string;
};

export interface ResultItem {
text: string;
confidence: number;
}
export interface Submission {
template_name: string;
template_image: string; // Base64-encoded image string
file_name: string;
file_image: string; // Base64-encoded image string
results: {
[key: string]: ResultItem; // Allows any key with a ResultItem value
};
}

export interface ImageToTextArgs {
// base 64 encoded image
sourceImage: string;
templateImage: string;
fieldNames: Field[];
text: string;
confidence: number;
}

export interface Submission {
template_name: string;
template_image: string; // Base64-encoded image string
file_name: string;
file_image: string; // Base64-encoded image string
results: {
[key: string]: ResultItem; // Allows any key with a ResultItem value
};
}

export interface ImageToTextArgs {
// base 64 encoded image
sourceImage: string;
templateImage: string;
fieldNames: Field[];
}

export interface AlignImageArgs {
// base 64 encoded image
sourceImage: string;
templateImage: string;
// base 64 encoded image
sourceImage: string;
templateImage: string;
}
export interface PDF {
file: string;
Expand Down
Loading

0 comments on commit 7d130c2

Please sign in to comment.