File size: 1,731 Bytes
e0789da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from matgraph.sdk import MatGraphSDK
import pandas as pd

def predict_material(formula, api_key):
    if not api_key:
        return "Please enter your Materials Project API Key."
    
    try:
        sdk = MatGraphSDK(api_key=api_key)
        results = sdk.predict(formula=formula, model="m3gnet")
        
        if not results:
            return "No data found for this formula."
            
        # Format results into a dataframe
        df = pd.DataFrame([{
            "ID": r["material_id"],
            "Formula": r["formula"],
            "Crystal System": r["crystal_system"],
            "Predicted Energy (eV)": round(r["m3gnet_energy"], 3) if r.get("m3gnet_energy") else "N/A"
        } for r in results])
        
        return df
    except Exception as e:
        return f"Error: {str(e)}"

with gr.Blocks(title="MatGraph CLI: Deep Learning for Material Science", theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 🔬 MatGraph Explorer")
    gr.Markdown("Predict thermodynamic stability and properties of materials using M3GNet Universal Potentials.")
    
    with gr.Row():
        with gr.Column():
            formula_input = gr.Textbox(label="Chemical Formula (e.g., LiFePO4)", placeholder="LiFePO4")
            api_input = gr.Textbox(label="Materials Project API Key", type="password")
            btn = gr.Button("Predict Properties", variant="primary")
            
        with gr.Column():
            output_table = gr.Dataframe(label="Polymorph Predictions")
            
    btn.click(fn=predict_material, inputs=[formula_input, api_input], outputs=[output_table])
    
    gr.Markdown("Powered by [matgraph-cli](https://pypi.org/project/matgraph-cli/)")

demo.launch()