import gradio as gr import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from PIL import Image import pickle from tensorflow.keras.models import load_model import os os.system('wget -O model.h5 "https://drive.google.com/u/0/uc?id=1UqXYR2e3c0VW8Ax4nYLvef7Vmlx3AEGi&export=download"') os.system('wget -O model2.pkl "https://drive.google.com/u/0/uc?id=16FuBwWEhG7oHH2YGm8EkEDTbv6GSUbyg&export=download"') # Load the RGB to hyperspectral conversion model #converion_model = load_model('/kaggle/input/convmo/Conversion_model.h5') converion_model = tf.keras.models.load_model("model.5") # Load the cancer classification model #cancer_model = pickle.load(open("/kaggle/input/classi/ClassRF (1).pkl", "rb")) cancer_model = pickle.load(open("model2.pkl", "rb")) def classify(rgb_image): img = Image.fromarray(rgb_image.astype('uint8'), 'RGB') img = img.resize((272, 512)) arr = np.array(img).astype('float32') / 255.0 new_size = (272, 512) resized_rgb_img = tf.image.resize(arr, new_size) resized_rgb_img = tf.reshape(resized_rgb_img, (272, 512, 3)) resized_rgb_img = np.expand_dims(resized_rgb_img , axis=0) # Convert the RGB image to hyperspectral using your model hyperspectral_image = converion_model(resized_rgb_img) hyperspectral_image = tf.image.resize(hyperspectral_image, new_size) hyperspectral_image = tf.reshape(hyperspectral_image, (272, 512, 16)) imgplot = hyperspectral_image.numpy().astype(np.float32) imgplot= imgplot.reshape(-1, 272*512*16) prediction = cancer_model.predict(imgplot) if np.argmax(prediction) == 0: x= "cancer" else: x="not a cancer" return x # Define the Gradio interface #image_input = gr.inputs.Image() output_label = gr.components.Label() #output_label=["text"] image_input = gr.components.Image() gr.Interface( classify, image_input, output_label, title="RGB to Hyperspectral Conversion and Cancer Classification", description="Upload an RGB image and get a prediction of whether you have skin cancer or not." ).launch(share=True)