Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import os
|
|
| 4 |
import pandas as pd
|
| 5 |
import traceback
|
| 6 |
import sys
|
|
|
|
| 7 |
from io import StringIO
|
| 8 |
|
| 9 |
def process_file(file_path, voucher_number):
|
|
@@ -40,21 +41,69 @@ def process_file(file_path, voucher_number):
|
|
| 40 |
output_file_path = output_path
|
| 41 |
|
| 42 |
# 성공 메시지 작성
|
| 43 |
-
status_message = "✅ 파일 변환 성공!
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
# 오류 발생 시 상세 오류 내용 캡처
|
| 47 |
error_detail = traceback.format_exc()
|
| 48 |
-
status_message = f"❌ 오류 발생: {str(e)}
|
| 49 |
|
| 50 |
finally:
|
| 51 |
# 캡처된 로그 가져오기
|
| 52 |
log_output = log_capture.getvalue()
|
| 53 |
sys.stdout = original_stdout # 원래 표준 출력으로 복구
|
| 54 |
|
| 55 |
-
# 로그
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
return output_file_path, status_message
|
| 60 |
|
|
@@ -76,15 +125,15 @@ with gr.Blocks() as demo:
|
|
| 76 |
with gr.Row():
|
| 77 |
submit_btn = gr.Button("제출", variant="primary")
|
| 78 |
clear_btn = gr.Button("지우기")
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
status_output = gr.Textbox(
|
| 82 |
label="처리 상태",
|
| 83 |
placeholder="파일을 제출하면 처리 상태가 여기에 표시됩니다.",
|
| 84 |
lines=10
|
| 85 |
)
|
| 86 |
-
|
| 87 |
-
output_file = gr.File(label="전처리 완료 파일 다운로드")
|
| 88 |
|
| 89 |
# 버튼 클릭 이벤트 연결
|
| 90 |
submit_btn.click(
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import traceback
|
| 6 |
import sys
|
| 7 |
+
import re
|
| 8 |
from io import StringIO
|
| 9 |
|
| 10 |
def process_file(file_path, voucher_number):
|
|
|
|
| 41 |
output_file_path = output_path
|
| 42 |
|
| 43 |
# 성공 메시지 작성
|
| 44 |
+
status_message = "✅ 파일 변환 성공! 위 버튼을 클릭하여 다운로드하세요."
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
# 오류 발생 시 상세 오류 내용 캡처
|
| 48 |
error_detail = traceback.format_exc()
|
| 49 |
+
status_message = f"❌ 오류 발생: {str(e)}"
|
| 50 |
|
| 51 |
finally:
|
| 52 |
# 캡처된 로그 가져오기
|
| 53 |
log_output = log_capture.getvalue()
|
| 54 |
sys.stdout = original_stdout # 원래 표준 출력으로 복구
|
| 55 |
|
| 56 |
+
# 필요한 로그 정보만 추출
|
| 57 |
+
important_info = []
|
| 58 |
+
|
| 59 |
+
# 금액 필드 정보 추출
|
| 60 |
+
amount_field_match = re.search(r"사용할 금액 필드: '([^']*)'", log_output)
|
| 61 |
+
if amount_field_match:
|
| 62 |
+
important_info.append(f"사용할 금액 필드: '{amount_field_match.group(1)}'")
|
| 63 |
+
|
| 64 |
+
# 팀 필드 정보 추출
|
| 65 |
+
team_field_match = re.search(r"팀 필드로 '([^']*)'를 자동 인식했습니다", log_output)
|
| 66 |
+
if team_field_match:
|
| 67 |
+
important_info.append(f"팀 필드로 '{team_field_match.group(1)}'를 자동 인식했습니다.")
|
| 68 |
+
|
| 69 |
+
# 제외된 항목 정보 추출
|
| 70 |
+
excluded_rows_match = re.search(r"금액이 없는 행\(반납 항목\) (\d+)개를 제외합니다", log_output)
|
| 71 |
+
if excluded_rows_match:
|
| 72 |
+
important_info.append(f"금액이 없는 행(반납 항목) {excluded_rows_match.group(1)}개를 제외합니다.")
|
| 73 |
+
|
| 74 |
+
# 금액 정보 추출
|
| 75 |
+
amt_info = []
|
| 76 |
+
debit_sum_match = re.search(r"차변 금액 합계: (\d+)", log_output)
|
| 77 |
+
credit_sum_match = re.search(r"대변 금액: (\d+)", log_output)
|
| 78 |
+
debit_count_match = re.search(r"차변 건수: (\d+)", log_output)
|
| 79 |
+
credit_count_match = re.search(r"대변 건수: (\d+)", log_output)
|
| 80 |
+
|
| 81 |
+
if debit_sum_match:
|
| 82 |
+
amt_info.append(f"차변 금액 합계: {int(debit_sum_match.group(1)):,}")
|
| 83 |
+
if credit_sum_match:
|
| 84 |
+
amt_info.append(f"대변 금액: {int(credit_sum_match.group(1)):,}")
|
| 85 |
+
if debit_count_match:
|
| 86 |
+
amt_info.append(f"차변 건수: {debit_count_match.group(1)}")
|
| 87 |
+
if credit_count_match:
|
| 88 |
+
amt_info.append(f"대변 건수: {credit_count_match.group(1)}")
|
| 89 |
+
|
| 90 |
+
if amt_info:
|
| 91 |
+
important_info.append("AMT 필드 확인:")
|
| 92 |
+
important_info.extend(amt_info)
|
| 93 |
+
|
| 94 |
+
# 매핑 오류 정보 추출 (오류가 있을 경우에만)
|
| 95 |
+
if "매핑되지 않은 팀명" in log_output:
|
| 96 |
+
unmapped_section = re.search(r"매핑되지 않은 팀명 (\d+)개:(.*?)(?=\n\n|\Z)", log_output, re.DOTALL)
|
| 97 |
+
if unmapped_section:
|
| 98 |
+
unmapped_count = unmapped_section.group(1)
|
| 99 |
+
unmapped_teams = re.findall(r"- '([^']*)'", unmapped_section.group(2))
|
| 100 |
+
important_info.append(f"매핑되지 않은 팀명 {unmapped_count}개:")
|
| 101 |
+
for team in unmapped_teams:
|
| 102 |
+
important_info.append(f"- '{team}'")
|
| 103 |
+
|
| 104 |
+
# 중요 정보를 상태 메시지에 추가
|
| 105 |
+
if important_info and not output_file_path: # 오류 발생 시에만 중요 정보 표시
|
| 106 |
+
status_message += "\n\n🔍 주요 정보:\n" + "\n".join(important_info)
|
| 107 |
|
| 108 |
return output_file_path, status_message
|
| 109 |
|
|
|
|
| 125 |
with gr.Row():
|
| 126 |
submit_btn = gr.Button("제출", variant="primary")
|
| 127 |
clear_btn = gr.Button("지우기")
|
| 128 |
+
|
| 129 |
+
output_file = gr.File(label="전처리 완료 파일 다운로드")
|
| 130 |
+
|
| 131 |
+
# 상태 메시지를 파일 다운로드 영역 아래로 이동
|
| 132 |
status_output = gr.Textbox(
|
| 133 |
label="처리 상태",
|
| 134 |
placeholder="파일을 제출하면 처리 상태가 여기에 표시됩니다.",
|
| 135 |
lines=10
|
| 136 |
)
|
|
|
|
|
|
|
| 137 |
|
| 138 |
# 버튼 클릭 이벤트 연결
|
| 139 |
submit_btn.click(
|