Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
#import necessary libraries
|
2 |
-
import
|
3 |
import tensorflow as tf
|
4 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
5 |
from huggingface_hub import from_pretrained_keras
|
@@ -8,7 +8,7 @@ import numpy as np
|
|
8 |
def detect_cancer(img):
|
9 |
#Load the model
|
10 |
model = from_pretrained_keras('MUmairAB/Breast_Cancer_Detector')
|
11 |
-
#Convert the
|
12 |
img = tf.convert_to_tensor(img)
|
13 |
#Convert the single images to batch image
|
14 |
img = tf.expand_dims(img, axis=0)
|
@@ -20,35 +20,14 @@ def detect_cancer(img):
|
|
20 |
return("Congratulation! you don't have breast cancer")
|
21 |
else:
|
22 |
return("Unfortunately! you have breast cancer. Kindly consult a doctor!")
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
|
28 |
def main():
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
st.subheader(h1)
|
35 |
-
st.write("The model is built using Convolutional Neural Network (CNN) in TensorFlow. Its code and other interesting projects are available on my [website](https://mumairab.github.io/)")
|
36 |
-
|
37 |
-
h2 = "Enter the following values to know the status of your health"
|
38 |
-
st.write(h2)
|
39 |
-
loaded_img = st.file_uploader(label="Upload the Histopathological Image patch of breast",
|
40 |
-
type=None, accept_multiple_files=False,
|
41 |
-
key="Img_upload_key",
|
42 |
-
label_visibility="visible")
|
43 |
-
|
44 |
-
if loaded_img is not None:
|
45 |
-
# Convert the file to TensorFlow image.
|
46 |
-
loaded_img = np.asarray(bytearray(loaded_img.read()), dtype=np.uint8)
|
47 |
-
img = load_img(loaded_img, target_size=(50,50))
|
48 |
-
|
49 |
-
if st.button(label='Show the Test Results'):
|
50 |
-
prediction = detect_cancer(img)
|
51 |
-
st.success(prediction)
|
52 |
-
|
53 |
if __name__ == '__main__':
|
54 |
main()
|
|
|
1 |
#import necessary libraries
|
2 |
+
import gradio as gr
|
3 |
import tensorflow as tf
|
4 |
from tensorflow.keras.preprocessing.image import load_img, img_to_array
|
5 |
from huggingface_hub import from_pretrained_keras
|
|
|
8 |
def detect_cancer(img):
|
9 |
#Load the model
|
10 |
model = from_pretrained_keras('MUmairAB/Breast_Cancer_Detector')
|
11 |
+
#Convert the NumPy image to tensor
|
12 |
img = tf.convert_to_tensor(img)
|
13 |
#Convert the single images to batch image
|
14 |
img = tf.expand_dims(img, axis=0)
|
|
|
20 |
return("Congratulation! you don't have breast cancer")
|
21 |
else:
|
22 |
return("Unfortunately! you have breast cancer. Kindly consult a doctor!")
|
23 |
+
|
|
|
|
|
24 |
|
25 |
|
26 |
def main():
|
27 |
+
gr.Interface(fn=detect_cancer,
|
28 |
+
inputs=gr.Image(shape=(50, 50)),
|
29 |
+
outputs=gr.Label("The Test Result"),
|
30 |
+
examples=[0, 1]).launch()
|
31 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
if __name__ == '__main__':
|
33 |
main()
|