CoolFace
Apppublic

aexcza/Machine_Learning_Integration

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py34 linesDownload Raw Back to root
1import gradio as gr2import tensorflow as tf3from PIL import Image4import numpy as np5 6# Load the TensorFlow model7model = tf.keras.models.load_model(r'C:\Users\User\Downloads\transportationn_model.h5')8 9# Define the prediction function10def predict(image):11    # Preprocess the input image12    img = np.array(image).astype('float32') / 255.013    img = tf.image.resize(img, (224, 224))  # Assuming input size is (224, 224)14    img = np.expand_dims(img, axis=0)15    16    # Make predictions17    predictions = model.predict(img)18    19    # Return the predictions20    return predictions[0]21 22# Define Gradio interface23title = "Transportation Classifier ✈️🛳️🚆"24description = "Classifier trained on images of airplane, cruise ship, train, car, and motorcycle. Created as a demo for Deep Learning app using HuggingFace Spaces & Gradio."25examples = ['train.jpg', 'airplane.jpg', 'car.jpg', 'cruise ship.jpg', 'motorcycle.jpg']26 27gr.Interface(28    fn=predict,29    inputs=gr.inputs.Image(shape=(224, 224)),30    outputs=gr.outputs.Label(num_top_classes=5),31    title=title,32    description=description,33    examples=examples).launch()34