segestic's picture
Update app.py
580f2d7 verified
raw
history blame
1.06 kB
import os
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
import cv2
###
def image_predict (image):
model_path = 'resnet_ct.h5'
h5_model = load_model(model_path)
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:")
print (probability)
if probability[0] > 0.5:
covid_chest_pred = str('%.2f' % (probability[0] * 100) + '% COVID-Positive')
probability = (probability[0] * 100)
else:
covid_chest_pred = str('%.2f' % ((1 - probability[0]) * 100) + '% COVID-Negative')
probability = ((1 - probability[0]) * 100)
return covid_chest_pred
#myApp = gr.Interface(fn=image_predict, inputs="image", outputs="text")
myApp = gr.Interface(fn=image_predict, inputs=gr.Image(type="numpy"), outputs=gr.Text()).launch()
myApp.launch(share=True)#share=True