Spaces:
Sleeping
Sleeping
Commit
·
2b7fc9b
1
Parent(s):
dd6b795
init
Browse files- app.py +37 -0
- examples/0.jpg +0 -0
- examples/1.jpg +0 -0
- model.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model = tf.keras.models.load_model('model.h5')
|
| 7 |
+
|
| 8 |
+
# Define the class names
|
| 9 |
+
class_names = {
|
| 10 |
+
0: 'Esophagitis',
|
| 11 |
+
1: 'Dyed lifted polyps'
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def classify_image(image):
|
| 16 |
+
# Preprocess the image
|
| 17 |
+
img_array = tf.image.resize(image, [256, 256])
|
| 18 |
+
img_array = tf.expand_dims(img_array, 0) / 255.0
|
| 19 |
+
|
| 20 |
+
# Make a prediction
|
| 21 |
+
prediction = model.predict(img_array)
|
| 22 |
+
predicted_class = tf.argmax(prediction[0], axis=-1)
|
| 23 |
+
confidence = np.max(prediction[0])
|
| 24 |
+
|
| 25 |
+
return class_names[predicted_class.numpy()], confidence
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=classify_image,
|
| 30 |
+
inputs="image",
|
| 31 |
+
outputs=["text", "number"],
|
| 32 |
+
interpretation="default",
|
| 33 |
+
examples=[
|
| 34 |
+
['examples/0.jpg'],
|
| 35 |
+
['examples/1.jpg'],
|
| 36 |
+
])
|
| 37 |
+
iface.launch()
|
examples/0.jpg
ADDED
|
examples/1.jpg
ADDED
|
model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a2619338d832d73cb50e6f9fe5be1c436341fdae8f9d3db10f7a046836317e69
|
| 3 |
+
size 4468544
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
pillow
|
| 4 |
+
tensorflow_hub
|