File size: 982 Bytes
2d972c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()