File size: 1,776 Bytes
bd6d9a2
98c9fa6
fd99d5c
 
 
98c9fa6
 
fd99d5c
 
 
98c9fa6
fd99d5c
 
98c9fa6
 
 
fd99d5c
 
98c9fa6
 
 
fd99d5c
98c9fa6
fd99d5c
 
 
 
 
 
98c9fa6
fd99d5c
 
98c9fa6
 
 
 
 
 
 
 
 
fd99d5c
 
 
 
 
 
 
98c9fa6
fd99d5c
98c9fa6
fd99d5c
 
 
 
 
98c9fa6
fd99d5c
 
 
 
 
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
import gradio as gr
import main  # main.py์— ์ž‘์„ฑ๋œ ์ „์ฒ˜๋ฆฌ ๋กœ์ง ํ˜ธ์ถœ
import os
import pandas as pd

def process_file(file_path, voucher_number):
    if file_path is None:
        return None

    # ํŒŒ์ผ ํ™•์žฅ์ž ํ™•์ธ
    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)

    return output_path

# 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"   # โญ ์—ฌ๊ธฐ๊ฐ€ ์ค‘์š”!
        )
        voucher_input = gr.Textbox(
            label="์ „ํ‘œ๋ฒˆํ˜ธ ์ž…๋ ฅ",
            placeholder="์˜ˆ: 20250427001"
        )

    with gr.Row():
        submit_btn = gr.Button("์ œ์ถœ")
        clear_btn = gr.Button("์ง€์šฐ๊ธฐ")

    output_file = gr.File(label="์ „์ฒ˜๋ฆฌ ์™„๋ฃŒ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ")

    # ๋ฒ„ํŠผ ํด๋ฆญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
    submit_btn.click(
        fn=process_file,
        inputs=[file_input, voucher_input],
        outputs=output_file
    )

    clear_btn.click(
        fn=lambda: (None, ""),
        inputs=[],
        outputs=[file_input, voucher_input]
    )

demo.launch()