File size: 1,151 Bytes
e029c27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr


def image_predict (image_pt):
    model_path = 'model/resnet_ct.h5'
    h5_model = load_model(model_path)

    #OLD IMAGE
    image = cv2.imread(image_pt)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image = cv2.resize(image, (224, 224))
    image = np.array(image) / 255
    image = np.expand_dims(image, axis=0)
    h5_prediction = h5_model.predict(image)  
    print('Prediction from h5 model: {}'.format(h5_prediction))
    print(h5_prediction)
    probability = h5_prediction[0]
    print("H5 Predictions:")
    status = 'error'
    probability = 0
    if probability[0] > 0.5:
        covid_chest_pred = str('%.2f' % (probability[0] * 100) + '% COVID-Positive')
        status = 'Covid-Positive'
        probability = (probability[0] * 100)
    else:
        covid_chest_pred = str('%.2f' % ((1 - probability[0]) * 100) + '% COVID-Negative')
        status = 'Covid-Negative'
        probability = ((1 - probability[0]) * 100)
    print(covid_chest_pred)
    return {'status': str(status), 'probability': str(probability) }



myApp = gr.Interface(fn=image_predict, inputs="image", outputs="label")
myApp.launch()