CoolFace
Apppublic

a4ad/Smart-material-selection-tool

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py58 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3 4# Material data embedded directly into the script5MATERIAL_DATA = [6    {"Material": "Steel", "Strength (MPa)": 250, "Density (g/cm³)": 7.8, "Cost ($/kg)": 1.5, "Corrosion Resistance": "Moderate"},7    {"Material": "Aluminum", "Strength (MPa)": 150, "Density (g/cm³)": 2.7, "Cost ($/kg)": 3.0, "Corrosion Resistance": "High"},8    {"Material": "Titanium", "Strength (MPa)": 300, "Density (g/cm³)": 4.5, "Cost ($/kg)": 10.0, "Corrosion Resistance": "Excellent"},9    {"Material": "Copper", "Strength (MPa)": 210, "Density (g/cm³)": 8.9, "Cost ($/kg)": 8.0, "Corrosion Resistance": "Moderate"},10    {"Material": "Plastic", "Strength (MPa)": 50, "Density (g/cm³)": 1.2, "Cost ($/kg)": 0.8, "Corrosion Resistance": "High"},11]12 13# Load material dataset14def load_data():15    return pd.DataFrame(MATERIAL_DATA)16 17# Filter materials based on user input18def filter_materials(data, load, weight_limit, budget, corrosion_resistance):19    filtered_data = data[20        (data["Strength (MPa)"] >= load) &21        (data["Density (g/cm³)"] <= weight_limit) &22        (data["Cost ($/kg)"] <= budget) &23        (data["Corrosion Resistance"] == corrosion_resistance)24    ]25    return filtered_data26 27# Streamlit App28st.title("🔧 Smart Material Selection Tool 🌟")29st.write("AI-powered tool to help you choose the best material for your mechanical application.")30 31# Sidebar for user inputs32st.sidebar.header("Enter Application Requirements:")33load = st.sidebar.number_input("Minimum Strength (MPa):", min_value=0, value=150)34weight_limit = st.sidebar.number_input("Maximum Density (g/cm³):", min_value=0.0, value=5.0, step=0.1)35budget = st.sidebar.number_input("Maximum Cost ($/kg):", min_value=0.0, value=5.0, step=0.1)36corrosion_resistance = st.sidebar.selectbox(37    "Corrosion Resistance:",38    ["High", "Moderate", "Excellent"]39)40 41# Load dataset42data = load_data()43 44# Show filtered results45if st.sidebar.button("Find Materials"):46    results = filter_materials(data, load, weight_limit, budget, corrosion_resistance)47    if not results.empty:48        st.success(f"Found {len(results)} matching materials:")49        st.dataframe(results)50    else:51        st.warning("No materials match your criteria. Try adjusting your inputs.")52else:53    st.info("Enter the application requirements and click 'Find Materials' to see results.")54 55# Footer56st.markdown("---")57st.markdown("Built with ❤️ by Abdul Ahad. Powered by Streamlit.")58