Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
img_array = np.expand_dims(img_array, axis=0)
|
19 |
-
img_array
|
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=
|
30 |
-
inputs=gr.Image(),
|
31 |
-
outputs=
|
32 |
-
live=True,
|
33 |
-
|
34 |
)
|
35 |
|
36 |
-
# Launch the
|
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 |
|