Download app.py from Hanuman17/Via: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/Hanuman17/Via/resolve/main/app.py
- Command line
-
hf download hf://spaces/Hanuman17/Via/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Hanuman17/Via/resolve/main/app.py
2.05 kB
| import pandas as pd | |
| import gradio as gr | |
| def process_excel(uploaded_file): | |
| try: | |
| all_sheets = pd.read_excel(uploaded_file.name, sheet_name=None, engine="openpyxl") | |
| ordered_sheetnames = [k for k in all_sheets.keys() if k.strip().upper() != "TEMPLATE" and not all_sheets[k].empty] | |
| records = [] | |
| for week in ordered_sheetnames: | |
| df = all_sheets[week].rename(columns=lambda x: str(x).strip()) | |
| name_col = next((c for c in df.columns if "name" in str(c).lower()), None) | |
| shift_col = next((c for c in df.columns if "shift" in str(c).lower()), None) | |
| if not name_col or not shift_col: | |
| continue | |
| valid = df[name_col].notnull() & df[shift_col].notnull() & (df[shift_col] > 0) | |
| for _, row in df.loc[valid, [name_col, shift_col]].iterrows(): | |
| emp = str(row[name_col]).strip() | |
| num_shifts = float(row[shift_col]) | |
| if emp and not emp.lower().startswith("unnamed"): | |
| records.append({"Week": week, "Employee": emp, "No_of_Shift": num_shifts}) | |
| output_file = "Filtered_Excel.xlsx" | |
| if not records: | |
| error_file = "Error_No_Data_Found.txt" | |
| with open(error_file, "w") as f: | |
| f.write("No employee/shift data found.") | |
| return error_file | |
| df_all = pd.DataFrame(records) | |
| df_all['Week'] = pd.Categorical(df_all['Week'], categories=ordered_sheetnames, ordered=True) | |
| book2 = df_all.pivot_table(index="Week", columns="Employee", values="No_of_Shift", fill_value="").reset_index() | |
| book2.to_excel(output_file, index=False) | |
| return output_file | |
| except Exception as e: | |
| error_file = "Error.txt" | |
| with open(error_file, "w") as f: | |
| f.write(str(e)) | |
| return error_file | |
| iface = gr.Interface( | |
| fn=process_excel, | |
| inputs=gr.File(label="Upload Excel File"), | |
| outputs=gr.File(label="Download Filtered Excel"), | |
| title="Excel Employee Shift Filter" | |
| ) | |
| iface.launch() | |