Skip to content
Open

Csy #14

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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified BankingServer/.DS_Store
Binary file not shown.
Binary file modified BankingServer/BankingServer/.DS_Store
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion BankingServer/BankingServer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
path('admin/', admin.site.urls),
path('', include(router.urls)),
path('process_audio/', views.process_audio, name='process_audio'),
path('get_bank/', views.get_bank, name='get_bank'),
path('post_bank/', views.post_bank, name='post_bank'),
path('accounts/', include('accounts.urls', namespace='accounts')),
path('money/', include('money.urls', namespace='money')),
]
Expand Down
61 changes: 37 additions & 24 deletions BankingServer/BankingServer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,43 @@
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

def get_bank(request):
if request.method == 'GET':
@csrf_exempt
def post_bank(request):
if request.method == 'POST':
# 클라이언트로부터 문자열 받기
user_input = request.GET.get('voiceBank') #"궁민은행"으로 입력받으면

# 비교 대상 문자열 목록
candidates = ["국민은행", "농협은행", "신한은행", "우리은행", "하나은행"]
#"궁민은행"과 제일 비슷한 값을 찾음

# 가장 가까운 문자열 찾기
min_distance = float('inf') # 최소 거리 초기화
closest_candidate = None

for candidate in candidates:
distance = textdistance.levenshtein(user_input, candidate)
if distance < min_distance:
min_distance = distance
closest_candidate = candidate

# 결과 리턴
response_data = {
"closest_bank": closest_candidate,
}
return JsonResponse(response_data)
try:
request_data = json.loads(request.body.decode('utf-8'))
user_input = request_data.get('voice_bank')
except json.JSONDecodeError as e:
# JSON 디코딩 오류 처리
return JsonResponse({"error": "Invalid JSON format"}, status=400)

print("client:", user_input)

if user_input is not None:
# 비교 대상 문자열 목록
candidates = ["국민은행", "신한은행", "우리은행", "하나은행", "농협은행", "기업은행", "토스뱅크", "카카오뱅크"]
# "궁민은행"과 제일 비슷한 값을 찾음

# 가장 가까운 문자열 찾기
min_distance = float('inf') # 최소 거리 초기화
closest_candidate = None

for candidate in candidates:
distance = textdistance.levenshtein(user_input, candidate)
if distance < min_distance:
min_distance = distance
closest_candidate = candidate

print("return", closest_candidate)
# 결과 리턴
response_data = {
"closest_bank": closest_candidate,
}
return JsonResponse(response_data)
else:
# 'user_input'이 None인 경우 처리
return JsonResponse({"error": "User input is missing."}, status=400)


# POST 응답 처리
Expand Down Expand Up @@ -83,7 +96,7 @@ def load_resnet_model():
nn.Dropout(p=0.5),
nn.Linear(512, 10)
)
resnet.load_state_dict(torch.load('BankingServer/resnetModel/best_resnet34_weights(911).pth'))
resnet.load_state_dict(torch.load('BankingServer/resnetModel/best_resnet34_weights(911_v2).pth'))
resnet.eval()
model_loaded = True

Expand Down
Binary file removed BankingServer/combined.wav
Binary file not shown.
Binary file modified BankingServer/money/.DS_Store
Binary file not shown.
14 changes: 8 additions & 6 deletions BankingServer/money/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def post(self, request):

if serializer.is_valid():
# # account_bank_to와 account_no_to 값을 추출
# account_bank_to = request.data.get('account_bank_to')
# account_no_to = request.data.get('account_no_to')
account_bank_to = request.data.get('account_bank_to')
account_no_to = request.data.get('account_no_to')

# 이체 정보 저장
transfer_instance = serializer.save()
Expand All @@ -59,17 +59,19 @@ def post(self, request):

if money.balance < amount:
# 잔액 부족 예외 처리
return Response({"error": "잔액 부족"}, status=status.HTTP_400_BAD_REQUEST)
print("잔액부족")
return Response({"return_msg": "잔액 부족"}, status=status.HTTP_400_BAD_REQUEST)

money.balance -= amount
money.save()

# response_data = {
# "user_id": user_id # Money 모델의 user_id 값을 클라이언트로 전달
# }

return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
print("송금완료:", money, amount, account_bank_to, account_no_to)
return_msg = "송금완료"
return Response({"return_msg": return_msg}, status=status.HTTP_201_CREATED)
return Response({"return_msg": "송금 실패"}, status=status.HTTP_400_BAD_REQUEST)


class BalanceCheckView(APIView):
Expand Down
Binary file removed BankingServer/my_audio_file.aac
Binary file not shown.
Binary file removed BankingServer/my_audio_file.wav
Binary file not shown.
Binary file added BankingServer/static/.DS_Store
Binary file not shown.
Binary file added BankingServer/static/images/.DS_Store
Binary file not shown.
Binary file removed BankingServer/static/images/test.jpg
Binary file not shown.