SondosMB commited on
Commit
72f9149
1 Parent(s): 7e610b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py CHANGED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pip install gradio==3.14.0
2
+ import gradio as gr
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ import matplotlib.pyplot as plt
6
+ from PIL import Image
7
+ import pickle
8
+ from tensorflow.keras.models import load_model
9
+
10
+ # Load the RGB to hyperspectral conversion model
11
+ converion_model = load_model('/kaggle/input/convmo/Conversion_model.h5')
12
+
13
+ # Load the cancer classification model
14
+ #cancer_model = pickle.load(open("/kaggle/input/classi/ClassRF (1).pkl", "rb"))
15
+
16
+ cancer_model = pickle.load(open("/kaggle/input/logistic/LRclass.pkl", "rb"))
17
+
18
+ def classify(rgb_image):
19
+ img = Image.fromarray(rgb_image.astype('uint8'), 'RGB')
20
+ img = img.resize((272, 512))
21
+ arr = np.array(img).astype('float32') / 255.0
22
+ new_size = (272, 512)
23
+ resized_rgb_img = tf.image.resize(arr, new_size)
24
+ resized_rgb_img = tf.reshape(resized_rgb_img, (272, 512, 3))
25
+ resized_rgb_img = np.expand_dims(resized_rgb_img , axis=0)
26
+
27
+ # Convert the RGB image to hyperspectral using your model
28
+ hyperspectral_image = converion_model(resized_rgb_img)
29
+ hyperspectral_image = tf.image.resize(hyperspectral_image, new_size)
30
+ hyperspectral_image = tf.reshape(hyperspectral_image, (272, 512, 16))
31
+ imgplot = hyperspectral_image.numpy().astype(np.float32)
32
+ imgplot= imgplot.reshape(-1, 272*512*16)
33
+ prediction = cancer_model.predict(imgplot)
34
+ if np.argmax(prediction) == 0:
35
+ x= "cancer"
36
+ else:
37
+ x="not a cancer"
38
+ return x
39
+
40
+ # Define the Gradio interface
41
+ #image_input = gr.inputs.Image()
42
+ output_label = gr.components.Label()
43
+ #output_label=["text"]
44
+ image_input = gr.components.Image()
45
+ gr.Interface(
46
+ classify,
47
+ image_input,
48
+ output_label,
49
+ title="RGB to Hyperspectral Conversion and Cancer Classification",
50
+ description="Upload an RGB image and get a prediction of whether you have skin cancer or not."
51
+ ).launch(share=True)
52
+
53
+