hariqueen commited on
Commit
fd99d5c
Β·
verified Β·
1 Parent(s): 01e49ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -16
app.py CHANGED
@@ -1,17 +1,56 @@
1
  import gradio as gr
2
- from main import process_uploaded_file
3
-
4
- def run_preprocessing(uploaded_file):
5
- output_csv_path = process_uploaded_file(uploaded_file)
6
- return output_csv_path
7
-
8
- iface = gr.Interface(
9
- fn=run_preprocessing,
10
- inputs=gr.File(label="λ Œνƒˆλ£Œ 파일 μ—…λ‘œλ“œ (CSV)"),
11
- outputs=gr.File(label="μ „μ²˜λ¦¬ μ™„λ£Œ 파일 λ‹€μš΄λ‘œλ“œ"),
12
- title="ERP μžλ™ μ „ν‘œ λ³€ν™˜κΈ°",
13
- description="CSV νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ©΄ μžλ™μœΌλ‘œ ERP μ—…λ‘œλ“œμš© 파일둜 λ³€ν™˜ν•΄μ€λ‹ˆλ‹€."
14
- )
15
-
16
- if __name__ == "__main__":
17
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import main # κΈ°μ‘΄ μ „μ²˜λ¦¬ ν•¨μˆ˜λ“€μ„ main.pyμ—μ„œ κ°€μ Έμ˜¨λ‹€κ³  κ°€μ •ν• κ²Œ
3
+ import os
4
+ import pandas as pd
5
+
6
+ def process_file(file, voucher_number):
7
+ if file is None:
8
+ return None
9
+
10
+ # μ—…λ‘œλ“œλœ 파일 μ €μž₯
11
+ input_path = f"temp_upload/{file.name}"
12
+ os.makedirs("temp_upload", exist_ok=True)
13
+ file.save(input_path)
14
+
15
+ # 파일 ν™•μž₯자 확인
16
+ ext = os.path.splitext(input_path)[1].lower()
17
+
18
+ if ext == ".xlsx":
19
+ # μ—‘μ…€ 파일 μ½μ–΄μ„œ CSV둜 λ³€ν™˜
20
+ df = pd.read_excel(input_path)
21
+ csv_path = input_path.replace(".xlsx", ".csv")
22
+ df.to_csv(csv_path, index=False)
23
+ input_path = csv_path
24
+
25
+ # 메인 μ „μ²˜λ¦¬ ν•¨μˆ˜ 호좜 (μˆ˜μ • μ˜ˆμ •)
26
+ output_path = main.process_rental_company_with_voucher(input_path, voucher_number)
27
+
28
+ return output_path
29
+
30
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("# ERP μžλ™ μ „ν‘œ λ³€ν™˜κΈ°\nCSV λ˜λŠ” μ—‘μ…€ νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ³  μ „ν‘œλ²ˆν˜Έλ₯Ό μž…λ ₯ν•˜μ„Έμš”.")
33
+
34
+ with gr.Row():
35
+ file_input = gr.File(label="λ Œνƒˆλ£Œ 파일 μ—…λ‘œλ“œ (CSV λ˜λŠ” Excel)", file_types=[".csv", ".xlsx"])
36
+ voucher_input = gr.Textbox(label="μ „ν‘œλ²ˆν˜Έ μž…λ ₯", placeholder="예: 20250427001")
37
+
38
+ with gr.Row():
39
+ submit_btn = gr.Button("제좜")
40
+ clear_btn = gr.Button("μ§€μš°κΈ°")
41
+
42
+ output_file = gr.File(label="μ „μ²˜λ¦¬ μ™„λ£Œ 파일 λ‹€μš΄λ‘œλ“œ")
43
+
44
+ submit_btn.click(
45
+ process_file,
46
+ inputs=[file_input, voucher_input],
47
+ outputs=output_file
48
+ )
49
+
50
+ clear_btn.click(
51
+ lambda: (None, ""),
52
+ inputs=[],
53
+ outputs=[file_input, voucher_input]
54
+ )
55
+
56
+ demo.launch()