Spaces:
Runtime error
Runtime error
import gradio as gr | |
import numpy as np | |
from tensorflow.keras.models import load_model | |
from PIL import Image | |
# Load the trained model | |
model = load_model('skin_model.h5') | |
# Define a function to make predictions | |
def predict(name, age, image): | |
# Preprocess the image | |
image = Image.fromarray(image) | |
image = image.resize((150, 150)) | |
image = np.array(image) / 255.0 | |
image = np.expand_dims(image, axis=0) | |
# Make a prediction using the model | |
prediction = model.predict(image) | |
# Get the predicted class label | |
if prediction[0][0] < 0.5: | |
label = 'Benign' | |
else: | |
label = 'Malignant' | |
return f"Patient: {name}, Age: {age}, Prediction: {label}" | |
# Define input and output components | |
name_input = gr.inputs.Text(label="Patient's Name") | |
age_input = gr.inputs.Text(label="Patient's Age") | |
image_input = gr.inputs.Image(shape=(150, 150)) | |
label_output = gr.outputs.Label() | |
# Define a Gradio interface for user interaction | |
iface = gr.Interface( | |
fn=predict, | |
inputs=[name_input, age_input, image_input], | |
outputs=label_output, | |
title="Skin Cancer Classification Chatbot", | |
description="Predicts whether a skin image is cancerous or not based on patient's name, age, and lesion image.", | |
theme="default", # Choose a theme: "default", "compact", "huggingface" | |
layout="vertical", # Choose a layout: "vertical", "horizontal", "double" | |
live=False # Set to True for live updates without clicking "Submit" | |
) | |
iface.launch() | |