hariqueen commited on
Commit
3f55dc7
Β·
verified Β·
1 Parent(s): 675f467

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -9
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)}\n\nπŸ” 상세 λ‚΄μš©:\n{error_detail}"
49
 
50
  finally:
51
  # 캑처된 둜그 κ°€μ Έμ˜€κΈ°
52
  log_output = log_capture.getvalue()
53
  sys.stdout = original_stdout # μ›λž˜ ν‘œμ€€ 좜λ ₯으둜 볡ꡬ
54
 
55
- # 둜그 좜λ ₯이 있으면 μƒνƒœ λ©”μ‹œμ§€μ— μΆ”κ°€
56
- if log_output.strip():
57
- status_message += f"\n\nπŸ“‹ 처리 둜그:\n{log_output}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(