Spaces:
Sleeping
Sleeping
File size: 1,123 Bytes
5c9d3b5 7afb0b9 6da6511 5c9d3b5 7afb0b9 932eb5f 7afb0b9 ca0ea7f 7afb0b9 ca0ea7f 7afb0b9 a2f2d80 5c9d3b5 5602dac 3802ba3 adf31a0 3802ba3 7afb0b9 3802ba3 5c9d3b5 |
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 |
import gradio as gr
import tensorflow
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
import os
model = tf.keras.models.load_model("fine_tuned_resnet50.h5")
img_dim = (224, 224)
lung_cancer_labels = ["Adenocarcinoma", "Benign", "Carcinoma"]
# returning classifiers output
def predict(img):
img = img.resize(img_dim)
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
prediction = model.predict(img_array)
class_index = np.argmax(prediction)
confidence = np.max(prediction)
return f"{lung_cancer_labels[class_index]} (Confidence: {confidence:.2f})"
with gr.Blocks() as demo:
gr.Markdown("# Lung Cancer Classifier")
with gr.Row():
with gr.Column():
input_image = gr.Image(label="Input Image", type="pil")
submit_btn = gr.Button("Detect Cancer")
with gr.Column():
output_text = gr.Textbox(label="Model Results")
submit_btn.click(
fn=predict,
inputs=[input_image],
outputs=[output_text]
)
demo.launch() |