import gradio as gr import tensorflow as tf import numpy as np import pickle # Load necessary objects from the pickle file with open("C:\Users\Administrator\Downloads\model_data_2.pkl" 'rb') as file: pickle_data = pickle.load(file) # Load the model model = pickle_data['model'] class_names = ["CLL case lymphocytes", "Normal lymphocytes"] # Define function to preprocess and predict image def predict(image): img_array = tf.keras.preprocessing.image.img_to_array(image) img_array = tf.expand_dims(img_array, 0) # Create a batch of images predictions = model.predict(img_array) predicted_class = class_names[np.argmax(predictions[0])] confidence = round(100 * np.max(predictions[0]), 2) return predicted_class + f" ({confidence}%)" # Define Gradio Interface image = gr.Image(type='pil', label="Upload Image") label = gr.Label(label="Predicted Class") gr.Interface(predict, inputs=image, outputs=label, title="Cancer Classification App").launch()