Zeeshan01 commited on
Commit
d09b024
·
1 Parent(s): d6a2153

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. README.md +2 -8
  2. __pycache__/app.cpython-310.pyc +0 -0
  3. app.py +62 -0
  4. brain01.jpg +0 -0
  5. brain02.jpg +0 -0
  6. model/braintumor.h5 +3 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Braintumor
3
- emoji: 📈
4
- colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 3.35.2
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: BrainTumor
3
+ app_file: app.py
 
 
4
  sdk: gradio
5
  sdk_version: 3.35.2
 
 
6
  ---
 
 
__pycache__/app.cpython-310.pyc ADDED
Binary file (1.2 kB). View file
 
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+
7
+
8
+
9
+
10
+
11
+ # Initial parameters for pretrained model
12
+ IMG_SIZE = 300
13
+
14
+ labelInfoBrain = {
15
+ 'glioma_tumor': 0,
16
+ 'no_tumor': 1,
17
+ 'meningioma_tumor': 2,
18
+ 'pituitary_tumor': 3
19
+ }
20
+
21
+ # Load the model from the H5 file
22
+ model = tf.keras.models.load_model('model/braintumor.h5')
23
+
24
+ # Define the prediction function
25
+ def predict(img):
26
+ img_height = 150
27
+ img_width = 150
28
+
29
+ # Convert the NumPy array to a PIL Image object
30
+ pil_img = Image.fromarray(img)
31
+
32
+ # Resize the image using the PIL Image object
33
+ pil_img = pil_img.resize((img_height, img_width))
34
+
35
+ # Convert the PIL Image object to a NumPy array
36
+ x = tf.keras.preprocessing.image.img_to_array(pil_img)
37
+
38
+ x = x.reshape(1, img_height, img_width, 3)
39
+ np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
40
+
41
+
42
+ predi = model.predict(x)
43
+ accuracy_of_class = '{:.1f}'.format(predi[0][np.argmax(predi)] * 100) + "%"
44
+ classes = list(labelInfoBrain.keys())[np.argmax(predi)]
45
+ context = {
46
+ 'predictedLabel': classes,
47
+ # 'y_class': y_class,
48
+ # 'z_class': z_class,
49
+ 'accuracy_of_class': accuracy_of_class
50
+ }
51
+
52
+
53
+
54
+ return context
55
+
56
+
57
+
58
+ demo = gr.Interface(fn=predict, inputs="image", outputs="text" , examples=[["brain01.jpg"],["brain02.jpg"]],)
59
+
60
+ demo.launch(share=True,server_port=8000)
61
+
62
+
brain01.jpg ADDED
brain02.jpg ADDED
model/braintumor.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dcb9e38ff8d3cd3fadc65fa0c67d97d6aba23a00dbe7fbab6dbbe5a6a9d02728
3
+ size 202133552