import tempfile import gradio as gr import pandas as pd from config import CONFIG from hr_utils.converter import get_data, make_table, parse from type_alias import GRADIO_OUTPUT WORKING_TIME = CONFIG.WORKING_TIME LATE = CONFIG.LATE def calculate(file: tempfile._TemporaryFileWrapper) -> GRADIO_OUTPUT: filename: str = file.name data: pd.DataFrame = pd.read_excel(filename) data = get_data(data=data) employees_list = parse(data=data) table = make_table(employees=employees_list) with tempfile.NamedTemporaryFile(mode="w+b", suffix=".xlsx", delete=False) as f: table.to_excel(f, index=False) downloadable_filename = f.name return downloadable_filename, table with gr.Blocks() as app: with gr.Row(): upload_file = gr.File(label="Upload file here") with gr.Row(): button = gr.Button(value="Calculate Working Time") with gr.Row(): download_processed_file = gr.File() with gr.Row(): processed_file = gr.DataFrame() button.click(fn=calculate, inputs=[upload_file], outputs=[download_processed_file, processed_file]) app.launch()