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(
|