Download app.py from Zeeshan01/hyper: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/spaces/Zeeshan01/hyper/resolve/main/app.py
- Command line
-
hf download hf://spaces/Zeeshan01/hyper/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Zeeshan01/hyper/resolve/main/app.py
2.74 kB
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Initial parameters for pretrained model | |
| IMG_SIZE = 300 | |
| labelInfo = { | |
| 'lower-gi-tract anatomical-landmarks cecum': 0, | |
| 'lower-gi-tract anatomical-landmarks ileum': 1, | |
| 'lower-gi-tract anatomical-landmarks retroflex-rectum': 2, | |
| 'lower-gi-tract pathological-findings hemorrhoids': 3, | |
| 'lower-gi-tract pathological-findings polyps': 4, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-0-1': 5, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-1': 6, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-1-2': 7, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-2': 8, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-2-3': 9, | |
| 'lower-gi-tract pathological-findings ulcerative-colitis-grade-3': 10, | |
| 'lower-gi-tract quality-of-mucosal-views bbps-0-1': 11, | |
| 'lower-gi-tract quality-of-mucosal-views bbps-2-3': 12, | |
| 'lower-gi-tract quality-of-mucosal-views impacted-stool': 13, | |
| 'lower-gi-tract therapeutic-interventions dyed-lifted-polyps': 14, | |
| 'lower-gi-tract therapeutic-interventions dyed-resection-margins': 15, | |
| 'upper-gi-tract anatomical-landmarks pylorus': 16, | |
| 'upper-gi-tract anatomical-landmarks retroflex-stomach': 17, | |
| 'upper-gi-tract anatomical-landmarks z-line': 18, | |
| 'upper-gi-tract pathological-findings barretts': 19, | |
| 'upper-gi-tract pathological-findings barretts-short-segment': 20, | |
| 'upper-gi-tract pathological-findings esophagitis-a': 21, | |
| 'upper-gi-tract pathological-findings esophagitis-b-d': 22 | |
| } | |
| # Load the model from the H5 file | |
| model = tf.keras.models.load_model('model/Hyper.h5') | |
| # Define the prediction function | |
| def predict(img): | |
| img_height = 300 | |
| img_width = 300 | |
| # Convert the NumPy array to a PIL Image object | |
| pil_img = Image.fromarray(img) | |
| # Resize the image using the PIL Image object | |
| pil_img = pil_img.resize((img_height, img_width)) | |
| # Convert the PIL Image object to a NumPy array | |
| x = tf.keras.preprocessing.image.img_to_array(pil_img) | |
| x = x.reshape(1, img_height, img_width, 3) | |
| np.set_printoptions(formatter={'float': '{: 0.3f}'.format}) | |
| predi = model.predict(x) | |
| accuracy_of_class = '{:.1f}'.format(predi[0][np.argmax(predi)] * 100) + "%" | |
| classes = list(labelInfo.keys())[np.argmax(predi)] | |
| context = { | |
| 'predictedLabel': classes, | |
| # 'y_class': y_class, | |
| # 'z_class': z_class, | |
| 'accuracy_of_class': accuracy_of_class | |
| } | |
| return context | |
| demo = gr.Interface(fn=predict, inputs="image", outputs="text" , examples=[["O1.jpg"],["O2.jpg"],["O3.jpg"]],) | |
| demo.launch() | |