Spaces:
Sleeping
Sleeping
File size: 1,594 Bytes
5e21dd3 97d56f9 8e3bc0e 6b0fbd1 5e21dd3 97d56f9 fd472ac 5e21dd3 6b0fbd1 5e21dd3 6b0fbd1 aa671f0 fd472ac aa671f0 8ffc381 6b0fbd1 60e6d39 6b0fbd1 78d84ec 6b0fbd1 60e6d39 8ffc381 6b0fbd1 2f62ccf |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tensorflow.keras.optimizers import Adam, Adamax
import numpy as np
# Load the trained model
model = tf.keras.models.load_model('Model1_kera.h5', compile=False)
model.compile(Adamax(learning_rate= 0.001), loss= 'categorical_crossentropy', metrics= ['accuracy'])
# model = tf.keras.models.load_model('Model1_kera.h5')
# Define the class names
classes = ['Colon Adenocarcinoma', 'Colon Benign Tissue', 'Lung Adenocarcinoma', 'Lung Benign Tissue', 'Lung Squamous Cell Carcinoma']
# Function to preprocess the uploaded image and make predictions
def predict(img):
try:
img = img.resize((224, 224))
img_array = tf.keras.preprocessing.image.img_to_array(img)
img_array = tf.expand_dims(img_array, 0)
predictions = model.predict(img_array)
class_labels = classes
# predictions = model.predict(img_array)
# predicted_class = classes[np.argmax(predictions[0])]
score = tf.nn.softmax(predictions[0])
# print(f"{class_labels[tf.argmax(score)]}")
return f"Prediction: {class_labels[tf.argmax(score)]}"
except Exception as e:
return str(e)
# Create a Gradio interface
iface = gr.Interface(
fn=predict,
inputs=gr.Image(type='pil'),
outputs=gr.Textbox(label="Prediction"),
title="Lung and Colon Cancer Detection",
description="Upload an image of histopathological tissue to detect if it is a type of lung or colon cancer."
)
# Launch the interface
iface.launch(share=True)
|