drkareemkamal commited on
Commit
7849494
·
verified ·
1 Parent(s): 982f37c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if not os.path.exists(TEMP_DIR):
11
+ os.makedirs(TEMP_DIR)
12
+
13
+ class_names = ['glioma', 'meningioma', 'notumor', 'pituitary']
14
+
15
+ def load_and_prep_imgg(filename ,img_shape=229, scale=True):
16
+
17
+ img = tf.io.read_file(filename)
18
+
19
+ img = tf.io.decode_image(img)
20
+
21
+ img = tf.image.resize(img,size=[img_shape,img_shape])
22
+
23
+ if scale :
24
+ return img/255
25
+ else :
26
+ return img
27
+
28
+ st.title('Brain Tumor Classidfication Predition using Xception ImageNet ')
29
+
30
+ uploaded_file = st.sidebar.file_uploader('Upload your Image', type=['jpg'])
31
+
32
+ if uploaded_file:
33
+
34
+ #file_path = os.path.join(uploaded_file.name)
35
+ img = load_and_prep_imgg(uploaded_file.name,scale=True)
36
+ imgg = Image.open(uploaded_file.name)
37
+ st.image(img,caption ="Predicted brain tumor is : {pred_class} with probs : {pred_img:max():.2f}" )
38
+
39
+ pred_img = model.predict(tf.expand_dims(img,axis=0))
40
+ pred_class = class_names[pred_img.argmax()]
41
+ st.write(f"Predicted brain tumor is : {pred_class} with probs : {pred_img:max():.2f}")
42
+