# -*- coding: utf-8 -*- """app Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1bK9oazNpp0ELz8EATsAmWYgKaiUpdV3W """ import gradio as gr import tensorflow as tf import keras import numpy as np import gradio import requests from tensorflow.keras.models import load_model import json from os.path import dirname, realpath, join model=load_model("model.h5") with open("label.json") as labels_file: labels = json.load(labels_file) def trans_image(pillow_image): a = np.array(pillow_image.resize((128,128))) a = a.reshape(1,128,128,3) return a def brain(predict): if predict==0: return 'Glioma Tumor' elif predict==1: return 'Meningioma Tumor' elif predict==2: return 'No Tumor or Normal' else: return 'Pituitary Tumor' def predictions(x): a = model.predict(x) classi = np.where(a == np.amax(a))[1][0] return str(a[0][classi]*100), brain(classi) def predicts(img): img = img.reshape((1, 128, 128, 3)) prediction = model.predict(img).flatten() return {labels[i]: float(prediction[i]) for i in range(4)} image = gradio.inputs.Image(shape=(128, 128), source="upload") label = gr.outputs.Label(num_top_classes= 5) iface = gr.Interface( fn = predicts, inputs = image, outputs = label, ) iface.launch(debug=True, share=False)