Spaces:
Runtime error
Runtime error
File size: 1,199 Bytes
1748405 |
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 |
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()
|