File size: 1,128 Bytes
a51de7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712e778
a51de7b
 
 
7c3435d
 
 
a51de7b
712e778
 
a51de7b
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr 
from PIL import Image 
import numpy as np
import tensorflow as tf

class_names = ['Covid19','Normal','Viral Pneumonia']

def process_image(image):
  image = image.resize((224,224))
  image = np.array(image) / 255.0
  image = np.expand_dims(image, axis=0) # (224,224,3)
  return image

model = tf.keras.models.load_model('Covid19_Model.h5')

def predict_image(image):
  processed_image = process_image(image)
  prediction = model.predict(processed_image)
  predicted_class_index = np.argmax(prediction)  # ---> [0.23,0.58,0.86]
  predicted_class_name = class_names[predicted_class_index]
  return f"Prediction: {predicted_class_name}"

examples = ['Samples/064.jpeg',
            'Samples/072.jpeg',
            'Samples/076.jpeg']

# Samples\076.jpeg

interface = gr.Interface(fn= predict_image,
                          inputs= gr.Image(type="pil"),
                          outputs='text',
                          title= "Covid19, Viral pneumonia or Normal",
                          description="import an image to get predictions",
                          examples=examples)



interface.launch()