courte commited on
Commit
86578bb
·
verified ·
1 Parent(s): 6cafd1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -8,9 +8,9 @@ model = tf.keras.models.load_model("car_brand_classifier_final.h5")
8
 
9
  # Define the preprocessing function
10
  def preprocess_image(image):
11
- if isinstance(image, str): # If image is a file path, open it
12
- image = Image.open(image)
13
-
14
  image = image.convert("RGB") # Ensure it's in RGB mode
15
  image = image.resize((299, 299)) # Resize to match model input size
16
  image = np.array(image) / 255.0 # Normalize pixel values
@@ -32,7 +32,7 @@ def predict(image):
32
  # Create the Gradio interface
33
  iface = gr.Interface(
34
  fn=predict,
35
- inputs="image",
36
  outputs="text",
37
  title="Car Vision",
38
  description="Upload an image of a car to classify its brand."
 
8
 
9
  # Define the preprocessing function
10
  def preprocess_image(image):
11
+ if isinstance(image, np.ndarray): # If Gradio gives a NumPy array, convert it to PIL Image
12
+ image = Image.fromarray(image)
13
+
14
  image = image.convert("RGB") # Ensure it's in RGB mode
15
  image = image.resize((299, 299)) # Resize to match model input size
16
  image = np.array(image) / 255.0 # Normalize pixel values
 
32
  # Create the Gradio interface
33
  iface = gr.Interface(
34
  fn=predict,
35
+ inputs=gr.Image(type="numpy"), # Ensure Gradio passes a NumPy array
36
  outputs="text",
37
  title="Car Vision",
38
  description="Upload an image of a car to classify its brand."