Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
@st.cache_data
|
| 5 |
+
def load_aisc_data():
|
| 6 |
+
df = pd.read_csv('AISC_Shape_Database.csv')
|
| 7 |
+
df.columns = df.columns.str.strip()
|
| 8 |
+
df['Designation'] = df['Designation'].str.upper().str.strip()
|
| 9 |
+
df.set_index('Designation', inplace=True)
|
| 10 |
+
return df
|
| 11 |
+
|
| 12 |
+
def lbft_to_kgm(lb_per_ft):
|
| 13 |
+
return lb_per_ft * 1.48816
|
| 14 |
+
|
| 15 |
+
def get_weight_for_section(section, aisc_df):
|
| 16 |
+
section = section.upper().strip()
|
| 17 |
+
if section in aisc_df.index:
|
| 18 |
+
return lbft_to_kgm(aisc_df.loc[section, 'W'])
|
| 19 |
+
else:
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
st.title("Steel Weight Estimator Using AISC Data")
|
| 23 |
+
|
| 24 |
+
price_per_kg = st.number_input("Price per kg (e.g. 150)", min_value=0.0, format="%.2f")
|
| 25 |
+
|
| 26 |
+
uploaded_file = st.file_uploader("Upload CSV with columns: Section, Length (meters)", type=["csv"])
|
| 27 |
+
|
| 28 |
+
if uploaded_file:
|
| 29 |
+
user_df = pd.read_csv(uploaded_file)
|
| 30 |
+
user_df.columns = user_df.columns.str.strip()
|
| 31 |
+
user_df['Section'] = user_df['Section'].str.upper().str.strip()
|
| 32 |
+
|
| 33 |
+
weights = []
|
| 34 |
+
aisc_data = load_aisc_data()
|
| 35 |
+
for sec in user_df['Section']:
|
| 36 |
+
w = get_weight_for_section(sec, aisc_data)
|
| 37 |
+
weights.append(w)
|
| 38 |
+
|
| 39 |
+
user_df['Weight (kg/m)'] = weights
|
| 40 |
+
missing = user_df[user_df['Weight (kg/m)'].isna()]
|
| 41 |
+
|
| 42 |
+
if not missing.empty:
|
| 43 |
+
st.error(f"Missing sections in database: {', '.join(missing['Section'].unique())}")
|
| 44 |
+
else:
|
| 45 |
+
user_df['Total Weight (kg)'] = user_df['Weight (kg/m)'] * user_df['Length']
|
| 46 |
+
total_weight = user_df['Total Weight (kg)'].sum()
|
| 47 |
+
total_price = total_weight * price_per_kg
|
| 48 |
+
|
| 49 |
+
st.write(user_df[['Section', 'Length', 'Weight (kg/m)', 'Total Weight (kg)']])
|
| 50 |
+
st.write(f"Total Weight: {total_weight:.2f} kg")
|
| 51 |
+
st.write(f"Total Price: {total_price:.2f}")
|