CoolFace
Apppublic

tbaig1605/Steel_Calculation

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py72 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3 4@st.cache_data5def load_aisc_data():6    df = pd.read_csv("AISC_Shape_Database.csv")7    df.columns = df.columns.str.strip()  # clean column headers8    # Normalize section names to uppercase and strip spaces9    df['AISC_Manual_Label'] = df['AISC_Manual_Label'].str.strip().str.upper()10    return df[['AISC_Manual_Label', 'W']]11 12def main():13    st.title("Steel Weight Estimator Using AISC Data")14 15    aisc_df = load_aisc_data()16    st.write("Sample AISC sections:", aisc_df['AISC_Manual_Label'].head(10).tolist())17 18    price_per_kg = st.number_input("Price per kg (e.g. 150)", min_value=0.0, format="%.2f")19 20    user_input = st.text_area(21        "Enter Section and Length separated by comma (one per line)\nExample:\nW44X408, 5.5\nHSS11.75X.250, 3"22    )23 24    if st.button("Calculate Weight and Price"):25        if not user_input.strip():26            st.error("Please enter section and length data.")27            return28        if price_per_kg <= 0:29            st.error("Please enter a valid price per kg.")30            return31 32        lines = user_input.strip().split('\n')33        results = []34 35        for line in lines:36            try:37                section, length_str = line.split(',')38                section = section.strip().upper()  # Normalize user input39                length_m = float(length_str.strip())40 41                st.write(f"Checking section: '{section}'")  # debug output42 43                row = aisc_df[aisc_df['AISC_Manual_Label'] == section]44 45                if row.empty:46                    results.append((section, length_m, None, None))47                    continue48 49                weight_lb_per_ft = float(row['W'].values[0])50                length_ft = length_m * 3.2808451                total_weight_lb = weight_lb_per_ft * length_ft52                total_weight_kg = total_weight_lb * 0.45359253                total_price = total_weight_kg * price_per_kg54 55                results.append((section, length_m, total_weight_kg, total_price))56 57            except Exception as e:58                results.append((line, None, None, None))59 60        st.write("### Results:")61        st.write("| Section | Length (m) | Weight (kg) | Price |")62        st.write("|---------|------------|-------------|-------|")63        for res in results:64            section, length_m, weight_kg, price = res65            if weight_kg is None:66                st.write(f"| {section} | {length_m if length_m else '-'} | Not found | - |")67            else:68                st.write(f"| {section} | {length_m:.2f} | {weight_kg:.2f} | {price:.2f} |")69 70if __name__ == "__main__":71    main()72