wizzseen commited on
Commit
19287b5
1 Parent(s): 0d37720

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -9,14 +9,19 @@ from tensorflow.keras.models import load_model
9
  from tensorflow.keras.preprocessing import image
10
  import numpy as np
11
 
12
- # Load the pre-trained model
13
- new_model = load_model('cat_classifier_model.h5')
14
 
15
- def classify_image(image_path):
16
- img = image.load_img(image_path, target_size=(224, 224))
17
- img_array = image.img_to_array(img)
 
 
 
 
 
18
  img_array = np.expand_dims(img_array, axis=0)
19
- img_array /= 255.0 # Rescale to values between 0 and 1 (same as during training)
20
 
21
  prediction = model.predict(img_array)
22
  if prediction[0][0] > 0.5:
@@ -26,15 +31,13 @@ def classify_image(image_path):
26
 
27
  # Create a Gradio interface
28
  iface = gr.Interface(
29
- fn=classify_image,
30
- inputs=gr.Image(),
31
- outputs="text",
32
- live=True,
33
-
34
  )
35
 
36
- # Launch the Gradio interface
37
- iface.launch()
38
 
39
 
40
 
 
9
  from tensorflow.keras.preprocessing import image
10
  import numpy as np
11
 
12
+ # Load the trained model
13
+ model = load_model('/content/cat_classifier_model.h5')
14
 
15
+ # Function to predict whether an image contains a cat
16
+ def predict_cat(image_content):
17
+ # Convert image content to PIL Image
18
+ img = Image.open(BytesIO(image_content))
19
+ img = img.convert('RGB')
20
+ img = img.resize((224, 224))
21
+
22
+ img_array = np.array(img)
23
  img_array = np.expand_dims(img_array, axis=0)
24
+ img_array = img_array / 255.0 # Rescale to values between 0 and 1 (same as during training)
25
 
26
  prediction = model.predict(img_array)
27
  if prediction[0][0] > 0.5:
 
31
 
32
  # Create a Gradio interface
33
  iface = gr.Interface(
34
+ fn=predict_cat,
35
+ inputs=gr.Image(type='file', label='Upload an image of a tablet'),
36
+ outputs='text'
 
 
37
  )
38
 
39
+ # Launch the interface with share=True to create a public link
40
+ iface.launch(share=True)
41
 
42
 
43