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 +81 -0
- model/Hyper.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: Hyper
|
| 3 |
-
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: gray
|
| 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: Hyper
|
| 3 |
+
app_file: app.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 3.35.2
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (2.67 kB). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 16 |
+
labelInfo = {
|
| 17 |
+
'lower-gi-tract anatomical-landmarks cecum': 0,
|
| 18 |
+
'lower-gi-tract anatomical-landmarks ileum': 1,
|
| 19 |
+
'lower-gi-tract anatomical-landmarks retroflex-rectum': 2,
|
| 20 |
+
'lower-gi-tract pathological-findings hemorrhoids': 3,
|
| 21 |
+
'lower-gi-tract pathological-findings polyps': 4,
|
| 22 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-0-1': 5,
|
| 23 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-1': 6,
|
| 24 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-1-2': 7,
|
| 25 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-2': 8,
|
| 26 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-2-3': 9,
|
| 27 |
+
'lower-gi-tract pathological-findings ulcerative-colitis-grade-3': 10,
|
| 28 |
+
'lower-gi-tract quality-of-mucosal-views bbps-0-1': 11,
|
| 29 |
+
'lower-gi-tract quality-of-mucosal-views bbps-2-3': 12,
|
| 30 |
+
'lower-gi-tract quality-of-mucosal-views impacted-stool': 13,
|
| 31 |
+
'lower-gi-tract therapeutic-interventions dyed-lifted-polyps': 14,
|
| 32 |
+
'lower-gi-tract therapeutic-interventions dyed-resection-margins': 15,
|
| 33 |
+
'upper-gi-tract anatomical-landmarks pylorus': 16,
|
| 34 |
+
'upper-gi-tract anatomical-landmarks retroflex-stomach': 17,
|
| 35 |
+
'upper-gi-tract anatomical-landmarks z-line': 18,
|
| 36 |
+
'upper-gi-tract pathological-findings barretts': 19,
|
| 37 |
+
'upper-gi-tract pathological-findings barretts-short-segment': 20,
|
| 38 |
+
'upper-gi-tract pathological-findings esophagitis-a': 21,
|
| 39 |
+
'upper-gi-tract pathological-findings esophagitis-b-d': 22
|
| 40 |
+
}
|
| 41 |
+
# Load the model from the H5 file
|
| 42 |
+
model = tf.keras.models.load_model('model/Hyper.h5')
|
| 43 |
+
|
| 44 |
+
# Define the prediction function
|
| 45 |
+
def predict(img):
|
| 46 |
+
img_height = 300
|
| 47 |
+
img_width = 300
|
| 48 |
+
|
| 49 |
+
# Convert the NumPy array to a PIL Image object
|
| 50 |
+
pil_img = Image.fromarray(img)
|
| 51 |
+
|
| 52 |
+
# Resize the image using the PIL Image object
|
| 53 |
+
pil_img = pil_img.resize((img_height, img_width))
|
| 54 |
+
|
| 55 |
+
# Convert the PIL Image object to a NumPy array
|
| 56 |
+
x = tf.keras.preprocessing.image.img_to_array(pil_img)
|
| 57 |
+
|
| 58 |
+
x = x.reshape(1, img_height, img_width, 3)
|
| 59 |
+
np.set_printoptions(formatter={'float': '{: 0.3f}'.format})
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
predi = model.predict(x)
|
| 63 |
+
accuracy_of_class = '{:.1f}'.format(predi[0][np.argmax(predi)] * 100) + "%"
|
| 64 |
+
classes = list(labelInfo.keys())[np.argmax(predi)]
|
| 65 |
+
context = {
|
| 66 |
+
'predictedLabel': classes,
|
| 67 |
+
# 'y_class': y_class,
|
| 68 |
+
# 'z_class': z_class,
|
| 69 |
+
'accuracy_of_class': accuracy_of_class
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
return context
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
demo = gr.Interface(fn=predict, inputs="image", outputs="text" , examples=[["O1.jpg"],["O2.jpg"],["O3.jpg"]],)
|
| 79 |
+
|
| 80 |
+
demo.launch()
|
| 81 |
+
|
model/Hyper.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e9255d46684df0f3be60cdafc04b3dc2e7520041741d2265aec51b36ae1df9a1
|
| 3 |
+
size 135418472
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
pillow
|