File size: 2,427 Bytes
3276d62
 
 
 
 
73b9b22
3276d62
762c215
13f404f
 
3276d62
13f404f
 
 
 
 
3276d62
 
 
 
ccb7fd1
9d4d70b
3276d62
 
 
 
1a24049
e5e5e62
9d4d70b
ccb7fd1
 
2322a94
3276d62
 
 
e5e5e62
3276d62
 
 
 
9d4d70b
3276d62
 
 
 
 
 
 
 
 
40adc2f
e5e5e62
3276d62
e5e5e62
40adc2f
3276d62
 
e5e5e62
3276d62
 
 
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
58
59
60
61
62
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from sklearn.preprocessing import PolynomialFeatures, StandardScaler
import joblib  # For loading the saved preprocessing objects
import pickle
# Load your pre-trained model
model = load_model('crack-v3.2.h5')
with open('poly_features.pkl', 'rb') as f:
    poly_loaded = pickle.load(f)

# Load the StandardScaler object
with open('standard_scaler.pkl', 'rb') as f:
    scaler_loaded = pickle.load(f)

    
# Load the preprocessing objects
poly = PolynomialFeatures(degree=5, include_bias=False)
scaler = StandardScaler()

# 
def preprocess_input(geometric_factor, flange_width, beam_width, beamh, columntw):
    """
    Preprocess the input data: apply polynomial features and then scale.
    """
    
    # # Apply Polynomial Features
    # ['GEOMETRIC_FACTOR',	'COLUMN_WIDTH',	'BEAM_WIDTH','BEAM - h', 'COLUMN - tw']
    X_test_poly = poly_loaded.transform([[geometric_factor, flange_width, beam_width, beamh, columntw]])

    # Standardize the polynomial features
    scaled_features = scaler_loaded.transform(X_test_poly)
    
    return scaled_features

def predict_fatigue_crack_growth_rate(geometric_factor, flange_width, beam_width, beamh, columntw):
    """
    Function to predict the fatigue crack growth rate based on the preprocessed input features.
    """
    # Preprocess the input data
    preprocessed_input = preprocess_input(geometric_factor, flange_width, beam_width, beamh, columntw)
    
    # Predict using the loaded model
    prediction = model.predict(preprocessed_input)
    
    # Return the prediction
    return f"Predicted Fatigue Crack Growth Rate: {prediction[0][0]}"

# Create a Gradio interface
iface = gr.Interface(fn=predict_fatigue_crack_growth_rate,
                     inputs=[gr.Number(label="Geometric Factor"),
                             gr.Number(label="Column Width"),
                             gr.Number(label="Beam Width"),
                             gr.Number(label="Beam - h"),
                             gr.Number(label="Column - tw")],
                     outputs=gr.Textbox(label="Prediction"),
                     title="Fatigue Crack Growth Rate Predictor",
                     description="Enter the values for Geometric Factor, Column Width, Beam Width, Beam - h, and COLUMN - tw to predict the Fatigue Crack Growth Rate.")

if __name__ == "__main__":
    iface.launch()