import streamlit as st import pandas as pd # Dictionary containing materials, classes, and their properties materials_data = { "Metals": { "Iron": {"Density (g/cm³)": 7.87, "Melting Point (°C)": 1538, "Conductivity (S/m)": 1.0e7}, "Aluminum": {"Density (g/cm³)": 2.7, "Melting Point (°C)": 660.3, "Conductivity (S/m)": 3.77e7}, "Copper": {"Density (g/cm³)": 8.96, "Melting Point (°C)": 1085, "Conductivity (S/m)": 5.96e7}, }, "Non-metals": { "Carbon": {"Density (g/cm³)": 2.26, "Melting Point (°C)": 3550, "Conductivity (S/m)": 0.0}, "Sulfur": {"Density (g/cm³)": 2.07, "Melting Point (°C)": 115.2, "Conductivity (S/m)": 0.0}, }, "Metalloids": { "Silicon": {"Density (g/cm³)": 2.33, "Melting Point (°C)": 1414, "Conductivity (S/m)": 1.56e-3}, "Boron": {"Density (g/cm³)": 2.34, "Melting Point (°C)": 2076, "Conductivity (S/m)": 0.0}, }, "Ceramics": { "Porcelain": {"Density (g/cm³)": 2.4, "Melting Point (°C)": 1200, "Conductivity (S/m)": 0.0}, "Zirconia": {"Density (g/cm³)": 5.68, "Melting Point (°C)": 2715, "Conductivity (S/m)": 0.0}, }, "Polymers": { "Polyethylene": {"Density (g/cm³)": 0.94, "Melting Point (°C)": 115, "Conductivity (S/m)": 0.0}, "PVC": {"Density (g/cm³)": 1.38, "Melting Point (°C)": 212, "Conductivity (S/m)": 0.0}, }, "Alloys": { "Brass": {"Density (g/cm³)": 8.6, "Melting Point (°C)": 930, "Conductivity (S/m)": 1.5e7}, "Steel": {"Density (g/cm³)": 7.85, "Melting Point (°C)": 1370, "Conductivity (S/m)": 6.1e6}, }, } # Streamlit app UI st.title("Material Selection Tool") st.sidebar.header("Select Material Class and Properties") # User input for selecting material class material_class = st.sidebar.selectbox("Select Material Class", options=materials_data.keys()) if material_class: # User input for selecting specific material material = st.sidebar.selectbox("Select Material", options=materials_data[material_class].keys()) # Display properties of the selected material if material: st.subheader(f"Properties of {material}") properties = materials_data[material_class][material] df = pd.DataFrame.from_dict(properties, orient="index", columns=["Value"]) df["Units"] = ["g/cm³", "°C", "S/m"] # Example units st.table(df) # Allow users to download data as CSV csv = df.to_csv().encode("utf-8") st.download_button( label="Download Properties as CSV", data=csv, file_name=f"{material}_properties.csv", mime="text/csv", )