import gradio as gr import tensorflow as tf import numpy as np from PIL import Image # Load model model = tf.keras.models.load_model("model/car_model.h5") class_names = ['Audi A4', 'Toyota Corolla', 'BMW X5', 'Ford Focus', 'Honda Civic', 'Hyundai Elantra', 'Mercedes C Class', 'Kia Sportage', 'Chevrolet Cruze', 'Mazda 3'] # Ganti sesuai dataset def classify_car(image): image = image.resize((224, 224)) img_array = tf.keras.utils.img_to_array(image) / 255.0 img_array = np.expand_dims(img_array, axis=0) predictions = model.predict(img_array)[0] top_3 = np.argsort(predictions)[-3:][::-1] return {class_names[i]: float(predictions[i]) for i in top_3} interface = gr.Interface(fn=classify_car, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=3), title="Car Brand & Model Classifier", description="Upload a car image to predict the brand and model.") if __name__ == "__main__": interface.launch()