import matplotlib.pyplot as plt import os # Make sure the directory exists os.makedirs("/mnt/data", exist_ok=True) # Sample average values for properties (example data) material_types = ["Conductor", "Semiconductor", "Dielectric"] band_gap = [0.01, 1.1, 6.0] density = [8.9, 2.3, 3.0] reflectivity = [0.95, 0.6, 0.4] transmission = [0.05, 0.5, 0.9] stability = [0.7, 0.8, 0.95] # Utility function to plot and save def make_plot(values, title, filename, ylabel): plt.figure(figsize=(6, 4)) bars = plt.bar(material_types, values, color=["#F44336", "#2196F3", "#4CAF50"]) plt.title(title, fontsize=14) plt.ylabel(ylabel, fontsize=12) plt.ylim(0, max(values) * 1.2) for bar, val in zip(bars, values): plt.text(bar.get_x() + bar.get_width()/2, val + 0.05, f"{val}", ha='center', fontsize=10) plt.tight_layout() plt.savefig(f"/mnt/data/{filename}") plt.close() # Generate all 5 plots make_plot(band_gap, "Band Gap vs Material Type", "band_gap_plot.png", "Band Gap (eV)") make_plot(density, "Density vs Material Type", "density_plot.png", "Density (g/cm³)") make_plot(reflectivity, "Reflectivity vs Material Type", "reflectivity_plot.png", "Reflectivity") make_plot(transmission, "Transmission vs Material Type", "transmission_plot.png", "Transmission") make_plot(stability, "Stability vs Material Type", "stability_plot.png", "Stability") print("✅ All property graphs saved to /mnt/data/ successfully!") import gradio as gr from PIL import Image import py3Dmol # Load property graphs band_gap_img = Image.open("/mnt/data/band_gap_plot.png") density_img = Image.open("/mnt/data/density_plot.png") reflectivity_img = Image.open("/mnt/data/reflectivity_plot.png") transmission_img = Image.open("/mnt/data/transmission_plot.png") stability_img = Image.open("/mnt/data/stability_plot.png") # Dummy model prediction (for demonstration) def classify_material(band_gap, density, reflectivity, transmission, stability): if band_gap < 0.1: return "⚡ Conductor" elif band_gap < 2: return "💡 Semiconductor" else: return "🔒 Dielectric" # CSS for styling css = """ body { font-family: 'Arial'; background-color: #f9f9f9; } .gradio-container { max-width: 900px; margin: auto; } h1, h2, h3 { color: #2c3e50; } .big-result { font-size: 40px; font-weight: bold; color: white; background: #27ae60; padding: 20px; text-align: center; border-radius: 10px; margin-top: 20px; } """ # Interface with gr.Blocks(css=css) as demo: gr.Markdown("

🔬 Understanding Optical and Electronic Materials

") gr.Markdown("""

Modern technology is built upon a rich variety of materials, each tailored for specific roles in electronics, optics, and energy systems. Among the most fundamental types of these materials are:

These classifications are primarily determined by the electronic band structure of the material — specifically, the band gap — and are closely associated with how materials interact with light, electricity, and thermal energy.

""") gr.Image("https://www.matsusada.com/column/uploads/dielectrics_vs_insulators-02-1280w.png", label="Dielectrics vs Conductors") gr.Markdown("""

⚡ Conductors

Conductors are materials that facilitate the efficient flow of electric current due to the availability of free-moving charge carriers, primarily electrons. Metals such as copper, aluminum, silver, and gold are exemplary conductors owing to their low electrical resistivity and high thermal conductivity. These materials are widely utilized in various technological domains, including power transmission, electrical wiring, and electronic circuits. For instance, copper and aluminum are the materials of choice in overhead power lines and residential wiring systems due to their excellent balance of conductivity, ductility, and cost. In microelectronics, conductors are used in printed circuit boards (PCBs) to establish electrical pathways between components, while in electrochemical systems, such as batteries and capacitors, they serve as electrodes that facilitate charge storage and transfer. Additionally, conductors are integral to signal transmission systems, including coaxial and fiber-optic cables (via metallic shielding), and are critical in electromagnetic devices like transformers, inductors, and electric motors

On the molecular level, the superior conductivity of these materials is rooted in their distinctive bonding and crystalline structures. Metals exhibit metallic bonding, where atoms are arranged in a regular, tightly packed lattice and valence electrons are delocalized—forming what is often referred to as an "electron sea." These free electrons can move throughout the lattice with minimal resistance, enabling both electrical and thermal energy transfer. The most common and conductive metals often crystallize in face-centered cubic (FCC) structures—such as copper, silver, and gold—which maximize atomic packing and reduce electron scattering, further enhancing conductivity. Additionally, the electronic band structure of conductors lacks a band gap; the conduction and valence bands overlap or are partially filled, ensuring a continuous supply of charge carriers at room temperature. This intrinsic property, combined with high electron mobility and favorable density of states at the Fermi level, makes conductors indispensable in all modern electrical and electronic systems.

💡 Semiconductors

Semiconductors are materials whose electrical conductivity lies between that of conductors and insulators, and can be precisely controlled through doping, temperature, and external electric fields. Silicon and germanium are the most widely used elemental semiconductors, while compound semiconductors like gallium arsenide (GaAs), indium phosphide (InP), and silicon carbide (SiC) offer advantages in high-speed and high-power applications. Semiconductors form the backbone of modern electronics, enabling the fabrication of transistors, diodes, solar cells, integrated circuits (ICs), and optoelectronic devices such as LEDs and photodetectors. The ability to manipulate charge carrier concentration and mobility has led to their use in processors, memory devices, communication systems, power converters, and photovoltaic panels. Silicon, in particular, dominates the microelectronics industry due to its abundance, stable oxide layer (SiO₂), and mature fabrication technology. In emerging applications, wide-bandgap semiconductors like SiC and GaN are increasingly adopted in high-voltage, high-frequency, and high-temperature environments such as electric vehicles and power grids.

At the molecular level, semiconductors are typically crystalline solids with a covalent bonding structure, where atoms share electrons to form a periodic lattice. This structure results in a distinct electronic band structure featuring a band gap between the valence band (occupied by electrons) and the conduction band (where free electrons can move). At absolute zero, intrinsic semiconductors behave as insulators, but as temperature increases, thermal energy excites electrons across the band gap, enabling limited conduction. The conductivity can be significantly enhanced by introducing dopants—impurities that create excess electrons (n-type) or holes (p-type) within the crystal. For instance, doping silicon with phosphorus adds extra electrons, while boron doping introduces holes, allowing for the creation of p-n junctions, which are fundamental to diode and transistor operation. The precise control over the band gap and doping concentration allows semiconductors to exhibit tunable electronic, optical, and thermal properties, making them crucial for both classical and emerging quantum electronic technologies.

🔒 Dielectrics (Insulators)

Dielectrics are insulating materials that do not conduct electricity under normal conditions but can support electrostatic fields, making them essential in applications where electrical insulation and energy storage are required. Common dielectric materials include ceramics (such as barium titanate), polymers (like polyethylene and Teflon), glass, mica, and even dry air. These materials are widely used in capacitors, where they serve to separate conducting plates and store electric charge through polarization. High-permittivity dielectrics enable compact capacitors with increased energy density, crucial for electronic circuits, power electronics, and radio frequency systems. Dielectrics are also employed as insulating layers in cables, transformers, and high-voltage equipment, and serve as gate insulators in metal-oxide-semiconductor field-effect transistors (MOSFETs), playing a pivotal role in modern integrated circuits. In optical systems, dielectric coatings are used to enhance reflectivity or transparency in lenses and mirrors through interference effects.

At the molecular level, dielectrics are composed of atoms or molecules bound by ionic or covalent bonds that do not have free charge carriers under normal conditions. When subjected to an external electric field, these materials do not conduct but instead exhibit electrical polarization, where positive and negative charges slightly shift in opposite directions. This behavior can occur via several mechanisms—electronic polarization (displacement of electron clouds), ionic polarization (displacement of ions in a lattice), and dipolar orientation (alignment of permanent molecular dipoles). The extent of polarization is quantified by the material's dielectric constant (relative permittivity), a key parameter in determining its effectiveness in storing electric energy. On a microscopic scale, dielectrics typically exhibit a non-metallic, often amorphous or crystalline structure with a large band gap (usually >4 eV), which prevents the excitation of electrons to the conduction band under normal electric fields. The interplay between their insulating nature, polarizability, and structural stability makes dielectrics indispensable in both classical electronics and emerging applications such as flexible electronics, energy harvesting devices, and advanced photonic systems.

""") gr.Markdown("

📊 Property Comparison Charts

") with gr.Row(): gr.Image(band_gap_img, label="Band Gap vs Material") gr.Image(density_img, label="Density vs Material") with gr.Row(): gr.Image(reflectivity_img, label="Reflectivity vs Material") gr.Image(transmission_img, label="Transmission vs Material") gr.Image(stability_img, label="Stability vs Material") gr.Markdown("### 🔎 Classify a Material") with gr.Row(): band_gap = gr.Slider(0, 6, step=0.1, label="Band Gap (eV)") density = gr.Slider(0, 20, step=0.1, label="Density (g/cm³)") reflectivity = gr.Slider(0, 100, step=1, label="Reflectivity (%)") transmission = gr.Slider(0, 100, step=1, label="Transmission (%)") stability = gr.Slider(1, 10, step=1, label="Stability (1-10)") result_box = gr.HTML() def update_material_classification(bg, d, r, t, s): result = classify_material(bg, d, r, t, s) applications = { "⚡ Conductor": [ "Applications:", "Electrical wiring and circuits", "Printed circuit boards (PCBs)", "Electromagnetic shielding", "Heat sinks" ], "💡 Semiconductor": [ "Transistors and microchips", "Solar cells and photodetectors", "LEDs and laser diodes", "Power electronics" ], "🔒 Dielectric": [ "Capacitors and insulators", "Optical lenses and fibers", "Microwave and RF components", "Protective coatings and barriers" ] } app_list = "".join([f"
  • {item}
  • " for item in applications[result]]) return f"""
    Predicted Material Type: {result}
    🔧 Common Applications:
    """ gr.Button("🔍 Predict").click( update_material_classification, inputs=[band_gap, density, reflectivity, transmission, stability], outputs=result_box ) demo.launch(share=True)