courte commited on
Commit
42089b6
·
verified ·
1 Parent(s): c0609dc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ from PIL import Image
4
+ import gradio as gr
5
+
6
+ # Load the Keras model
7
+ model = tf.keras.models.load_model("car_brand_classifier_final.h5")
8
+
9
+ # Define the preprocessing function
10
+ def preprocess_image(image):
11
+ image = image.resize((299, 299)) # Resize to match model input size
12
+ image = np.array(image) / 255.0 # Normalize pixel values
13
+ image = np.expand_dims(image, axis=0) # Add batch dimension
14
+ return image
15
+
16
+ # Define the prediction function
17
+ def predict(image):
18
+ # Preprocess the image
19
+ processed_image = preprocess_image(image)
20
+
21
+ # Make a prediction
22
+ predictions = model.predict(processed_image)
23
+ predicted_class = np.argmax(predictions, axis=1)[0]
24
+
25
+ # Return the result
26
+ return f"Predicted class: {predicted_class}"
27
+
28
+ # Create the Gradio interface
29
+ iface = gr.Interface(
30
+ fn=predict,
31
+ inputs="image",
32
+ outputs="text",
33
+ title="Car Vision",
34
+ description="Upload an image of a car to classify its brand."
35
+ )
36
+
37
+ # Launch the app
38
+ iface.launch()