Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,71 @@
|
|
| 1 |
# app.py
|
| 2 |
-
import pickle
|
| 3 |
-
import numpy as np
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
if
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
model = pickle.load(f)
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
X = np.array([[daily_capacity, demand, material_available]])
|
| 21 |
-
risk = model.predict_proba(X)[0][1]
|
| 22 |
-
return round(float(risk), 3)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
demo = gr.Interface(
|
| 25 |
-
fn=
|
| 26 |
inputs=[
|
| 27 |
-
gr.Number(label="
|
| 28 |
-
gr.Number(label="
|
| 29 |
-
gr.Number(label="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
],
|
| 31 |
-
|
| 32 |
-
|
| 33 |
)
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
| 1 |
# app.py
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
import math
|
| 4 |
+
import pandas as pd
|
| 5 |
|
| 6 |
+
def production_planner(total_production, machines_available, daily_capacity_per_machine, target_days=None):
|
| 7 |
+
"""
|
| 8 |
+
Smart Production Planner:
|
| 9 |
+
- total_production: total units to produce
|
| 10 |
+
- machines_available: number of machines
|
| 11 |
+
- daily_capacity_per_machine: units a machine produces per shift
|
| 12 |
+
- target_days: optional, desired completion time
|
| 13 |
+
"""
|
| 14 |
+
if machines_available <= 0 or daily_capacity_per_machine <= 0 or total_production <= 0:
|
| 15 |
+
return "All input values must be greater than 0", "", "", "", pd.DataFrame()
|
| 16 |
+
|
| 17 |
+
capacity_per_day_one_shift = machines_available * daily_capacity_per_machine
|
| 18 |
|
| 19 |
+
if target_days:
|
| 20 |
+
shifts_per_day = math.ceil(total_production / (capacity_per_day_one_shift * target_days))
|
| 21 |
+
days_required = target_days
|
| 22 |
+
else:
|
| 23 |
+
days_required = math.ceil(total_production / capacity_per_day_one_shift)
|
| 24 |
+
shifts_per_day = 1
|
| 25 |
|
| 26 |
+
production_per_shift_per_machine = daily_capacity_per_machine
|
| 27 |
+
total_daily_capacity = capacity_per_day_one_shift * shifts_per_day
|
|
|
|
| 28 |
|
| 29 |
+
# Generate shift distribution table
|
| 30 |
+
production_remaining = total_production
|
| 31 |
+
schedule = []
|
| 32 |
+
for day in range(1, days_required + 1):
|
| 33 |
+
for shift in range(1, shifts_per_day + 1):
|
| 34 |
+
shift_production = min(production_remaining, machines_available * production_per_shift_per_machine)
|
| 35 |
+
schedule.append({
|
| 36 |
+
"Day": day,
|
| 37 |
+
"Shift": shift,
|
| 38 |
+
"Production This Shift": shift_production,
|
| 39 |
+
"Production per Machine": math.ceil(shift_production / machines_available)
|
| 40 |
+
})
|
| 41 |
+
production_remaining -= shift_production
|
| 42 |
+
if production_remaining <= 0:
|
| 43 |
+
break
|
| 44 |
+
if production_remaining <= 0:
|
| 45 |
+
break
|
| 46 |
|
| 47 |
+
schedule_df = pd.DataFrame(schedule)
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
return days_required, shifts_per_day, production_per_shift_per_machine, total_daily_capacity, schedule_df
|
| 50 |
+
|
| 51 |
+
# Gradio interface
|
| 52 |
demo = gr.Interface(
|
| 53 |
+
fn=production_planner,
|
| 54 |
inputs=[
|
| 55 |
+
gr.Number(label="Total Production Required"),
|
| 56 |
+
gr.Number(label="Number of Machines Available"),
|
| 57 |
+
gr.Number(label="Daily Capacity per Machine"),
|
| 58 |
+
gr.Number(label="Target Completion Days (optional)", value=None)
|
| 59 |
+
],
|
| 60 |
+
outputs=[
|
| 61 |
+
gr.Number(label="Estimated Days Required"),
|
| 62 |
+
gr.Number(label="Shifts Per Day Required"),
|
| 63 |
+
gr.Number(label="Production per Shift per Machine"),
|
| 64 |
+
gr.Number(label="Total Daily Production Capacity"),
|
| 65 |
+
gr.Dataframe(label="Shift Distribution Schedule")
|
| 66 |
],
|
| 67 |
+
title="Smart Production Planner",
|
| 68 |
+
description="Enter production requirements, machine info, and optional target days to calculate days, shifts, and a full production schedule."
|
| 69 |
)
|
| 70 |
|
| 71 |
demo.launch()
|