MuhammadHananKhan123's picture
Update app.py
867fdcf verified
import streamlit as st
def main():
# Set up the app title and description
st.title("Material Selector for Industries and Equipment")
st.write("""
This tool helps you identify the right material for designing equipment based on industry type and equipment requirements.
Select from metals, polymers, ceramics, alloys, and more by specifying the industry and equipment name.
""")
# User inputs
industry = st.text_input("Enter the industry (e.g., Automotive, Aerospace, Medical):")
equipment = st.text_input("Enter the equipment name (e.g., Pipes, Bearings, Surgical Tools):")
# Selection categories
material_type = st.selectbox(
"Select a material category:",
["Metals", "Polymers", "Ceramics", "Alloys"]
)
# Output recommendations
if st.button("Get Material Recommendation"):
if not industry or not equipment:
st.warning("Please provide both the industry and equipment name.")
else:
recommendation = get_material_recommendation(industry, equipment, material_type)
st.success("Recommendation:")
st.write(recommendation)
def get_material_recommendation(industry, equipment, material_type):
"""Returns a material recommendation based on the inputs."""
if material_type == "Metals":
return "Metals like stainless steel, aluminum alloys, and titanium are often suitable for industries like {} with equipment such as {}. These materials offer high strength, durability, and corrosion resistance.".format(industry, equipment)
elif material_type == "Polymers":
return "Polymers such as PVC, polyethylene, and nylon are ideal for lightweight and flexible equipment in the {} industry, especially for {}.".format(industry, equipment)
elif material_type == "Ceramics":
return "Ceramics, including alumina and silicon carbide, are excellent choices for {} industry applications requiring high heat resistance and insulation, such as {}.".format(industry, equipment)
elif material_type == "Alloys":
return "Alloys like brass, bronze, and nickel-based superalloys are widely used in the {} industry for {} due to their strength, wear resistance, and tailored properties.".format(industry, equipment)
else:
return "Invalid material type selected. Please choose a valid category."
if __name__ == "__main__":
main()
# Dictionary containing material data
MATERIALS = {
"Metals": {
"Alkali Metals": [
"Highly reactive metals",
"Soft, silvery-white in appearance",
"Low density and melting points",
"React vigorously with water to produce hydrogen gas and metal hydroxides",
"Examples: Lithium, Sodium, Potassium, etc."
],
"Transition Metals": [
"High melting and boiling points",
"Good conductors of heat and electricity",
"Form colored compounds",
"Examples: Iron, Copper, Gold, etc."
],
# Add more metal categories here
},
"Non-metals": {
"Oxygen": [
"Essential for respiration and combustion",
"Reacts with most elements to form oxides",
"Supports life and used in industrial processes",
],
"Carbon": [
"Exists in various forms (diamond, graphite)",
"Backbone of organic compounds",
"Used in fuels, materials, and electronics",
],
# Add more non-metals here
},
"Metalloids": {
"Silicon": [
"Essential for electronics as a semiconductor",
"Used in glass, ceramics, and solar cells",
"Second most abundant element in Earth’s crust",
],
"Boron": [
"Used in semiconductors and ceramics",
"Essential micronutrient for plants",
"High melting and boiling points",
],
# Add more metalloids here
},
"Polymers": {
"Thermoplastics": [
"Can be softened and reshaped multiple times",
"Examples: Polyethylene, Polypropylene",
"Good electrical insulators and chemical resistance",
],
"Thermosetting Polymers": [
"Rigid, strong, and heat-resistant",
"Examples: Epoxy resins, Polyurethane",
"Good electrical insulators",
],
# Add more polymer types here
},
"Ceramics": {
"Oxide Ceramics": [
"High melting points and hardness",
"Examples: Alumina, Zirconia",
"Used in high-temperature applications",
],
"Carbide Ceramics": [
"Extremely hard and wear-resistant",
"Examples: Tungsten carbide, Silicon carbide",
"Used in cutting tools and engine components",
],
# Add more ceramics here
},
"Alloys": {
"Steel": [
"High strength and durability",
"Used in construction and manufacturing",
"Resistant to corrosion when alloyed with chromium",
],
"Bronze": [
"Hard and durable",
"Used in sculptures, bells, and bearings",
"Resistant to corrosion",
],
# Add more alloys here
}
}
def main():
st.title("Material Selector")
st.write("Use this app to identify the correct material for designing equipment and industries.")
# Input fields for industry and equipment type
industry = st.text_input("Enter the Industry (e.g., Aerospace, Automotive, etc.):")
equipment = st.text_input("Enter the Equipment Name (e.g., Engine, Pipes, etc.):")
st.write("### Material Categories")
# Dropdown menu to select material category
category = st.selectbox("Select a Material Category:", list(MATERIALS.keys()))
# Display materials and their properties
if category:
st.subheader(f"{category} Properties")
for subcategory, properties in MATERIALS[category].items():
with st.expander(subcategory):
for property in properties:
st.write(f"- {property}")
# Display recommendations based on user inputs (example logic)
if industry and equipment:
st.write("### Recommended Materials")
st.write(f"For **{equipment}** in the **{industry}** industry, consider the following materials:")
if "steel" in equipment.lower() or "construction" in industry.lower():
st.write("- **Steel**: High strength and durability, widely used in construction.")
if "electronics" in industry.lower():
st.write("- **Silicon**: Essential for semiconductors and electronics.")
if "high temperature" in equipment.lower() or "aerospace" in industry.lower():
st.write("- **Titanium Alloys**: High strength-to-weight ratio and excellent corrosion resistance.")
# Create a function for material selection
def material_selector(industry, equipment_material):
# Material database
materials_data = {
"Metals": [
{"Type": "Alkali Metals", "Properties": "Highly reactive, low density, low melting points, reacts with water", "Examples": "Lithium, Sodium, Potassium"},
{"Type": "Alkaline Earth Metals", "Properties": "Reactive, higher density than alkali, moderate melting points", "Examples": "Magnesium, Calcium"},
{"Type": "Transition Metals", "Properties": "High density, high melting points, excellent conductors", "Examples": "Iron, Copper, Gold"},
{"Type": "Post-Transition Metals", "Properties": "Soft, malleable, moderate conductivity", "Examples": "Aluminum, Lead, Tin"},
],
"Non-Metals": [
{"Type": "Hydrogen", "Properties": "Highly flammable, colorless, combines with oxygen to form water", "Examples": "H2"},
{"Type": "Carbon", "Properties": "Versatile, forms organic compounds", "Examples": "Graphite, Diamond"},
{"Type": "Nitrogen", "Properties": "Essential for life, inert in its gaseous state", "Examples": "N2"},
],
"Polymers": [
{"Type": "Thermoplastics", "Properties": "Softened and reshaped by heat, lightweight, flexible", "Examples": "Polyethylene, Polypropylene"},
{"Type": "Thermosetting", "Properties": "Strong, rigid, cannot be reshaped after curing", "Examples": "Epoxy Resin, Polyurethane"},
{"Type": "Elastomers", "Properties": "Elastic, returns to original shape", "Examples": "Rubber, Silicone"},
],
"Ceramics": [
{"Type": "Oxide Ceramics", "Properties": "High hardness, heat resistance", "Examples": "Alumina, Silica"},
{"Type": "Carbide Ceramics", "Properties": "Extremely hard, wear-resistant", "Examples": "Tungsten Carbide"},
{"Type": "Silicate Ceramics", "Properties": "High strength, chemically resistant", "Examples": "Glass, Porcelain"},
],
"Alloys": [
{"Type": "Steel", "Properties": "Strong, durable, malleable", "Examples": "Carbon Steel, Stainless Steel"},
{"Type": "Bronze", "Properties": "Corrosion-resistant, durable", "Examples": "Copper-Tin Alloy"},
{"Type": "Titanium Alloys", "Properties": "High strength-to-weight ratio, corrosion resistant", "Examples": "Ti-6Al-4V"},
],
}
# Filter materials based on input
matching_materials = []
for category, materials in materials_data.items():
for material in materials:
if industry.lower() in material["Properties"].lower() or equipment_material.lower() in material["Examples"].lower():
matching_materials.append({"Category": category, **material})
return matching_materials
# Streamlit App Layout
st.title("Material Selector for Industries and Equipment")
st.subheader("Select the best material for your industrial application")
# User Inputs
industry = st.text_input("Enter Industry Type (e.g., Aerospace, Automotive, Construction):")
equipment_material = st.text_input("Enter Equipment Material Requirement (e.g., Lightweight, Corrosion Resistant):")
if st.button("Find Materials"):
if industry and equipment_material:
# Get matching materials
results = material_selector(industry, equipment_material)
if results:
st.success(f"Found {len(results)} matching materials:")
for result in results:
st.write(f"**Category:** {result['Category']}")
st.write(f"**Type:** {result['Type']}")
st.write(f"**Properties:** {result['Properties']}")
st.write(f"**Examples:** {result['Examples']}")
st.write("---")
else:
st.warning("No matching materials found. Please refine your search.")
else:
st.error("Please provide both inputs to search for materials.")
if __name__ == "__main__":
main()
# Load data for materials
@st.cache_data
def load_data():
# Material properties data
materials_data = {
"Metals": {
"Alkali Metals": ["Lithium", "Sodium", "Potassium"],
"Alkaline Earth Metals": ["Magnesium", "Calcium"],
"Transition Metals": ["Iron", "Copper", "Gold"],
},
"Polymers": {
"Thermoplastics": ["Polyethylene", "Polypropylene"],
"Thermosetting": ["Epoxy", "Phenolic"],
"Elastomers": ["Rubber", "Neoprene"],
},
"Ceramics": {
"Oxide Ceramics": ["Alumina", "Zirconia"],
"Carbide Ceramics": ["Silicon Carbide", "Tungsten Carbide"],
},
"Alloys": {
"Steel": ["High Carbon Steel", "Stainless Steel"],
"Titanium Alloys": ["Ti-6Al-4V", "CP-Titanium"],
}
}
return materials_data
materials_data = load_data()
# App Header
st.title("Material Selector App")
st.write("Identify the best material for making new objects based on your requirements.")
# Input from the user
industry = st.text_input("Enter the name of the industry (e.g., Aerospace, Construction, Medical, etc.):")
equipment_type = st.selectbox(
"Select the type of material group:",
options=["Metals", "Polymers", "Ceramics", "Alloys"]
)
# Display options based on material type
if equipment_type:
st.write(f"### Material Options for {equipment_type}:")
material_options = materials_data.get(equipment_type, {})
for category, items in material_options.items():
st.write(f"#### {category}:")
st.write(", ".join(items))
# Material property viewer (for further details)
st.write("\n")
st.write("---")
st.write("### View Material Properties")
selected_material = st.text_input("Enter the name of a material to view its properties:")
if selected_material:
# Mock property data for simplicity; you can expand this further
properties_data = {
"Lithium": {"Density (g/cm³)": 0.534, "Melting Point (°C)": 180.5, "Boiling Point (°C)": 1342},
"Iron": {"Density (g/cm³)": 7.874, "Melting Point (°C)": 1538, "Boiling Point (°C)": 2862},
"Polyethylene": {"Density (g/cm³)": 0.94, "Melting Point (°C)": 115, "Tensile Strength (MPa)": 37},
"Alumina": {"Density (g/cm³)": 3.95, "Melting Point (°C)": 2072, "Hardness (Mohs)": 9},
"Stainless Steel": {"Density (g/cm³)": 8.0, "Melting Point (°C)": 1510, "Tensile Strength (MPa)": 505}
}
material_properties = properties_data.get(selected_material)
if material_properties:
st.write(f"#### Properties of {selected_material}:")
st.json(material_properties)
else:
st.write(f"Properties for {selected_material} are not available. Please try another material.")
# Footer
st.write("---")
st.write("Developed by [Your Name]. Powered by Streamlit and Deployable on Hugging Face Spaces.")