Ahmed235 commited on
Commit
f17fbd4
1 Parent(s): 60fa5fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -5,30 +5,19 @@ import gradio as gr
5
  import io
6
 
7
  # Load the model
8
- model_path = 'dentist/final_teath_classifier.h5'
9
  model = tf.keras.models.load_model(model_path)
10
-
11
- # Define preprocessing function
12
- def preprocess_image(image):
13
- # Resize the image to match input size
14
- image = image.resize((256, 256))
15
- # Convert image to array and preprocess input
16
- img_array = np.array(image) / 255.0
17
- # Add batch dimension
18
- img_array = np.expand_dims(img_array, axis=0)
19
- return img_array
20
-
21
  # Define prediction function
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)
33
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
34
  predicted_class_index = np.argmax(predictions)
 
5
  import io
6
 
7
  # Load the model
8
+ model_path = 'final_teath_classifier.h5'
9
  model = tf.keras.models.load_model(model_path)
 
 
 
 
 
 
 
 
 
 
 
10
  # Define prediction function
11
  def predict_image(image):
12
  # Save the image to a file-like object
13
  image_bytes = io.BytesIO()
14
  image.save(image_bytes, format="JPEG") # Change "JPG" to "JPEG"
15
  image_bytes.seek(0) # Reset file pointer to start
 
16
  # Load the image from the file-like object
17
  image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256), color_mode="rgb") # Specify color_mode="rgb"
18
+ #image = image.resize((256, 256))
19
+ img_array = np.array(image) / 255.0
20
+ img_array = np.expand_dims(img_array, axis=0)
21
  outputs = model.predict(img_array)
22
  predictions = tf.nn.softmax(outputs.logits, axis=-1)
23
  predicted_class_index = np.argmax(predictions)