Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
import gradio as gr
|
5 |
+
import numpy as np
|
6 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
7 |
+
from tensorflow.keras.models import load_model
|
8 |
+
|
9 |
+
model = load_model('covid-model.h5')
|
10 |
+
ex=['./examples/' + path for path in os.listdir('examples')]
|
11 |
+
random.shuffle(ex)
|
12 |
+
|
13 |
+
def predict_image(image_path):
|
14 |
+
try:
|
15 |
+
|
16 |
+
img = cv2.imread(image_path)
|
17 |
+
img_array = img_to_array(img)
|
18 |
+
img_resized = cv2.resize(img_array, (224, 224))
|
19 |
+
prediction = model.predict(np.expand_dims(img_resized / 255.0, axis=0))
|
20 |
+
prediction = 'Normal' if prediction >= 0.5 else 'Covid'
|
21 |
+
return f'Prediction : {prediction}'
|
22 |
+
except Exception as e:
|
23 |
+
print(f"Error predicting image: {e}")
|
24 |
+
|
25 |
+
# Define the interface
|
26 |
+
def app():
|
27 |
+
title = "COVID-19 Detection using X-Ray"
|
28 |
+
|
29 |
+
gr.Interface(
|
30 |
+
title=title,
|
31 |
+
fn=predict_image,
|
32 |
+
inputs=gr.Image(type="filepath"),
|
33 |
+
outputs=gr.Textbox(),
|
34 |
+
examples=ex,
|
35 |
+
).launch()
|
36 |
+
|
37 |
+
# Run the app
|
38 |
+
if __name__ == "__main__":
|
39 |
+
app()
|