segestic commited on
Commit
e029c27
1 Parent(s): 9ddcc5d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ def image_predict (image_pt):
5
+ model_path = 'model/resnet_ct.h5'
6
+ h5_model = load_model(model_path)
7
+
8
+ #OLD IMAGE
9
+ image = cv2.imread(image_pt)
10
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
11
+ image = cv2.resize(image, (224, 224))
12
+ image = np.array(image) / 255
13
+ image = np.expand_dims(image, axis=0)
14
+ h5_prediction = h5_model.predict(image)
15
+ print('Prediction from h5 model: {}'.format(h5_prediction))
16
+ print(h5_prediction)
17
+ probability = h5_prediction[0]
18
+ print("H5 Predictions:")
19
+ status = 'error'
20
+ probability = 0
21
+ if probability[0] > 0.5:
22
+ covid_chest_pred = str('%.2f' % (probability[0] * 100) + '% COVID-Positive')
23
+ status = 'Covid-Positive'
24
+ probability = (probability[0] * 100)
25
+ else:
26
+ covid_chest_pred = str('%.2f' % ((1 - probability[0]) * 100) + '% COVID-Negative')
27
+ status = 'Covid-Negative'
28
+ probability = ((1 - probability[0]) * 100)
29
+ print(covid_chest_pred)
30
+ return {'status': str(status), 'probability': str(probability) }
31
+
32
+
33
+
34
+ myApp = gr.Interface(fn=image_predict, inputs="image", outputs="label")
35
+ myApp.launch()