Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| def load_aisc_data(): | |
| df = pd.read_csv("AISC_Shape_Database.csv") | |
| df.columns = df.columns.str.strip() # clean column headers | |
| # Normalize section names to uppercase and strip spaces | |
| df['AISC_Manual_Label'] = df['AISC_Manual_Label'].str.strip().str.upper() | |
| return df[['AISC_Manual_Label', 'W']] | |
| def main(): | |
| st.title("Steel Weight Estimator Using AISC Data") | |
| aisc_df = load_aisc_data() | |
| st.write("Sample AISC sections:", aisc_df['AISC_Manual_Label'].head(10).tolist()) | |
| price_per_kg = st.number_input("Price per kg (e.g. 150)", min_value=0.0, format="%.2f") | |
| user_input = st.text_area( | |
| "Enter Section and Length separated by comma (one per line)\nExample:\nW44X408, 5.5\nHSS11.75X.250, 3" | |
| ) | |
| if st.button("Calculate Weight and Price"): | |
| if not user_input.strip(): | |
| st.error("Please enter section and length data.") | |
| return | |
| if price_per_kg <= 0: | |
| st.error("Please enter a valid price per kg.") | |
| return | |
| lines = user_input.strip().split('\n') | |
| results = [] | |
| for line in lines: | |
| try: | |
| section, length_str = line.split(',') | |
| section = section.strip().upper() # Normalize user input | |
| length_m = float(length_str.strip()) | |
| st.write(f"Checking section: '{section}'") # debug output | |
| row = aisc_df[aisc_df['AISC_Manual_Label'] == section] | |
| if row.empty: | |
| results.append((section, length_m, None, None)) | |
| continue | |
| weight_lb_per_ft = float(row['W'].values[0]) | |
| length_ft = length_m * 3.28084 | |
| total_weight_lb = weight_lb_per_ft * length_ft | |
| total_weight_kg = total_weight_lb * 0.453592 | |
| total_price = total_weight_kg * price_per_kg | |
| results.append((section, length_m, total_weight_kg, total_price)) | |
| except Exception as e: | |
| results.append((line, None, None, None)) | |
| st.write("### Results:") | |
| st.write("| Section | Length (m) | Weight (kg) | Price |") | |
| st.write("|---------|------------|-------------|-------|") | |
| for res in results: | |
| section, length_m, weight_kg, price = res | |
| if weight_kg is None: | |
| st.write(f"| {section} | {length_m if length_m else '-'} | Not found | - |") | |
| else: | |
| st.write(f"| {section} | {length_m:.2f} | {weight_kg:.2f} | {price:.2f} |") | |
| if __name__ == "__main__": | |
| main() | |