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