File size: 2,075 Bytes
3ef9b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bba8866
 
3ef9b01
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import numpy as np
import tensorflow as tf
import joblib

# 1. Load the model
model = tf.keras.models.load_model('consolidated_fault_model.keras')

# Load the scaler and label encoder
scaler = joblib.load('scaler.joblib')
label_encoder = joblib.load('label_encoder.joblib')

def predict_smart_grid(Ia, Ib, Ic, Va, Vb, Vc):
    # Prepare the input features
    features = np.array([[Ia, Ib, Ic, Va, Vb, Vc]])

    # Scale the input using the loaded scaler
    features_scaled = scaler.transform(features)

    # Make prediction
    det_pred, cl_pred = model.predict(features_scaled, verbose=0)

    # Process Detection Output
    fault_prob = float(det_pred[0][0])
    det_status = "FAULT DETECTED" if fault_prob > 0.5 else "NO FAULT"
    det_conf = fault_prob if fault_prob > 0.5 else 1 - fault_prob
    detection_str = f"{det_status} ({det_conf:.2%})"

    # Process Classification Output
    class_idx = np.argmax(cl_pred[0])
    class_label = label_encoder.classes_[class_idx] # Use the loaded label_encoder
    class_conf = float(cl_pred[0][class_idx])
    classification_str = f"{class_label} ({class_conf:.2%})"

    return detection_str, classification_str

iface = gr.Interface(
    fn=predict_smart_grid,
    inputs=[
        gr.Number(label="Ia (Line current of phase A)"),
        gr.Number(label="Ib (Line current of phase B)"),
        gr.Number(label="Ic (Line current of phase C)"),
        gr.Number(label="Va (Line voltage of phase A)"),
        gr.Number(label="Vb (Line voltage of phase B)"),
        gr.Number(label="Vc (Line voltage of phase C)")
    ],
    outputs=[
        gr.Textbox(label="Fault Detection Analysis"),
        gr.Textbox(label="Fault Type Classification")
    ],
    title="AI-Driven Smart Grid Transmission Line Fault Detection and Classification System",
    description="Input the three-phase current and voltage parameters (Ia, Ib, Ic, Va, Vb, and Vc) to intelligently analyze transmission line conditions and accurately detect and classify smart grid faults in real time.",
    theme="soft"
)

iface.launch()