Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invalid receipt #34

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions backend/src/review/review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export class ReviewService {
let images = await this.imageRepository.findBy({
id: In(imageIds.concat([receiptImageId ?? -1])),
});

let isPositive = false;
try {
isPositive = await getReviewIsPositive(content);
} catch (e) {
console.log(e);
throw new BadRequestException('리뷰 분석 중 오류가 발생했습니다.');
}

const receiptImage = images.find((image) => image.id === receiptImageId);
let menu = [];
if (receiptImage) {
Expand All @@ -42,13 +51,6 @@ export class ReviewService {
}
}

let isPositive = false;
try {
isPositive = await getReviewIsPositive(content);
} catch (e) {
throw new BadRequestException('리뷰 분석 중 오류가 발생했습니다.');
}

return await ReviewEntity.create({
content,
user,
Expand Down
3 changes: 3 additions & 0 deletions ml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ async def receipt_ocr(data: OcrModel):
jpg_image.save(receipt_path)
response = ocr_receipt(receipt_path)

if(response is None):
raise HTTPException(status_code=403, detail="잘못된 영수증입니다")

return response


Expand Down
3 changes: 3 additions & 0 deletions ml/ocr/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def ocr_receipt(path):
images = response_body["images"]
images_receipt = images[0].get("receipt")

if(images_receipt is None):
return None

receipt_title = images_receipt["result"]["storeInfo"]["name"]["text"]
receipt_address = images_receipt["result"]["storeInfo"]["addresses"][0]["text"]
receipt_date = images_receipt["result"]["paymentInfo"]["date"]["text"]
Expand Down
Loading