Diaa-Zaher commited on
Commit
a51de7b
·
1 Parent(s): 6417f79

Add application file

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
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+
6
+ class_names = ['Covid19','Normal','Viral Pneumonia']
7
+
8
+ def process_image(image):
9
+ image = image.resize((224,224))
10
+ image = np.array(image) / 255.0
11
+ image = np.expand_dims(image, axis=0) # (224,224,3)
12
+ return image
13
+
14
+ model = tf.keras.models.load_model('Covid19_Model.h5')
15
+
16
+ def predict_image(image):
17
+ processed_image = process_image(image)
18
+ prediction = model.predict(processed_image)
19
+ predicted_class_index = np.argmax(prediction)
20
+ predicted_class_name = class_names[predicted_class_index]
21
+ return f"Prediction: {predicted_class_name}"
22
+
23
+ examples = ['D:/Machine Learning Course/Covid19_Deployment/Covid19-viral-normal/Samples/064.jpeg',
24
+ 'D:/Machine Learning Course/Covid19_Deployment/Covid19-viral-normal/Samples/072.jpeg',
25
+ 'D:/Machine Learning Course/Covid19_Deployment/Covid19-viral-normal/Samples/076.jpeg']
26
+
27
+ interface = gr.Interface(fn= predict_image,
28
+ inputs= gr.Image(type="pil"),
29
+ outputs='text',
30
+ title= "Covid19, Viral pneumonia or Normal",
31
+ description="import an image to get predictions",
32
+ examples=examples)
33
+
34
+
35
+
36
+ interface.launch()