from skimage.util import montage as montage2d from utils import load_model, preprocess_image, attempt_download_from_hub import matplotlib.pyplot as plt import gradio as gr def keras_inference(img_data, model_path): model_path = attempt_download_from_hub(model_path) seg_model = load_model(model_path) out_img = preprocess_image(img_data) pred_y = seg_model.predict(out_img) plt.imshow(montage2d(pred_y[:, :, :, 0]), cmap = 'bone_r') plt.savefig('output.png') return 'output.png' inputs = [ gr.Image(type='filepath', label='Image'), gr.Dropdown(['kadirnar/Keras-Segmenting-Buildings-v1'], value="kadirnar/Keras-Segmenting-Buildings-v1", label='Model Path') ] outputs = gr.Image(label='Segmentation') examples = [ ['data/testv1.jpg', 'kadirnar/Keras-Segmenting-Buildings-v1'], ['data/testv2.jpg', 'kadirnar/Keras-Segmenting-Buildings-v1'], ['data/testv3.jpg', 'kadirnar/Keras-Segmenting-Buildings-v1'], ] title = 'Segmenting Buildings in Satellite Images with Keras' demo_app = gr.Interface( keras_inference, inputs, outputs, title=title, examples=examples, cache_examples=True, ) demo_app.launch(debug=True, enable_queue=True)