samridh12 commited on
Commit
c4a369f
·
verified ·
1 Parent(s): 7f5e350

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -115
app.py CHANGED
@@ -2,13 +2,10 @@ import streamlit as st
2
  import pandas as pd
3
  import pickle
4
  import os
5
- import sqlalchemy
6
- from database import create_connection, initialize_database, insert_data, fetch_data
7
-
8
 
9
  # Database setup
10
- conn = st.connection('example_db', type='sql')
11
-
12
 
13
  # Load the trained models
14
  current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -22,13 +19,13 @@ with open(os.path.join(current_dir, 'inspection_model.pkl'), 'rb') as model_file
22
 
23
  # Final landed cost based on grade type
24
  final_landed_cost = {
25
- '1 MT XX (25-95 dia)': 103,
26
- '1 MT XX (100-210 dia)': 113,
27
- '1 MT YY (25-95 dia)': 160,
28
- '1 MT YY (100-125 dia)': 173,
29
- '1 MT XY (25-95 dia))': 106,
30
- '1 MT 8319 (100-210 dia)':116,
31
- '1 MT 8319':104
32
  }
33
 
34
  # Function to calculate raw material cost
@@ -41,36 +38,35 @@ def calculate_raw_material_cost(process_type, input_weight, grade_type):
41
  # Function to calculate process cost
42
  def calculate_process_cost(process_type, input_weight):
43
  if process_type == 0: # 0 represents casting
44
- return (input_weight * (120.57788 / 1000) * 1000)
45
  elif process_type == 1: # 1 represents forging
46
  return input_weight * 30
47
 
48
  # Streamlit interface
49
  st.title("EX-Works Calculator")
50
 
51
- # Page navigation
52
- pages = ["Home", "Vendor Data", "Material Data", "RM Cost Data", "Supplier Data"]
53
- page = st.sidebar.selectbox("Select Page", pages)
54
 
55
- if page == "Home":
56
  st.write("Welcome to the EX-Works Calculator application.")
57
 
58
- elif page == "Vendor Data":
59
  st.header("Vendor Data")
60
  vendor_name = st.text_input("Vendor Name")
61
  vendor_type = st.text_input("Vendor Type")
62
- gst_no =st.number_input("GST NO")
63
- contact_person_name=st.text_input("CONTACT PERSON/NAME")
64
- address=st.text_input("ADDRESS")
65
- city=st.text_input("CITY")
66
- panno=st.text_input("PAN NO")
67
 
68
  if st.button("Add Vendor"):
69
- vendor_data = pd.DataFrame({'vendor_name': [vendor_name], 'vendor_type': [vendor_type], 'GST_NO': [gst_no], 'Contact_person_name': [contact_person_name], 'address': [address], 'city': [city], 'pan_no':[panno]})
70
  insert_data(conn, 'vendor_data', vendor_data)
71
  st.success("Vendor data added successfully")
72
 
73
- elif page == "Material Data":
74
  st.header("Material Data")
75
  part_id = st.number_input("Part ID")
76
  part_no = st.number_input("Part Number")
@@ -84,93 +80,4 @@ elif page == "Material Data":
84
  green_drg_no = st.selectbox("Green DRG Number", options=[0, 1])
85
 
86
  if st.button("Add Material"):
87
- 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]})
88
- insert_data(conn, 'material_data', material_data)
89
- st.success("Material data added successfully")
90
-
91
-
92
- elif page == "RM Cost Data":
93
- st.header("RM Cost Data")
94
- rm_type = st.text_input("RM Type")
95
- rm_cost = st.number_input("RM Cost", min_value=0.0, step=0.01)
96
- vendor_id = st.number_input("Vendor ID", min_value=1, step=1)
97
-
98
- if st.button("Add RM Cost Data"):
99
- rm_cost_data = pd.DataFrame({'rm_type': [rm_type], 'rm_cost': [rm_cost], 'vendor_id': [vendor_id]})
100
- insert_data(conn, 'rm_cost_data', rm_cost_data)
101
- st.success("RM cost data added successfully")
102
-
103
- elif page == "Supplier Data":
104
- st.header("Supplier Data")
105
- part_no = st.number_input("Part No", min_value=1, step=1)
106
- process_type = st.selectbox("Process Type", options=[0, 1])
107
- part_od = st.number_input("Part OD", min_value=0.0, step=0.1)
108
- part_id = st.number_input("Part ID", min_value=0.0, step=0.1)
109
- part_width = st.number_input("Part Width", min_value=0, step=1)
110
- finish_wt = st.number_input("Finish Wt", min_value=0.0, step=0.1)
111
- grade_type = st.selectbox("Grade Type", options=list(final_landed_cost.keys()))
112
- material_id = st.number_input("Material ID", min_value=1, step=1)
113
-
114
- if st.button("Calculate and Add Supplier Data"):
115
- # Prepare the input data for prediction
116
- input_data = pd.DataFrame({
117
- 'Process type': [process_type],
118
- 'Part Od': [part_od],
119
- 'Part ID': [part_id],
120
- 'Part Width': [part_width],
121
- 'Finish Wt': [finish_wt]
122
- })
123
-
124
- # Predict the input weight
125
- predicted_input_weight = input_weight_model.predict(input_data)[0]
126
-
127
- # Calculate raw material cost
128
- raw_material_cost = calculate_raw_material_cost(process_type, predicted_input_weight, grade_type)
129
-
130
- # Calculate process cost
131
- process_cost = calculate_process_cost(process_type, predicted_input_weight)
132
-
133
- # Prepare the data for machining time prediction
134
- machining_data = pd.DataFrame({
135
- 'Process type': [process_type],
136
- 'Part Od': [part_od],
137
- 'Part ID': [part_id],
138
- 'Part Width': [part_width],
139
- 'Finish Wt': [finish_wt],
140
- 'Input Weight': [predicted_input_weight],
141
- 'Raw material cost': [raw_material_cost],
142
- 'Process cost': [process_cost]
143
- })
144
-
145
- # Predict the machining time
146
- predicted_machining_time = machining_model.predict(machining_data)[0]
147
-
148
- # Calculate machining cost
149
- machining_cost = predicted_machining_time * 375.71
150
-
151
- # Calculate scrap recovery
152
- scrap_recovery = (predicted_input_weight - finish_wt) * 11.5
153
-
154
- # Prepare the data for inspection time prediction
155
- inspection_data = pd.DataFrame({
156
- 'Process type': [process_type],
157
- 'Part Od': [part_od],
158
- 'Part ID': [part_id],
159
- 'Part Width': [part_width],
160
- 'Finish Wt': [finish_wt],
161
- 'Input Weight': [predicted_input_weight],
162
- 'Raw material cost': [raw_material_cost],
163
- 'Process cost': [process_cost],
164
- 'Machining Time': [predicted_machining_time],
165
- 'Machining cost': [machining_cost],
166
- 'Scrap recovery': [scrap_recovery]
167
- })
168
-
169
- # Predict the inspection time
170
- predicted_inspection_time = inspection_model.predict(inspection_data)[0]
171
-
172
- # Calculate inspection cost
173
- inspection_cost = predicted_inspection_time * 375.71
174
-
175
- # Calculate total mg cost
176
- total_mg_cost = raw_material_cost + process_cost + machining_cost + scrap_recovery + inspection
 
2
  import pandas as pd
3
  import pickle
4
  import os
5
+ from database import create_connection, insert_data
 
 
6
 
7
  # Database setup
8
+ conn = create_connection('example_db') # Assuming this function is correctly defined in database.py
 
9
 
10
  # Load the trained models
11
  current_dir = os.path.dirname(os.path.abspath(__file__))
 
19
 
20
  # Final landed cost based on grade type
21
  final_landed_cost = {
22
+ '1 MT XX (25-95 dia)': 103,
23
+ '1 MT XX (100-210 dia)': 113,
24
+ '1 MT YY (25-95 dia)': 160,
25
+ '1 MT YY (100-125 dia)': 173,
26
+ '1 MT XY (25-95 dia)': 106,
27
+ '1 MT 8319 (100-210 dia)': 116,
28
+ '1 MT 8319': 104
29
  }
30
 
31
  # Function to calculate raw material cost
 
38
  # Function to calculate process cost
39
  def calculate_process_cost(process_type, input_weight):
40
  if process_type == 0: # 0 represents casting
41
+ return input_weight * (120.57788 / 1000) * 1000
42
  elif process_type == 1: # 1 represents forging
43
  return input_weight * 30
44
 
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]:
52
  st.write("Welcome to the EX-Works Calculator application.")
53
 
54
+ with tabs[1]:
55
  st.header("Vendor Data")
56
  vendor_name = st.text_input("Vendor Name")
57
  vendor_type = st.text_input("Vendor Type")
58
+ gst_no = st.number_input("GST NO")
59
+ contact_person_name = st.text_input("Contact Person/Name")
60
+ address = st.text_input("Address")
61
+ city = st.text_input("City")
62
+ panno = st.text_input("PAN NO")
63
 
64
  if st.button("Add Vendor"):
65
+ vendor_data = pd.DataFrame({'vendor_name': [vendor_name], 'vendor_type': [vendor_type], 'GST_NO': [gst_no], 'Contact_person_name': [contact_person_name], 'address': [address], 'city': [city], 'pan_no': [panno]})
66
  insert_data(conn, 'vendor_data', vendor_data)
67
  st.success("Vendor data added successfully")
68
 
69
+ with tabs[2]:
70
  st.header("Material Data")
71
  part_id = st.number_input("Part ID")
72
  part_no = st.number_input("Part Number")
 
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':