Upload folder using huggingface_hub
Browse files- README.md +1 -7
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +58 -0
- b1.png +0 -0
- b2.png +0 -0
- model/BreastCancer.h5 +3 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
title: BCancer
|
3 |
-
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: blue
|
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: BCancer
|
3 |
+
app_file: app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 3.35.2
|
|
|
|
|
6 |
---
|
|
|
|
__pycache__/app.cpython-310.pyc
ADDED
Binary file (1.14 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
labelsBreast = {'Benign':0,
|
15 |
+
'Malignant':1,
|
16 |
+
'Normal':2}
|
17 |
+
|
18 |
+
# Load the model from the H5 file
|
19 |
+
model = tf.keras.models.load_model('model/BreastCancer.h5')
|
20 |
+
|
21 |
+
# Define the prediction function
|
22 |
+
def predict(img):
|
23 |
+
img_height = 224
|
24 |
+
img_width = 224
|
25 |
+
|
26 |
+
# Convert the NumPy array to a PIL Image object
|
27 |
+
pil_img = Image.fromarray(img)
|
28 |
+
|
29 |
+
# Resize the image using the PIL Image object
|
30 |
+
pil_img = pil_img.resize((img_height, img_width))
|
31 |
+
|
32 |
+
# Convert the PIL Image object to a NumPy array
|
33 |
+
x = tf.keras.preprocessing.image.img_to_array(pil_img)
|
34 |
+
|
35 |
+
x = x.reshape(1, img_height, img_width, 3)
|
36 |
+
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
|
37 |
+
|
38 |
+
|
39 |
+
predi = model.predict(x)
|
40 |
+
accuracy_of_class = '{:.1f}'.format(predi[0][np.argmax(predi)] * 100) + "%"
|
41 |
+
classes = list(labelsBreast.keys())[np.argmax(predi)]
|
42 |
+
context = {
|
43 |
+
'predictedLabel': classes,
|
44 |
+
# 'y_class': y_class,
|
45 |
+
# 'z_class': z_class,
|
46 |
+
'accuracy_of_class': accuracy_of_class
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
return context
|
52 |
+
|
53 |
+
|
54 |
+
|
55 |
+
demo = gr.Interface(fn=predict, inputs="image", outputs="text" , examples=[["b1.png"],["b2.png"]],)
|
56 |
+
|
57 |
+
demo.launch()
|
58 |
+
|
b1.png
ADDED
![]() |
b2.png
ADDED
![]() |
model/BreastCancer.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9a2d31cc5eed3d9ad783f825e5233ad0c983d033de76d28581bb510d3d2d67ff
|
3 |
+
size 177263680
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
numpy
|
3 |
+
pillow
|