samridh12 commited on
Commit
206b239
·
verified ·
1 Parent(s): c4a369f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -2
app.py CHANGED
@@ -45,7 +45,7 @@ def calculate_process_cost(process_type, input_weight):
45
  # Streamlit interface
46
  st.title("EX-Works Calculator")
47
 
48
- # Create tabs
49
  tabs = st.tabs(["Home", "Vendor Data", "Material Data", "RM Cost Data", "Supplier Data"])
50
 
51
  with tabs[0]:
@@ -80,4 +80,113 @@ with tabs[2]:
80
  green_drg_no = st.selectbox("Green DRG Number", options=[0, 1])
81
 
82
  if st.button("Add Material"):
83
- material_data = pd.DataFrame({'Part_id': [part_id], 'part_no': [part_no], 'scf': [scf], 'process_type': [process_type], 'part_od': [part_od], 'part_width': [part_width], 'part_inner_dimension': [part_inner_dimension], 'material_specification': [material_spec], 'finish_wt':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # Streamlit interface
46
  st.title("EX-Works Calculator")
47
 
48
+ # Tabs for page navigation
49
  tabs = st.tabs(["Home", "Vendor Data", "Material Data", "RM Cost Data", "Supplier Data"])
50
 
51
  with tabs[0]:
 
80
  green_drg_no = st.selectbox("Green DRG Number", options=[0, 1])
81
 
82
  if st.button("Add Material"):
83
+ material_data = pd.DataFrame({'Part_id': [part_id], 'part_no': [part_no], 'scf': [scf], 'process_type': [process_type], 'part_od': [part_od], 'part_width': [part_width], 'part_inner_dimension': [part_inner_dimension], 'material_specification': [material_spec], 'finish_wt': [finish_wt], 'green_drg_no': [green_drg_no]})
84
+ insert_data(conn, 'material_data', material_data)
85
+ st.success("Material data added successfully")
86
+
87
+ with tabs[3]:
88
+ st.header("RM Cost Data")
89
+ rm_type = st.text_input("RM Type")
90
+ rm_cost = st.number_input("RM Cost", min_value=0.0, step=0.01)
91
+ vendor_id = st.number_input("Vendor ID", min_value=1, step=1)
92
+
93
+ if st.button("Add RM Cost Data"):
94
+ rm_cost_data = pd.DataFrame({'rm_type': [rm_type], 'rm_cost': [rm_cost], 'vendor_id': [vendor_id]})
95
+ insert_data(conn, 'rm_cost_data', rm_cost_data)
96
+ st.success("RM cost data added successfully")
97
+
98
+ with tabs[4]:
99
+ st.header("Supplier Data")
100
+ part_no = st.number_input("Part No", min_value=1, step=1)
101
+ process_type = st.selectbox("Process Type", options=[0, 1])
102
+ part_od = st.number_input("Part OD", min_value=0.0, step=0.1)
103
+ part_id = st.number_input("Part ID", min_value=0.0, step=0.1)
104
+ part_width = st.number_input("Part Width", min_value=0, step=1)
105
+ finish_wt = st.number_input("Finish Wt", min_value=0.0, step=0.1)
106
+ grade_type = st.selectbox("Grade Type", options=list(final_landed_cost.keys()))
107
+ material_id = st.number_input("Material ID", min_value=1, step=1)
108
+
109
+ if st.button("Calculate and Add Supplier Data"):
110
+ # Prepare the input data for prediction
111
+ input_data = pd.DataFrame({
112
+ 'Process type': [process_type],
113
+ 'Part Od': [part_od],
114
+ 'Part ID': [part_id],
115
+ 'Part Width': [part_width],
116
+ 'Finish Wt': [finish_wt]
117
+ })
118
+
119
+ # Predict the input weight
120
+ predicted_input_weight = input_weight_model.predict(input_data)[0]
121
+
122
+ # Calculate raw material cost
123
+ raw_material_cost = calculate_raw_material_cost(process_type, predicted_input_weight, grade_type)
124
+
125
+ # Calculate process cost
126
+ process_cost = calculate_process_cost(process_type, predicted_input_weight)
127
+
128
+ # Prepare the data for machining time prediction
129
+ machining_data = pd.DataFrame({
130
+ 'Process type': [process_type],
131
+ 'Part Od': [part_od],
132
+ 'Part ID': [part_id],
133
+ 'Part Width': [part_width],
134
+ 'Finish Wt': [finish_wt],
135
+ 'Input Weight': [predicted_input_weight],
136
+ 'Raw material cost': [raw_material_cost],
137
+ 'Process cost': [process_cost]
138
+ })
139
+
140
+ # Predict the machining time
141
+ predicted_machining_time = machining_model.predict(machining_data)[0]
142
+
143
+ # Calculate machining cost
144
+ machining_cost = predicted_machining_time * 375.71
145
+
146
+ # Calculate scrap recovery
147
+ scrap_recovery = (predicted_input_weight - finish_wt) * 11.5
148
+
149
+ # Prepare the data for inspection time prediction
150
+ inspection_data = pd.DataFrame({
151
+ 'Process type': [process_type],
152
+ 'Part Od': [part_od],
153
+ 'Part ID': [part_id],
154
+ 'Part Width': [part_width],
155
+ 'Finish Wt': [finish_wt],
156
+ 'Input Weight': [predicted_input_weight],
157
+ 'Raw material cost': [raw_material_cost],
158
+ 'Process cost': [process_cost],
159
+ 'Machining Time': [predicted_machining_time],
160
+ 'Machining cost': [machining_cost],
161
+ 'Scrap recovery': [scrap_recovery]
162
+ })
163
+
164
+ # Predict the inspection time
165
+ predicted_inspection_time = inspection_model.predict(inspection_data)[0]
166
+
167
+ # Calculate inspection cost
168
+ inspection_cost = predicted_inspection_time * 375.71
169
+
170
+ # Calculate total manufacturing cost
171
+ total_mg_cost = raw_material_cost + process_cost + machining_cost - scrap_recovery + inspection_cost
172
+
173
+ # Insert supplier data
174
+ supplier_data = pd.DataFrame({
175
+ 'Part No': [part_no],
176
+ 'Process Type': [process_type],
177
+ 'Part OD': [part_od],
178
+ 'Part ID': [part_id],
179
+ 'Part Width': [part_width],
180
+ 'Finish Wt': [finish_wt],
181
+ 'Grade Type': [grade_type],
182
+ 'Material ID': [material_id],
183
+ 'Predicted Input Weight': [predicted_input_weight],
184
+ 'Raw Material Cost': [raw_material_cost],
185
+ 'Process Cost': [process_cost],
186
+ 'Machining Cost': [machining_cost],
187
+ 'Scrap Recovery': [scrap_recovery],
188
+ 'Inspection Cost': [inspection_cost],
189
+ 'Total Manufacturing Cost': [total_mg_cost]
190
+ })
191
+ insert_data(conn, 'supplier_data', supplier_data)
192
+ st.success("Supplier data added successfully")