daniel15568/Dog-Breed-Classification
0
1import os, subprocess2packages = ['tensorflow==2.12.0', 'tensorflow-hub==0.14.0', 'numpy']3for package in packages:4 subprocess.check_call([os.sys.executable, "-m", "pip", "install", package])5 6import tensorflow as tf7import tensorflow_hub as hub8import pandas as pd9import numpy as np10import gradio as gr11from PIL import Image12 13 14model = tf.keras.models.load_model("dogbreed.h5", custom_objects={'KerasLayer': hub.KerasLayer})15 16data = pd.read_csv('labels.csv')17classes = data.breed.unique()18 19 20def predict(image):21 image = Image.fromarray(image).resize((224, 224))22 image = np.array(image) / 25523 image = np.expand_dims(image, axis=0)24 predictions = model.predict(image)25 predicted_class = classes[np.argmax(predictions)]26 return predicted_class27 28 29interface = gr.Interface(30 fn=predict,31 inputs=gr.Image(type="numpy"),32 outputs="text",33 title="Dog Breeds Classifier",34 description="Upload a dog image to get the predicted breed"35)36 37interface.launch()38 