Spaces:
Runtime error
Runtime error
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() |