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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -8
app.py CHANGED
@@ -1,4 +1,47 @@
1
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 and not output_file_path: # 였λ₯˜ λ°œμƒ μ‹œμ—λ§Œ μ€‘μš” 정보 ν‘œμ‹œ
106
- status_message += "\n\nπŸ” μ£Όμš” 정보:\n" + "\n".join(important_info)
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