Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,47 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import main # main.pyμ μμ±λ μ μ²λ¦¬ λ‘μ§ νΈμΆ
|
| 3 |
import os
|
| 4 |
import pandas as pd
|
|
@@ -44,8 +87,7 @@ def process_file(file_path, voucher_number):
|
|
| 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:
|
|
@@ -53,7 +95,7 @@ def process_file(file_path, voucher_number):
|
|
| 53 |
log_output = log_capture.getvalue()
|
| 54 |
sys.stdout = original_stdout # μλ νμ€ μΆλ ₯μΌλ‘ 볡ꡬ
|
| 55 |
|
| 56 |
-
#
|
| 57 |
important_info = []
|
| 58 |
|
| 59 |
# κΈμ‘ νλ μ 보 μΆμΆ
|
|
@@ -92,7 +134,7 @@ def process_file(file_path, voucher_number):
|
|
| 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)
|
|
@@ -101,9 +143,9 @@ def process_file(file_path, voucher_number):
|
|
| 101 |
for team in unmapped_teams:
|
| 102 |
important_info.append(f"- '{team}'")
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
if important_info
|
| 106 |
-
status_message += "\n\n
|
| 107 |
|
| 108 |
return output_file_path, status_message
|
| 109 |
|
|
|
|
| 1 |
+
def process_file(file_path, voucher_number):
|
| 2 |
+
# μν λ©μμ§μ κ²°κ³Όλ₯Ό ν¨κ» λ°ννκΈ° μν λ³μ μ΄κΈ°ν
|
| 3 |
+
status_message = ""
|
| 4 |
+
output_file_path = None
|
| 5 |
+
|
| 6 |
+
# λ‘κ·Έλ₯Ό μΊ‘μ²νκΈ° μν StringIO κ°μ²΄
|
| 7 |
+
log_capture = StringIO()
|
| 8 |
+
|
| 9 |
+
if file_path is None:
|
| 10 |
+
return None, "νμΌμ μ
λ‘λν΄μ£ΌμΈμ."
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
# νμ€ μΆλ ₯μ μΊ‘μ²
|
| 14 |
+
original_stdout = sys.stdout
|
| 15 |
+
sys.stdout = log_capture
|
| 16 |
+
|
| 17 |
+
# νμΌ νμ₯μ νμΈ
|
| 18 |
+
ext = os.path.splitext(file_path)[1].lower()
|
| 19 |
+
|
| 20 |
+
if ext == ".xlsx":
|
| 21 |
+
# μμ
νμΌμ CSVλ‘ λ³ν
|
| 22 |
+
df = pd.read_excel(file_path)
|
| 23 |
+
csv_path = file_path.replace(".xlsx", ".csv")
|
| 24 |
+
df.to_csv(csv_path, index=False)
|
| 25 |
+
input_path = csv_path
|
| 26 |
+
else:
|
| 27 |
+
# μ΄λ―Έ CSV νμΌμ΄λ©΄ κ·Έλλ‘ μ¬μ©
|
| 28 |
+
input_path = file_path
|
| 29 |
+
|
| 30 |
+
# λ©μΈ μ μ²λ¦¬ ν¨μ νΈμΆ (μ νλ²νΈ λ겨주기)
|
| 31 |
+
output_path = main.process_rental_company_with_voucher(input_path, voucher_number)
|
| 32 |
+
output_file_path = output_path
|
| 33 |
+
|
| 34 |
+
# μ±κ³΅ λ©μμ§ μμ±
|
| 35 |
+
status_message = "β
νμΌ λ³ν μ±κ³΅! μ λ²νΌμ ν΄λ¦νμ¬ λ€μ΄λ‘λνμΈμ."
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
# μ€λ₯ λ°μ μ κ°λ¨ν μ€λ₯ λ©μμ§
|
| 39 |
+
status_message = f"β μ€λ₯ λ°μ: {str(e)}"
|
| 40 |
+
|
| 41 |
+
# μΊ‘μ²λ λ‘κ·Έ κ°μ Έμ€κΈ°
|
| 42 |
+
log_output = log_capture.getvalue()
|
| 43 |
+
|
| 44 |
+
# νμν λ‘κ·Έ μ 보λ§import gradio as gr
|
| 45 |
import main # main.pyμ μμ±λ μ μ²λ¦¬ λ‘μ§ νΈμΆ
|
| 46 |
import os
|
| 47 |
import pandas as pd
|
|
|
|
| 87 |
status_message = "β
νμΌ λ³ν μ±κ³΅! μ λ²νΌμ ν΄λ¦νμ¬ λ€μ΄λ‘λνμΈμ."
|
| 88 |
|
| 89 |
except Exception as e:
|
| 90 |
+
# μ€λ₯ λ°μ μ κ°λ¨ν μ€λ₯ λ©μμ§
|
|
|
|
| 91 |
status_message = f"β μ€λ₯ λ°μ: {str(e)}"
|
| 92 |
|
| 93 |
finally:
|
|
|
|
| 95 |
log_output = log_capture.getvalue()
|
| 96 |
sys.stdout = original_stdout # μλ νμ€ μΆλ ₯μΌλ‘ 볡ꡬ
|
| 97 |
|
| 98 |
+
# μ£Όμ μ 보 μΆμΆ (μ€λ₯ λ°μ μ¬λΆμ μκ΄μμ΄)
|
| 99 |
important_info = []
|
| 100 |
|
| 101 |
# κΈμ‘ νλ μ 보 μΆμΆ
|
|
|
|
| 134 |
important_info.extend(amt_info)
|
| 135 |
|
| 136 |
# λ§€ν μ€λ₯ μ 보 μΆμΆ (μ€λ₯κ° μμ κ²½μ°μλ§)
|
| 137 |
+
if not output_file_path and "λ§€νλμ§ μμ νλͺ
" in log_output: # μ€λ₯ λ°μ μμλ§ λ§€ν μ 보 νμ
|
| 138 |
unmapped_section = re.search(r"λ§€νλμ§ μμ νλͺ
(\d+)κ°:(.*?)(?=\n\n|\Z)", log_output, re.DOTALL)
|
| 139 |
if unmapped_section:
|
| 140 |
unmapped_count = unmapped_section.group(1)
|
|
|
|
| 143 |
for team in unmapped_teams:
|
| 144 |
important_info.append(f"- '{team}'")
|
| 145 |
|
| 146 |
+
# μ£Όμ μ 보λ₯Ό μν λ©μμ§μ μΆκ° (νμ)
|
| 147 |
+
if important_info:
|
| 148 |
+
status_message += "\n\n" + "\n".join(important_info)
|
| 149 |
|
| 150 |
return output_file_path, status_message
|
| 151 |
|