{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import tensorflow as tf\n", "from PIL import Image\n", "import numpy as np\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "model = tf.keras.models.load_model('./Trained_Model.keras')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "classes = ['glioma_tumor', 'meningioma_tumor', 'no_tumor', 'pituitary_tumor'] \n", "\n", "def preprocess_image(image_path):\n", " img = Image.open(image_path).convert('RGB') \n", " img_array = img.resize((128, 128)) \n", " return np.expand_dims(img_array, axis=0)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def predict_gradio(image):\n", " img_array = preprocess_image(image)\n", " predictions = model.predict(img_array)\n", " predicted_class = np.argmax(predictions, axis=1)[0]\n", " return classes[predicted_class]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7864\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "