File size: 2,828 Bytes
a1c2775
 
91ef415
 
e4778c4
91ef415
 
 
 
 
 
 
 
 
 
 
 
e4778c4
91ef415
 
 
 
 
 
e4778c4
91ef415
 
1c115a9
91ef415
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c115a9
91ef415
a1c2775
91ef415
 
 
a1c2775
91ef415
a1c2775
91ef415
 
 
 
 
 
 
 
 
 
 
a1c2775
91ef415
 
a1c2775
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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()