Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import main #
|
| 3 |
import os
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
def process_file(
|
| 7 |
-
if
|
| 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(
|
| 17 |
|
| 18 |
if ext == ".xlsx":
|
| 19 |
-
# 엑셀
|
| 20 |
-
df = pd.read_excel(
|
| 21 |
-
csv_path =
|
| 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 자동 전표 변환기\
|
| 33 |
|
| 34 |
with gr.Row():
|
| 35 |
-
file_input = gr.File(
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
with gr.Row():
|
| 39 |
submit_btn = gr.Button("제출")
|
|
@@ -41,14 +46,15 @@ with gr.Blocks() as demo:
|
|
| 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 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import main # main.py에 작성된 전처리 로직 호출
|
| 3 |
import os
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
+
def process_file(file_path, voucher_number):
|
| 7 |
+
if file_path is None:
|
| 8 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# 파일 확장자 확인
|
| 11 |
+
ext = os.path.splitext(file_path)[1].lower()
|
| 12 |
|
| 13 |
if ext == ".xlsx":
|
| 14 |
+
# 엑셀 파일을 CSV로 변환
|
| 15 |
+
df = pd.read_excel(file_path)
|
| 16 |
+
csv_path = file_path.replace(".xlsx", ".csv")
|
| 17 |
df.to_csv(csv_path, index=False)
|
| 18 |
input_path = csv_path
|
| 19 |
+
else:
|
| 20 |
+
# 이미 CSV 파일이면 그대로 사용
|
| 21 |
+
input_path = file_path
|
| 22 |
|
| 23 |
+
# 메인 전처리 함수 호출 (전표번호 넘겨주기)
|
| 24 |
output_path = main.process_rental_company_with_voucher(input_path, voucher_number)
|
| 25 |
|
| 26 |
return output_path
|
| 27 |
|
| 28 |
# Gradio 인터페이스 구성
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# ERP 자동 전표 변환기\n\n업로드할 파일과 전표번호를 입력하세요.")
|
| 31 |
|
| 32 |
with gr.Row():
|
| 33 |
+
file_input = gr.File(
|
| 34 |
+
label="렌탈료 파일 업로드 (CSV 또는 Excel)",
|
| 35 |
+
file_types=[".csv", ".xlsx"],
|
| 36 |
+
type="filepath" # ⭐ 여기가 중요!
|
| 37 |
+
)
|
| 38 |
+
voucher_input = gr.Textbox(
|
| 39 |
+
label="전표번호 입력",
|
| 40 |
+
placeholder="예: 20250427001"
|
| 41 |
+
)
|
| 42 |
|
| 43 |
with gr.Row():
|
| 44 |
submit_btn = gr.Button("제출")
|
|
|
|
| 46 |
|
| 47 |
output_file = gr.File(label="전처리 완료 파일 다운로드")
|
| 48 |
|
| 49 |
+
# 버튼 클릭 이벤트 연결
|
| 50 |
submit_btn.click(
|
| 51 |
+
fn=process_file,
|
| 52 |
inputs=[file_input, voucher_input],
|
| 53 |
outputs=output_file
|
| 54 |
)
|
| 55 |
|
| 56 |
clear_btn.click(
|
| 57 |
+
fn=lambda: (None, ""),
|
| 58 |
inputs=[],
|
| 59 |
outputs=[file_input, voucher_input]
|
| 60 |
)
|