Spaces:
Sleeping
Sleeping
| 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() |