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

Ml initialization #11

Merged
merged 34 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
29da859
ml : OCR 및 리뷰 분류 1차 작업/ dataset 가공 및 코드 수정 요
ozeeeno Oct 25, 2023
a0529bb
Merge branch 'ml-initialization' of github.com:snuhcs-course/swpp-202…
eldpswp99 Oct 26, 2023
3d9cbeb
fastapi initialization
eldpswp99 Oct 26, 2023
0a83c00
Merge branch 'main' of github.com:snuhcs-course/swpp-2023-project-tea…
eldpswp99 Oct 26, 2023
a6b6295
ml deploy test
eldpswp99 Oct 26, 2023
a0cd824
deploy backend
eldpswp99 Oct 29, 2023
f886e68
ml : 리뷰긍부정 분류 1차 완성
ozeeeno Nov 2, 2023
c741299
server update
eldpswp99 Nov 2, 2023
41a03f0
resolve conflict
ozeeeno Nov 2, 2023
e435c22
rollback workflow to main
eldpswp99 Nov 2, 2023
b26196c
Merge branch 'ml-initialization' of github.com:snuhcs-course/swpp-202…
eldpswp99 Nov 2, 2023
ccfa22f
user predic
eldpswp99 Nov 2, 2023
09131bb
fix import
eldpswp99 Nov 2, 2023
81a6479
fix import
eldpswp99 Nov 2, 2023
21aef7c
train
eldpswp99 Nov 2, 2023
1abd048
fix typo
eldpswp99 Nov 2, 2023
f4d6a96
fix import
eldpswp99 Nov 2, 2023
91f215a
fix import
eldpswp99 Nov 2, 2023
f77f7aa
implement: clova ocr document model implemented
ozeeeno Nov 4, 2023
7a3eb51
resolve : review part resolve
ozeeeno Nov 4, 2023
9142f4a
resolve confilct
ozeeeno Nov 4, 2023
1385e3b
implement : for model execution
ozeeeno Nov 4, 2023
25b9509
preset ml server interaction
eldpswp99 Nov 6, 2023
9ee20bb
Merge branch 'ml-initialization' of github.com:snuhcs-course/swpp-202…
eldpswp99 Nov 6, 2023
8f4895a
gitignore model pt
eldpswp99 Nov 6, 2023
508f509
server use function in execution.pu
eldpswp99 Nov 6, 2023
60550b4
remove print
eldpswp99 Nov 6, 2023
2d39ea3
disable receipt price
eldpswp99 Nov 6, 2023
e7d6979
response type check
eldpswp99 Nov 6, 2023
045610d
interaction with nest and ml server
eldpswp99 Nov 7, 2023
412a3f5
test github workflow
eldpswp99 Nov 7, 2023
cb30e72
Merge branch 'main' into ml-initialization
eldpswp99 Nov 7, 2023
f4a5f5e
add restaurant name
eldpswp99 Nov 7, 2023
d0cb999
Merge branch 'ml-initialization' of github.com:snuhcs-course/swpp-202…
eldpswp99 Nov 7, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/publish-backend-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
username: eldpswp99
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build image
Expand All @@ -51,4 +51,4 @@ jobs:
username: eldpswp99
password: ${{ secrets.DOCKER_TOKEN }}
- name: Docker compose up
run: SHA=${GITHUB_SHA} docker compose -f ~/docker-compose.yml up -d fooriend-backend
run: SHA=${GITHUB_SHA} docker compose -f ~/docker-compose.yml up -d
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: 테스트

on:
push:
branches: [ "main" ]
branches:
- "main"
pull_request:
branches: [ "main" ]
branches:
- "main"

jobs:
test:
Expand Down
41 changes: 36 additions & 5 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/bcryptjs": "^2.4.5",
"@types/jsonwebtoken": "^9.0.3",
"@types/multer": "^1.4.8",
"axios": "^1.6.0",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand Down
3 changes: 3 additions & 0 deletions backend/src/review/dtos/in-dtos/restaurant.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export class RestaurantDto {
@IsString()
googleMapPlaceId: string;

@IsString()
name: string;

@IsNumber()
latitude: number;

Expand Down
10 changes: 9 additions & 1 deletion backend/src/review/dtos/out-dtos/restaurant.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ export class RestaurantDto {
private googleMapPlaceId: string;
private longitude: number;
private latitude: number;
private name: string;

constructor({ id, googleMapPlaceId, longitude, latitude }: RestaurantEntity) {
constructor({
id,
googleMapPlaceId,
longitude,
latitude,
name,
}: RestaurantEntity) {
this.id = id;
this.googleMapPlaceId = googleMapPlaceId;
this.longitude = longitude;
this.latitude = latitude;
this.name = name;
}
}
19 changes: 19 additions & 0 deletions backend/src/review/ml-remote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import axios from 'axios';

export async function getReceiptOcr(imageUrl: string) {
return (
await axios.post(`${process.env.ML_URL}ocr`, {
image_url: imageUrl,
})
).data;
}

export async function getReviewIsPositive(review: string) {
return (
(
await axios.post(`${process.env.ML_URL}review`, {
review,
})
).data['result'] === '긍정'
);
}
3 changes: 3 additions & 0 deletions backend/src/review/models/restaurant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class RestaurantEntity extends IssuedAtMetaEntity {
@Column({ type: 'float8' })
longitude: number;

@Column({ type: 'varchar', default: '' })
name: string;

@OneToMany(() => ReviewEntity, (review) => review.restaurant)
reviews: ReviewEntity[];
}
6 changes: 6 additions & 0 deletions backend/src/review/models/review.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export class ReviewEntity extends IssuedAtMetaEntity {
@Column({ type: 'varchar' })
content: string;

@Column({ type: 'boolean', default: false })
isPositive: boolean;

@Column('varchar', { array: true, default: [] })
menu: string[];

get receiptImage() {
return this.images.find((image) => image.isReceipt);
}
Expand Down
3 changes: 2 additions & 1 deletion backend/src/review/repositories/restaurant.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RestaurantDto } from '../dtos/in-dtos/restaurant.dto';
@CustomRepository(RestaurantEntity)
export class RestaurantRepository extends Repository<RestaurantEntity> {
async findOrCreate(data: RestaurantDto) {
const { googleMapPlaceId, longitude, latitude } = data;
const { googleMapPlaceId, longitude, latitude, name } = data;
const restaurant = await this.findOne({
where: { googleMapPlaceId },
});
Expand All @@ -17,6 +17,7 @@ export class RestaurantRepository extends Repository<RestaurantEntity> {
googleMapPlaceId,
longitude,
latitude,
name,
}).save();
}
}
19 changes: 18 additions & 1 deletion backend/src/review/review.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { UserEntity } from '../user/models/user.entity';
import { CreateReviewDto } from './dtos/in-dtos/createReview.dto';
import { RestaurantRepository } from './repositories/restaurant.repository';
Expand All @@ -7,6 +7,7 @@ import { In } from 'typeorm';
import { ReviewEntity } from './models/review.entity';
import { ReviewAdjacentQueryDto } from './dtos/in-dtos/review-adjacent-query.dto';
import { getDistance } from 'geolib';
import { getReceiptOcr, getReviewIsPositive } from './ml-remote';
import { RestaurantEntity } from './models/restaurant.entity';

@Injectable()
Expand All @@ -29,15 +30,31 @@ export class ReviewService {
id: In(imageIds.concat([receiptImageId ?? -1])),
});
const receiptImage = images.find((image) => image.id === receiptImageId);
let menu = [];
if (receiptImage) {
await receiptImage.markAsReceipt();
try {
const receiptData = await getReceiptOcr(receiptImage.url);
menu = receiptData['menu'];
} catch (e) {
throw new BadRequestException('잘못된 영수증입니다.');
}
}

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

return await ReviewEntity.create({
content,
user,
restaurant,
images,
isPositive,
menu,
}).save();
}

Expand Down
Loading