notjulietxd's picture
version bump
762c215 verified
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()