prakashkota commited on
Commit
0c01b91
·
1 Parent(s): 9ca345c

Added initial project files

Browse files
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Everything here goes into the app.py file
2
+ # Define Gradio inference function
3
+
4
+ # 15 March 2025
5
+ # Prakash Kota
6
+ # East Greenbush
7
+
8
+ import numpy as np
9
+ import tensorflow as tf
10
+ import os
11
+ import gradio as gr
12
+ import joblib
13
+
14
+ # Fixed reactor parameters
15
+ V = 100 # Reactor volume (L)
16
+ k = 0.1 # Reaction rate constant (1/min)
17
+ delta_H = -50000 # Heat of reaction (J/mol)
18
+ rho = 1 # Density in kg/L
19
+ Cp = 4184 # Heat capacity in J/kg·K
20
+
21
+ # Define Gradio inference function
22
+ def predict_cstr(CA_in, T_in, F):
23
+ # Load scalers and model
24
+ scaler_X = joblib.load(f"{model_dir}/scaler_X.pkl")
25
+ scaler_Y = joblib.load(f"{model_dir}/scaler_Y.pkl")
26
+ model = tf.keras.models.load_model(f"{model_dir}/cstr_model.keras")
27
+
28
+ # Scale input
29
+ input_scaled = scaler_X.transform([[CA_in, T_in, F]])
30
+
31
+ # Predict using the model
32
+ prediction_scaled = model.predict(input_scaled)
33
+ prediction_original = scaler_Y.inverse_transform(prediction_scaled)
34
+ CA_ss_pred, T_ss_pred = prediction_original[0]
35
+
36
+ # Compute analytical solution
37
+ CA_ss_analytical = (CA_in * (F / V)) / ((F / V) + k)
38
+ T_ss_analytical = T_in + ((-delta_H * k * CA_ss_analytical) / (rho * Cp)) * (V / F)
39
+
40
+ # Compute % Error and % Accuracy
41
+ percent_error = abs((CA_ss_pred - CA_ss_analytical) / CA_ss_analytical) * 100
42
+ percent_accuracy = (1 - abs(CA_ss_pred - CA_ss_analytical) / CA_ss_analytical) * 100
43
+
44
+ return (f"Predicted CA_ss: {CA_ss_pred:.4f} mol/L\n"
45
+ f"Predicted T_ss: {T_ss_pred:.2f} K\n"
46
+ f"Analytical CA_ss: {CA_ss_analytical:.4f} mol/L\n"
47
+ f"Analytical T_ss: {T_ss_analytical:.2f} K\n"
48
+ f"% Error: {percent_error:.2f}%\n"
49
+ f"% Accuracy: {percent_accuracy:.2f}%")
50
+
51
+ # Deploy using Gradio
52
+ iface = gr.Interface(
53
+ fn=predict_cstr,
54
+ inputs=[
55
+ gr.Number(label="Input Concentration CA_in - Range [0.5-2.0] mol/L"),
56
+ gr.Number(label="Input Temperature T_in - Range [300-350] K"),
57
+ gr.Number(label="CSTR Flow Rate F - Range [5-20] L/min")
58
+ ],
59
+ outputs="text",
60
+ title="CSTR Surrogate Model Inference",
61
+ description="Enter the input values to predict steady-state concentration and temperature."
model/cstr_model.keras ADDED
Binary file (53.7 kB). View file
 
model/scaler_X.pkl ADDED
Binary file (799 Bytes). View file
 
model/scaler_Y.pkl ADDED
Binary file (743 Bytes). View file
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ numpy
4
+ joblib
5
+ scikit-learn
6
+ scipy