Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,56 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|