rachman commited on
Commit
7efcd04
·
verified ·
1 Parent(s): 9a21153

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +49 -0
  3. my_model.keras +3 -0
  4. requirements.txt +5 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ my_model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import library
2
+ import pandas as pd
3
+ import numpy as np
4
+ import streamlit as st
5
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
6
+ import tensorflow_hub as hub
7
+
8
+ import tensorflow as tf
9
+ from tensorflow.keras.models import load_model
10
+
11
+ #import pickle
12
+ import pickle
13
+
14
+ #load model
15
+ def run():
16
+ file = st.file_uploader("Upload an image", type=["jpg", "png"])
17
+
18
+ model = load_model('my_model.keras', custom_objects={'KerasLayer': hub.KerasLayer})
19
+ target_size=(224, 224)
20
+
21
+ def import_and_predict(image_data, model):
22
+ image = load_img(image_data, target_size=(224, 224))
23
+ img_array = img_to_array(image)
24
+ img_array = tf.expand_dims(img_array, 0) # Create a batch
25
+
26
+ # Normalize the image
27
+ img_array = img_array / 255.0
28
+
29
+ # Make prediction
30
+ predictions = model.predict(img_array)
31
+
32
+ # Get the class with the highest probability
33
+ idx = np.where(predictions >= 0.5, 1, 0).item()
34
+ # predicted_class = np.argmax(predictions)
35
+
36
+ jenis = ['Brain Tumor', 'Healthy']
37
+ result = f"Prediction: {jenis[idx]}"
38
+
39
+ return result
40
+
41
+ if file is None:
42
+ st.text("Please upload an image file")
43
+ else:
44
+ result = import_and_predict(file, model)
45
+ st.image(file)
46
+ st.write(result)
47
+
48
+ if __name__ == "__main__":
49
+ run()
my_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:68cf6196d2a11321bfaa734b9b8b1f7b08fa4e59df83b63669c973f7961a033e
3
+ size 27066361
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ scikit.learn==1.3.0
5
+ tensorflow