MUmairAB commited on
Commit
9821f8b
1 Parent(s): aed0572

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -1,6 +1,25 @@
 
1
  import streamlit as st
2
- import numpy as input
3
  from tensorflow.keras.preprocessing.image import load_img, img_to_array
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
  def main():
@@ -21,13 +40,8 @@ def main():
21
 
22
  if uploaded_file is not None:
23
  # Convert the file to TensorFlow image.
24
- file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
25
- img = load_img(file_bytes, target_size=(50,50))
26
- #Rescale the image from [0,255] to [0,1]
27
- np_image = np.array(image).astype('float32')/255.0
28
 
29
- image = tf.keras.utils.load_img(image_path)
30
- input_arr = tf.keras.utils.img_to_array(image)
31
- input_arr = np.array([input_arr]) # Convert single image to a batch.
32
- predictions = model.predict(input_arr)
33
 
 
1
+ #import necessary libraries
2
  import streamlit as st
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
6
+ import numpy as np
7
+
8
+ def detect_cancer(img):
9
+ #Load the model
10
+ model = from_pretrained_keras('MUmairAB/Breast_Cancer_Detector')
11
+ #Convert the PIL ImageFile to image tensor
12
+ img = tf.convert_to_tensor(img)
13
+ #Convert the single images to batch image
14
+ img = tf.expand_dims(img, axis=0)
15
+ #Make predictions
16
+ pred = model.predict(img)
17
+ #Convert the "numpy.ndarray" object to a simple numebr
18
+ prediction = round(float(pred))
19
+ return prediction
20
+
21
+
22
+
23
 
24
 
25
  def main():
 
40
 
41
  if uploaded_file is not None:
42
  # Convert the file to TensorFlow image.
43
+ loaded_img = np.asarray(bytearray(loaded_img.read()), dtype=np.uint8)
44
+ img = load_img(loaded_img, target_size=(50,50))
45
+ prediction = detect_cancer(img)
 
46
 
 
 
 
 
47