drkareemkamal commited on
Commit
c0ff9ff
·
verified ·
1 Parent(s): c167a16

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import os
5
+
6
+ model = tf.keras.models.load_model('Brain_tumor/')
7
+ st.write('Model is loaded successfully')
8
+
9
+ TEMP_DIR = 'temp'
10
+
11
+ class_names = ['glioma', 'meningioma', 'notumor', 'pituitary']
12
+
13
+ def load_and_prep_imgg(filename ,img_shape=229, scale=True):
14
+
15
+ img = tf.io.read_file(filename)
16
+
17
+ img = tf.io.decode_image(img)
18
+
19
+ img = tf.image.resize(img,size=[img_shape,img_shape])
20
+
21
+ if scale :
22
+ return img/255
23
+ else :
24
+ return img
25
+
26
+ st.title('Brain Tumor Classidfication Predition using Xception ImageNet ')
27
+
28
+ uploaded_file = st.sidebar.file_uploader('Upload your Image', type=['jpg'])
29
+
30
+ if uploaded_file:
31
+
32
+ file_path = os.path.join(TEMP_DIR, uploaded_file.name)
33
+ img = load_and_prep_imgg(file_path,scale=True)
34
+ imgg = Image.open(file_path)
35
+ st.image(img,caption ="Predicted brain tumor is : {pred_class} with probs : {pred_img:max():.2f}" )
36
+
37
+ pred_img = model.predict(tf.expand_dims(img,axis=0))
38
+ pred_class = class_names[pred_img.argmax()]
39
+ st.write(f"Predicted brain tumor is : {pred_class} with probs : {pred_img:max():.2f}")
40
+