|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
import pickle |
|
|
|
|
|
|
|
|
with open("C:\Users\Administrator\Downloads\model_data_2.pkl" 'rb') as file: |
|
|
pickle_data = pickle.load(file) |
|
|
|
|
|
|
|
|
model = pickle_data['model'] |
|
|
class_names = ["CLL case lymphocytes", "Normal lymphocytes"] |
|
|
|
|
|
|
|
|
def predict(image): |
|
|
img_array = tf.keras.preprocessing.image.img_to_array(image) |
|
|
img_array = tf.expand_dims(img_array, 0) |
|
|
|
|
|
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}%)" |
|
|
|
|
|
|
|
|
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() |
|
|
|