| import streamlit as st |
| import pandas as pd |
| import pickle |
|
|
| |
| with open('best_model.pkl', 'rb') as model_file: |
| input_weight_model = pickle.load(model_file) |
| with open('inspection_model.pkl', 'rb') as model_file: |
| machining_model = pickle.load(model_file) |
| with open('machining_model.pkl', 'rb') as model_file: |
| inspection_model = pickle.load(model_file) |
|
|
| |
| final_landed_cost = { |
| '1 MT XX (25-95 dia)': 103, |
| '1 MT XX (100-210 dia)': 113, |
| '1 MT YY (25-95 dia)': 160, |
| '1 MT YY (100-125 dia)': 173, |
| '1 MT XY (25-95 dia))': 106, |
| '1 MT 8319 (100-210 dia)':116, |
| '1 MT 8319':104 |
| } |
|
|
| |
| def calculate_raw_material_cost(process_type, input_weight, grade_type): |
| if process_type == 0: |
| return 0 |
| elif process_type == 1: |
| return input_weight * final_landed_cost[grade_type] |
|
|
|
|
| |
| def calculate_process_cost(process_type, input_weight): |
| if process_type == 0: |
| return (input_weight * (120.57788 / 1000)*1000) |
| elif process_type == 1: |
| return input_weight * 30 |
|
|
| |
| st.title("EX-Works Calculator") |
|
|
| |
| with st.form("input_form"): |
| part_no = st.number_input("Part No", min_value=1, step=1) |
| process_type = st.selectbox("Process Type", options=[0,1]) |
| part_od = st.number_input("Part Od", min_value=0.0, step=0.1) |
| part_id = st.number_input("Part ID", min_value=0.0, step=0.1) |
| part_width = st.number_input("Part Width", min_value=0, step=1) |
| finish_wt = st.number_input("Finish Wt", min_value=0.0, step=0.1) |
| grade_type = st.selectbox("Grade Type", options=list(final_landed_cost.keys())) |
| |
| submitted = st.form_submit_button("Calculate") |
|
|
| if submitted: |
| |
| input_data = pd.DataFrame({ |
| 'Process type': [process_type], |
| 'Part Od': [part_od], |
| 'Part ID': [part_id], |
| 'Part Width': [part_width], |
| 'Finish Wt': [finish_wt] |
| }) |
|
|
| |
| predicted_input_weight = input_weight_model.predict(input_data)[0] |
|
|
| |
| raw_material_cost = calculate_raw_material_cost(process_type, predicted_input_weight, grade_type) |
| |
| |
| process_cost = calculate_process_cost(process_type, predicted_input_weight) |
| |
| |
| machining_data = pd.DataFrame({ |
| 'Process type': [process_type], |
| 'Part Od': [part_od], |
| 'Part ID': [part_id], |
| 'Part Width': [part_width], |
| 'Finish Wt': [finish_wt], |
| 'Input Weight': [predicted_input_weight], |
| 'Raw material cost': [raw_material_cost], |
| 'Process cost': [process_cost] |
| }) |
|
|
| |
| predicted_machining_time = machining_model.predict(machining_data)[0] |
|
|
| |
| machining_cost = predicted_machining_time * 375.71 |
| |
| |
| scrap_recovery = (predicted_input_weight - finish_wt) * 11.5 |
| |
| |
| inspection_data = pd.DataFrame({ |
| 'Process type': [process_type], |
| 'Part Od': [part_od], |
| 'Part ID': [part_id], |
| 'Part Width': [part_width], |
| 'Finish Wt': [finish_wt], |
| 'Input Weight': [predicted_input_weight], |
| 'Raw material cost': [raw_material_cost], |
| 'Process cost': [process_cost], |
| 'Machining Time': [predicted_machining_time], |
| 'Machining cost ': [machining_cost], |
| }) |
|
|
| |
| predicted_inspection_time = inspection_model.predict(inspection_data)[0] |
| |
| |
| inspection_cost = predicted_inspection_time * 435.43 |
| |
| |
| total_mg_cost = raw_material_cost + process_cost + machining_cost + inspection_cost - scrap_recovery |
| |
| |
| rejection_on_manufacturing_cost = total_mg_cost * 0.003 |
| |
| |
| oiling_inspection_cost = total_mg_cost * 0.005 |
| |
| |
| transport_packing_cost = total_mg_cost * 0.01 |
| |
| |
| overheads_profit_material = raw_material_cost * 0.003 |
|
|
| |
| overheads_profit_conversion = (total_mg_cost - raw_material_cost) * 0.07 |
|
|
| |
| icc = total_mg_cost * 0.01 |
| |
| ex_works = total_mg_cost + rejection_on_manufacturing_cost + oiling_inspection_cost + \ |
| transport_packing_cost + overheads_profit_material + overheads_profit_conversion |
|
|
| |
| data = { |
| 'Part No': [part_no], |
| 'Process type': ['casting' if process_type == 0 else 'forging'], |
| 'Part Od': [part_od], |
| 'Part ID': [part_id], |
| 'Part Width': [part_width], |
| 'Finish Wt': [finish_wt], |
| 'Predicted Input Weight': [predicted_input_weight], |
| 'Grade type': [grade_type], |
| 'Raw material cost': [raw_material_cost], |
| 'Process cost': [process_cost], |
| 'Predicted Machining Time': [predicted_machining_time], |
| 'Machining Cost': [machining_cost], |
| 'Scrap Recovery': [scrap_recovery], |
| 'Predicted Inspection Time': [predicted_inspection_time], |
| 'Inspection Cost': [inspection_cost], |
| 'Total Mg Cost': [total_mg_cost], |
| 'Rejection on Manufacturing cost': [rejection_on_manufacturing_cost], |
| 'Oiling, Inspectio': [oiling_inspection_cost], |
| 'Transport and packing( BIN + 80 micron bag)': [transport_packing_cost], |
| 'Overheads & Profit on Material': [overheads_profit_material], |
| 'Overheads & Profit on Conversion': [overheads_profit_conversion], |
| 'ICC': [icc], |
| 'Ex-works': [ex_works] |
| } |
|
|
| df = pd.DataFrame(data) |
| |
| st.write("Input Data, Predicted Input Weight, and Calculated Costs:") |
| st.dataframe(df) |
|
|