Ahmed235 commited on
Commit
07ade99
·
verified ·
1 Parent(s): 9585f42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -6
app.py CHANGED
@@ -2,7 +2,6 @@ from PIL import Image
2
  import tensorflow as tf
3
  import numpy as np
4
  import gradio as gr
5
- from tensorflow.keras.models import load_model
6
  import io
7
 
8
  # Load the model
@@ -23,11 +22,11 @@ def preprocess_image(image):
23
  def predict_image(image):
24
  # Save the image to a file-like object
25
  image_bytes = io.BytesIO()
26
- image.save(image_bytes, format="JPG")
27
  image_bytes.seek(0) # Reset file pointer to start
28
 
29
  # Load the image from the file-like object
30
- image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256))
31
 
32
  img_array = preprocess_image(image)
33
  outputs = model.predict(img_array)
@@ -42,10 +41,8 @@ def predict_image(image):
42
 
43
  return {"prediction": predicted_label}
44
 
45
- #return json.dumps(prediction_dict, indent=1)
46
-
47
  # Create the interface
48
- input_interface = gr.Image(type = "pil")
49
  iface = gr.Interface(
50
  fn=predict_image,
51
  inputs=input_interface,
 
2
  import tensorflow as tf
3
  import numpy as np
4
  import gradio as gr
 
5
  import io
6
 
7
  # Load the model
 
22
  def predict_image(image):
23
  # Save the image to a file-like object
24
  image_bytes = io.BytesIO()
25
+ image.save(image_bytes, format="JPEG") # Change "JPG" to "JPEG"
26
  image_bytes.seek(0) # Reset file pointer to start
27
 
28
  # Load the image from the file-like object
29
+ image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256), color_mode="rgb") # Specify color_mode="rgb"
30
 
31
  img_array = preprocess_image(image)
32
  outputs = model.predict(img_array)
 
41
 
42
  return {"prediction": predicted_label}
43
 
 
 
44
  # Create the interface
45
+ input_interface = gr.Image(type="pil")
46
  iface = gr.Interface(
47
  fn=predict_image,
48
  inputs=input_interface,