Spaces:
Build error
Build error
| import streamlit as st | |
| # Set page config | |
| st.set_page_config(page_title="Slab Concrete Calculator", layout="centered") | |
| st.title("🧱 Slab Concrete Calculator") | |
| # Units selection | |
| unit = st.selectbox("Select unit for dimensions:", ["m", "cm", "mm"]) | |
| # Input fields | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| length = st.number_input("Length (L)", min_value=0.0, format="%.2f") | |
| with col2: | |
| width = st.number_input("Width (W)", min_value=0.0, format="%.2f") | |
| with col3: | |
| thickness = st.number_input("Thickness (T)", min_value=0.0, format="%.2f") | |
| # Convert all dimensions to meters | |
| conversion_factor = {"m": 1, "cm": 0.01, "mm": 0.001} | |
| factor = conversion_factor[unit] | |
| length_m = length * factor | |
| width_m = width * factor | |
| thickness_m = thickness * factor | |
| # Concrete Ratio Inputs | |
| st.markdown("### 🧮 Concrete Mix Ratio") | |
| col1, col2, col3 = st.columns(3) | |
| with col1: | |
| cement_ratio = st.number_input("Cement", min_value=0.0, value=1.0) | |
| with col2: | |
| sand_ratio = st.number_input("Sand", min_value=0.0, value=2.0) | |
| with col3: | |
| aggregate_ratio = st.number_input("Aggregate", min_value=0.0, value=4.0) | |
| total_ratio = cement_ratio + sand_ratio + aggregate_ratio | |
| # Additional inputs | |
| cement_bag_weight = st.number_input("Cement Bag Weight (kg)", value=50.0) | |
| cement_bag_price = st.number_input("Cement Bag Price ($)", value=0.0) | |
| water_cement_ratio = st.number_input("Water-Cement Ratio", value=0.5) | |
| concrete_price = st.number_input("Concrete Price per m³ ($)", value=0.0) | |
| # Calculate button | |
| if st.button("Calculate"): | |
| # Step 1: Concrete Volume | |
| concrete_volume = length_m * width_m * thickness_m | |
| # Step 2: Dry volume | |
| dry_volume = concrete_volume * 1.54 | |
| # Step 3: Material Volumes | |
| cement_volume = (cement_ratio / total_ratio) * dry_volume | |
| sand_volume = (sand_ratio / total_ratio) * dry_volume | |
| aggregate_volume = (aggregate_ratio / total_ratio) * dry_volume | |
| # Step 4: Cement weight & bags | |
| cement_density = 1440 # kg/m³ | |
| cement_weight = cement_volume * cement_density | |
| cement_bags = cement_weight / cement_bag_weight | |
| # Step 5: Water | |
| water_liters = cement_weight * water_cement_ratio | |
| # Step 6: Costs | |
| cement_cost = cement_bags * cement_bag_price | |
| total_concrete_cost = concrete_volume * concrete_price | |
| concrete_weight = cement_weight + (sand_volume + aggregate_volume) * 1600 # estimated total mass | |
| # Results | |
| st.markdown("### 📊 Results") | |
| st.write(f"**Concrete Volume:** {concrete_volume:.2f} m³") | |
| st.write(f"**Dry Concrete Volume:** {dry_volume:.2f} m³") | |
| st.write(f"**Cement Volume:** {cement_volume:.2f} m³") | |
| st.write(f"**Cement Weight:** {cement_weight:.2f} kg") | |
| st.write(f"**Cement Bags:** {cement_bags:.2f} bags") | |
| st.write(f"**Sand Volume:** {sand_volume:.2f} m³") | |
| st.write(f"**Aggregate Volume:** {aggregate_volume:.2f} m³") | |
| st.write(f"**Water Required:** {water_liters:.2f} liters") | |
| st.write(f"**Cement Cost:** ${cement_cost:.2f}") | |
| st.write(f"**Concrete Cost:** ${total_concrete_cost:.2f}") | |
| st.write(f"**Estimated Concrete Weight:** {concrete_weight:.2f} kg") | |