| import gradio as gr |
| import numpy as np |
| from tensorflow.keras.models import load_model |
| from sklearn.preprocessing import PolynomialFeatures, StandardScaler |
| import joblib |
| import pickle |
| |
| model = load_model('crack-v3.2.h5') |
| with open('poly_features.pkl', 'rb') as f: |
| poly_loaded = pickle.load(f) |
|
|
| |
| with open('standard_scaler.pkl', 'rb') as f: |
| scaler_loaded = pickle.load(f) |
|
|
| |
| |
| 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. |
| """ |
| |
| |
| |
| X_test_poly = poly_loaded.transform([[geometric_factor, flange_width, beam_width, beamh, columntw]]) |
|
|
| |
| 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. |
| """ |
| |
| preprocessed_input = preprocess_input(geometric_factor, flange_width, beam_width, beamh, columntw) |
| |
| |
| prediction = model.predict(preprocessed_input) |
| |
| |
| return f"Predicted Fatigue Crack Growth Rate: {prediction[0][0]}" |
|
|
| |
| 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() |
|
|