DHEIVER commited on
Commit
0ea2c03
1 Parent(s): 728545a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('stomach.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
+ examples=[
33
+ ['examples/0.jpg'],
34
+ ['examples/1.jpg'],
35
+ ])
36
+ iface.launch()