Download app.py from VSPLC/AI: direct link, hf CLI and curl.
- Browser
- Download file 2.83 kB
-
https://huggingface.co/spaces/VSPLC/AI/resolve/main/app.py
- Command line
-
hf download hf://spaces/VSPLC/AI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VSPLC/AI/resolve/main/app.py
2.83 kB
| # app.py | |
| import gradio as gr | |
| import math | |
| import pandas as pd | |
| def production_planner(total_production, machines_available, daily_capacity_per_machine, target_days=None): | |
| """ | |
| Smart Production Planner: | |
| - total_production: total units to produce | |
| - machines_available: number of machines | |
| - daily_capacity_per_machine: units a machine produces per shift | |
| - target_days: optional, desired completion time | |
| """ | |
| if machines_available <= 0 or daily_capacity_per_machine <= 0 or total_production <= 0: | |
| return "All input values must be greater than 0", "", "", "", pd.DataFrame() | |
| capacity_per_day_one_shift = machines_available * daily_capacity_per_machine | |
| if target_days: | |
| shifts_per_day = math.ceil(total_production / (capacity_per_day_one_shift * target_days)) | |
| days_required = target_days | |
| else: | |
| days_required = math.ceil(total_production / capacity_per_day_one_shift) | |
| shifts_per_day = 1 | |
| production_per_shift_per_machine = daily_capacity_per_machine | |
| total_daily_capacity = capacity_per_day_one_shift * shifts_per_day | |
| # Generate shift distribution table | |
| production_remaining = total_production | |
| schedule = [] | |
| for day in range(1, days_required + 1): | |
| for shift in range(1, shifts_per_day + 1): | |
| shift_production = min(production_remaining, machines_available * production_per_shift_per_machine) | |
| schedule.append({ | |
| "Day": day, | |
| "Shift": shift, | |
| "Production This Shift": shift_production, | |
| "Production per Machine": math.ceil(shift_production / machines_available) | |
| }) | |
| production_remaining -= shift_production | |
| if production_remaining <= 0: | |
| break | |
| if production_remaining <= 0: | |
| break | |
| schedule_df = pd.DataFrame(schedule) | |
| return days_required, shifts_per_day, production_per_shift_per_machine, total_daily_capacity, schedule_df | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=production_planner, | |
| inputs=[ | |
| gr.Number(label="Total Production Required"), | |
| gr.Number(label="Number of Machines Available"), | |
| gr.Number(label="Daily Capacity per Machine"), | |
| gr.Number(label="Target Completion Days (optional)", value=None) | |
| ], | |
| outputs=[ | |
| gr.Number(label="Estimated Days Required"), | |
| gr.Number(label="Shifts Per Day Required"), | |
| gr.Number(label="Production per Shift per Machine"), | |
| gr.Number(label="Total Daily Production Capacity"), | |
| gr.Dataframe(label="Shift Distribution Schedule") | |
| ], | |
| title="Smart Production Planner", | |
| description="Enter production requirements, machine info, and optional target days to calculate days, shifts, and a full production schedule." | |
| ) | |
| demo.launch() | |