Spaces:
Sleeping
Sleeping
File size: 6,572 Bytes
2129e5e 98c9fa6 fd99d5c 675f467 3f55dc7 675f467 fd99d5c 3f47d42 675f467 3f47d42 98c9fa6 675f467 3f47d42 fd99d5c 675f467 fd99d5c 675f467 fd99d5c 3f47d42 675f467 3f55dc7 675f467 d6463ae 3f55dc7 675f467 d6463ae 3f55dc7 d6463ae 3f55dc7 d6463ae 675f467 fd99d5c 3f47d42 fd99d5c 98c9fa6 675f467 98c9fa6 3f47d42 98c9fa6 3f47d42 98c9fa6 3f47d42 fd99d5c 675f467 fd99d5c 3f55dc7 675f467 fd99d5c 98c9fa6 fd99d5c 98c9fa6 3f47d42 675f467 fd99d5c 3f47d42 fd99d5c 3f47d42 fd99d5c 675f467 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import gradio as gr
import main # main.pyμ μμ±λ μ μ²λ¦¬ λ‘μ§ νΈμΆ
import os
import pandas as pd
import traceback
import sys
import re
from io import StringIO
def process_file(file_path, voucher_number, employee_number):
# μν λ©μμ§μ κ²°κ³Όλ₯Ό ν¨κ» λ°ννκΈ° μν λ³μ μ΄κΈ°ν
status_message = ""
output_file_path = None
# λ‘κ·Έλ₯Ό μΊ‘μ²νκΈ° μν StringIO κ°μ²΄
log_capture = StringIO()
# μ
λ ₯κ° κ²μ¦
if file_path is None:
return None, "νμΌμ μ
λ‘λν΄μ£ΌμΈμ."
if not voucher_number or not voucher_number.strip():
return None, "μ νλ²νΈλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
if not employee_number or not employee_number.strip():
return None, "μ¬μλ²νΈλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ. μ¬μλ²νΈλ νμ μ
λ ₯κ°μ
λλ€."
try:
# νμ€ μΆλ ₯μ μΊ‘μ²
original_stdout = sys.stdout
sys.stdout = log_capture
# νμΌ νμ₯μ νμΈ
ext = os.path.splitext(file_path)[1].lower()
if ext == ".xlsx":
# μμ
νμΌμ CSVλ‘ λ³ν
df = pd.read_excel(file_path)
csv_path = file_path.replace(".xlsx", ".csv")
df.to_csv(csv_path, index=False)
input_path = csv_path
else:
# μ΄λ―Έ CSV νμΌμ΄λ©΄ κ·Έλλ‘ μ¬μ©
input_path = file_path
# λ©μΈ μ μ²λ¦¬ ν¨μ νΈμΆ (μ νλ²νΈμ μ¬μλ²νΈ λ겨주기)
output_path = main.process_rental_company_with_voucher(input_path, voucher_number, employee_number)
output_file_path = output_path
# μ±κ³΅ λ©μμ§ μμ±
status_message = "β
νμΌ λ³ν μ±κ³΅! μ λ²νΌμ ν΄λ¦νμ¬ λ€μ΄λ‘λνμΈμ."
except Exception as e:
# μ€λ₯ λ°μ μ κ°λ¨ν μ€λ₯ λ©μμ§
status_message = f"β μ€λ₯ λ°μ: {str(e)}"
finally:
# μΊ‘μ²λ λ‘κ·Έ κ°μ Έμ€κΈ°
log_output = log_capture.getvalue()
sys.stdout = original_stdout # μλ νμ€ μΆλ ₯μΌλ‘ 볡ꡬ
# μ£Όμ μ 보 μΆμΆ (μ€λ₯ λ°μ μ¬λΆμ μκ΄μμ΄)
important_info = []
# κΈμ‘ νλ μ 보 μΆμΆ
amount_field_match = re.search(r"μ¬μ©ν κΈμ‘ νλ: '([^']*)'", log_output)
if amount_field_match:
important_info.append(f"μ¬μ©ν κΈμ‘ νλ: '{amount_field_match.group(1)}'")
# ν νλ μ 보 μΆμΆ
team_field_match = re.search(r"ν νλλ‘ '([^']*)'λ₯Ό μλ μΈμνμ΅λλ€", log_output)
if team_field_match:
important_info.append(f"ν νλλ‘ '{team_field_match.group(1)}'λ₯Ό μλ μΈμνμ΅λλ€.")
# μ μΈλ νλͺ© μ 보 μΆμΆ
excluded_rows_match = re.search(r"κΈμ‘μ΄ μλ ν\(λ°λ© νλͺ©\) (\d+)κ°λ₯Ό μ μΈν©λλ€", log_output)
if excluded_rows_match:
important_info.append(f"κΈμ‘μ΄ μλ ν(λ°λ© νλͺ©) {excluded_rows_match.group(1)}κ°λ₯Ό μ μΈν©λλ€.")
# κΈμ‘ μ 보 μΆμΆ
amt_info = []
debit_sum_match = re.search(r"μ°¨λ³ κΈμ‘ ν©κ³: (\d+)", log_output)
credit_sum_match = re.search(r"λλ³ κΈμ‘: (\d+)", log_output)
debit_count_match = re.search(r"μ°¨λ³ κ±΄μ: (\d+)", log_output)
credit_count_match = re.search(r"λλ³ κ±΄μ: (\d+)", log_output)
if debit_sum_match:
amt_info.append(f"μ°¨λ³ κΈμ‘ ν©κ³: {int(debit_sum_match.group(1)):,}")
if credit_sum_match:
amt_info.append(f"λλ³ κΈμ‘: {int(credit_sum_match.group(1)):,}")
if debit_count_match:
amt_info.append(f"μ°¨λ³ κ±΄μ: {debit_count_match.group(1)}")
if credit_count_match:
amt_info.append(f"λλ³ κ±΄μ: {credit_count_match.group(1)}")
if amt_info:
important_info.append("AMT νλ νμΈ:")
important_info.extend(amt_info)
# λ§€ν μ€λ₯ μ 보 μΆμΆ (μ€λ₯κ° μμ κ²½μ°μλ§)
if not output_file_path and "λ§€νλμ§ μμ νλͺ
" in log_output: # μ€λ₯ λ°μ μμλ§ λ§€ν μ 보 νμ
unmapped_section = re.search(r"λ§€νλμ§ μμ νλͺ
(\d+)κ°:(.*?)(?=\n\n|\Z)", log_output, re.DOTALL)
if unmapped_section:
unmapped_count = unmapped_section.group(1)
unmapped_teams = re.findall(r"- '([^']*)'", unmapped_section.group(2))
important_info.append(f"λ§€νλμ§ μμ νλͺ
{unmapped_count}κ°:")
for team in unmapped_teams:
important_info.append(f"- '{team}'")
# μ£Όμ μ 보λ₯Ό μν λ©μμ§μ μΆκ° (νμ)
if important_info:
status_message += "\n\n" + "\n".join(important_info)
return output_file_path, status_message
# Gradio μΈν°νμ΄μ€ ꡬμ±
with gr.Blocks() as demo:
gr.Markdown("# ERP μλ μ ν λ³νκΈ°\n\nμ
λ‘λν νμΌκ³Ό μ νλ²νΈ, μ¬μλ²νΈλ₯Ό μ
λ ₯νμΈμ.")
with gr.Row():
file_input = gr.File(
label="λ νλ£ νμΌ μ
λ‘λ (CSV λλ Excel)",
file_types=[".csv", ".xlsx"],
type="filepath"
)
with gr.Row():
voucher_input = gr.Textbox(
label="μ νλ²νΈ μ
λ ₯ (νμ)",
placeholder="μ: 20250427001"
)
employee_input = gr.Textbox(
label="μ¬μλ²νΈ μ
λ ₯ (νμ)",
placeholder="μ: 00616"
)
with gr.Row():
submit_btn = gr.Button("μ μΆ", variant="primary")
clear_btn = gr.Button("μ§μ°κΈ°")
output_file = gr.File(label="μ μ²λ¦¬ μλ£ νμΌ λ€μ΄λ‘λ")
# μν λ©μμ§λ₯Ό νμΌ λ€μ΄λ‘λ μμ μλλ‘ μ΄λ
status_output = gr.Textbox(
label="μ²λ¦¬ μν",
placeholder="νμΌμ μ μΆνλ©΄ μ²λ¦¬ μνκ° μ¬κΈ°μ νμλ©λλ€.",
lines=10
)
# λ²νΌ ν΄λ¦ μ΄λ²€νΈ μ°κ²°
submit_btn.click(
fn=process_file,
inputs=[file_input, voucher_input, employee_input],
outputs=[output_file, status_output]
)
clear_btn.click(
fn=lambda: (None, "", "", ""),
inputs=[],
outputs=[file_input, voucher_input, employee_input, status_output]
)
# μμ λ©μμ§ νμ
print("ERP μλ μ ν λ³νκΈ°κ° μμλμμ΅λλ€.")
demo.launch() |