{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "import tensorflow as tf\n", "import numpy as np\n", "\n", "# Load the pre-trained model\n", "model = tf.keras.models.load_model(\"\")\n", "\n", "# Define the prediction function\n", "def classify_image(image):\n", " # Preprocess the image\n", " image = tf.image.resize(image, (224, 224))\n", " image = tf.keras.applications.mobilenet_v2.preprocess_input(image)\n", " image = np.expand_dims(image, axis=0)\n", "\n", " # Make predictions\n", " predictions = model.predict(image)\n", " label = np.argmax(predictions[0])\n", " confidence = predictions[0][label]\n", "\n", " return label, confidence\n", "\n", "# Create the Gradio interface\n", "inputs = gr.inputs.Image()\n", "outputs = gr.outputs.Label(num_top_classes=3)\n", "\n", "# Launch the interface with a public link\n", "gr.Interface(\n", " fn=classify_image, \n", " inputs=inputs, \n", " outputs=outputs, \n", " title=\"Micro-Guru\", \n", " description=\"Upload an image and the model will predict its class along with the confidence level.\"\n", ").launch(share=True)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }