Annex e Gui
Annex e Gui
VISUZILATION
import tkinter as tk
import numpy as np
import joblib
import os
def load_keras_model(model_path):
return load_model(model_path)
def load_joblib_model(model_path):
return joblib.load(model_path)
keras_models = {}
rf_models = {}
svr_models = {}
scalers = {}
'''
keras_model_files = {
keras_models[key] = load_keras_model(model_path)
scalers[key] = load_joblib_model(scaler_path)'''
keras_model_files = {
keras_models[key] = load_keras_model(model_path)
scalers[key] = load_joblib_model(scaler_path)
rf_model_files = {
rf_models[key] = load_joblib_model(model_path)
svr_model_files = {
svr_models[key] = load_joblib_model(model_path)
# GUI creation
root = tk.Tk()
feature_names = [
"Percentage Passing through 26mm Sieve", "Percentage Passing through 19mm Sieve",
"Percentage Passing through 13.2mm Sieve", "Percentage Passing through 9.5mm Sieve",
"Percentage Passing through 1.18mm Sieve", "Percentage Passing through 0.6mm Sieve",
"Percentage Passing through 0.3mm Sieve", "Percentage Passing through 0.15mm Sieve",
entries = []
entry = tk.Entry(root)
entry.grid(row=i, column=1)
entries.append(entry)
def predict():
try:
numeric_features = []
non_numeric_indices = []
numeric_value = float(value)
numeric_features.append(numeric_value)
except ValueError:
non_numeric_indices.append(i)
entries[index].config(bg="red")
if non_numeric_indices:
return
predictions = {
'Keras': [],
'RF': [],
'SVR': []
if model:
scaler = scalers[key]
scaled_features = scaler.transform(features_array)
keras_prediction = model.predict(scaled_features)
predictions['Keras'].append(f"{key}: {keras_prediction[0][0]:.2f}")
if model:
rf_prediction = model.predict(features_array)
predictions['RF'].append(f"{key}: {rf_prediction[0]:.2f}")
if model:
svr_prediction = model.predict(features_array)
predictions['SVR'].append(f"{key}: {svr_prediction[0]:.2f}")
# Display predictions
keras_output.delete(1.0, tk.END)
keras_output.insert(tk.END, "\n".join(predictions['Keras']))
rf_output.delete(1.0, tk.END)
rf_output.insert(tk.END, "\n".join(predictions['RF']))
svr_output.delete(1.0, tk.END)
svr_output.insert(tk.END, "\n".join(predictions['SVR']))
except Exception as e:
root.mainloop()
GUI Interface for prediction of OBC