Importing Required Libraries

import tensorflow as tf
from tensorflow.keras.utils import image_dataset_from_directory
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPool2D, Flatten, Dense, GlobalAveragePooling2D, Dropout, MaxPooling2D
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint
from sklearn.metrics import classification_report,confusion_matrix
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="0"# Train and Test File Directory
train_dir=r"C:\Users\Metalab\OneDrive - 4i Apps Solutions Pvt Ltd\nj\pcb\data"
test_dir=r"C:\Users\Metalab\OneDrive - 4i Apps Solutions Pvt Ltd\nj\pcb\data" os.listdir()['.ipynb_checkpoints', '.venv', 'app.py', 'data', 'Untitled.ipynb']

import tensorflow as tf

train_ds = tf.keras.utils.image_dataset_from_directory(
train_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(128, 128),
batch_size=32
)

valid_ds = tf.keras.utils.image_dataset_from_directory(
train_dir,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(128, 128),
batch_size=32
)# Different Classes of Dependent Variable
class_name=sorted(os.listdir(train_dir))
class_name['false call', 'ng']

Defining the Graph Function

def show_image(image, title=None):
plt.imshow(image)
plt.title(title)
plt.axis('off')# Building the Model
model = Sequential()
model.add(Conv2D(8,kernel_size=(9,9),padding = 'same',activation ='relu', input_shape = (128,128,3)))
model.add(MaxPooling2D(pool_size=(7,7)))
model.add(Flatten())
model.add(Dense(70,activation='relu'))
model.add(Dense(20,activation='relu'))
model.add(Dense(1, activation='sigmoid'))early_stopping = EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])# Fit the model with EarlyStopping callback
history = model.fit(
train_ds,
validation_data=valid_ds,
epochs=100,  # Set the maximum number of epochs
#steps_per_epoch=len(train_ds),
#validation_steps=len(valid_ds),
callbacks=[early_stopping]  # Include EarlyStopping callback
)model.summary()#import matplotlib.pyplot as plt
plt.plot(history.history["loss"])
plt.plot(history.history['accuracy'])
plt.plot(history.history['val_loss'])
plt.plot(history.history['val_accuracy'])
plt.title("Model accuracy")
plt.ylabel("Accuracy")
plt.xlabel("Epoch")
plt.legend(["Loss","Accuracy","Validation Loss","Validation Accuracy"])
plt.show()# Validation Labels
val_label = valid_ds.classes
val_labelimport tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
import matplotlib.pyplot as pltimg_path = r"C:\Users\Metalab\OneDrive - 4i Apps Solutions Pvt Ltd\nj\pcb\data\ng\DAMAGE Q4.JPG"  # Replace with your image path

Load image with target size

img = image.load_img(img_path, target_size=(128, 128))

Convert to array

img_array = image.img_to_array(img)

Scale pixel values (if you used rescaling during training)

img_array = img_array / 255.0

Add batch dimension: model expects shape (batch_size, height, width, channels)

img_array = np.expand_dims(img_array, axis=0)  # Shape: (1, 128, 128, 3)
pred = model.predict(img_array)
print("Raw model output:", pred)
threshold = 0.5  # You can adjust this threshold if needed
if pred[0][0] > threshold:
print("Predicted class: ng")
else:
print("Predicted class: false call")
img_path = r"C:\Users\Metalab\OneDrive - 4i Apps Solutions Pvt Ltd\nj\pcb\data\false call\2.JPG"  # Replace with your image path

Load image with target size

img = image.load_img(img_path, target_size=(128, 128))

Convert to array

img_array = image.img_to_array(img)

Scale pixel values (if you used rescaling during training)

img_array = img_array / 255.0

Add batch dimension: model expects shape (batch_size, height, width, channels)

img_array = np.expand_dims(img_array, axis=0)  # Shape: (1, 128, 128, 3)
pred = model.predict(img_array)
print("Raw model output:", pred)threshold = 0.5  # You can adjust this threshold if needed
if pred[0][0] > threshold:
print("Predicted class: ng")
else:
print("Predicted class: false call")
for this we are looking for frontend modern macbook style in flask app.py how cn we do . currently code is in ipynb file and need to implement frontend for it.