Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load model
|
| 7 |
+
model = tf.keras.models.load_model("model/car_model.h5")
|
| 8 |
+
class_names = ['Audi A4', 'Toyota Corolla', 'BMW X5', 'Ford Focus', 'Honda Civic',
|
| 9 |
+
'Hyundai Elantra', 'Mercedes C Class', 'Kia Sportage', 'Chevrolet Cruze', 'Mazda 3'] # Ganti sesuai dataset
|
| 10 |
+
|
| 11 |
+
def classify_car(image):
|
| 12 |
+
image = image.resize((224, 224))
|
| 13 |
+
img_array = tf.keras.utils.img_to_array(image) / 255.0
|
| 14 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 15 |
+
predictions = model.predict(img_array)[0]
|
| 16 |
+
top_3 = np.argsort(predictions)[-3:][::-1]
|
| 17 |
+
return {class_names[i]: float(predictions[i]) for i in top_3}
|
| 18 |
+
|
| 19 |
+
interface = gr.Interface(fn=classify_car,
|
| 20 |
+
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs=gr.Label(num_top_classes=3),
|
| 22 |
+
title="Car Brand & Model Classifier",
|
| 23 |
+
description="Upload a car image to predict the brand and model.")
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
interface.launch()
|