Spaces:
Sleeping
Sleeping
| import cv2 | |
| from tensorflow.keras.models import load_model | |
| import gradio as gr | |
| import tensorflow as tf | |
| import cv2 | |
| import numpy as np | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.models import load_model | |
| from tensorflow.keras.preprocessing import image | |
| import numpy as np | |
| # Load the trained model | |
| model = load_model('/content/cat_classifier_model.h5') | |
| # Function to predict whether an image contains a cat | |
| def predict_cat(image_content): | |
| # Convert image content to PIL Image | |
| img = Image.open(BytesIO(image_content)) | |
| img = img.convert('RGB') | |
| img = img.resize((224, 224)) | |
| img_array = np.array(img) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| img_array = img_array / 255.0 # Rescale to values between 0 and 1 (same as during training) | |
| prediction = model.predict(img_array) | |
| if prediction[0][0] > 0.5: | |
| return "not a tablet" | |
| else: | |
| return "is a tablet" | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_cat, | |
| inputs=gr.Image(type='file', label='Upload an image of a tablet'), | |
| outputs='text' | |
| ) | |
| # Launch the interface with share=True to create a public link | |
| iface.launch(share=True) | |