Download camera_functions.py from Bhargavitippareddy/wild_fire_detection: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/spaces/Bhargavitippareddy/wild_fire_detection/resolve/main/camera_functions.py
- Command line
-
hf download hf://spaces/Bhargavitippareddy/wild_fire_detection/camera_functions.py
-
curl -L -o camera_functions.py https://huggingface.co/spaces/Bhargavitippareddy/wild_fire_detection/resolve/main/camera_functions.py
758 Bytes
| import numpy as np | |
| from PIL import Image | |
| from io import BytesIO | |
| from tensorflow.keras.models import load_model | |
| # Load the model | |
| model_path = "analysis/wildfire_camera_detection_model.keras" | |
| model = load_model(model_path) | |
| # Function to preprocess the image before prediction | |
| def preprocess_image(img): | |
| img_resized = img.resize((224, 224)) | |
| img_array = np.array(img_resized) | |
| img_array = img_array / 255.0 | |
| return np.expand_dims(img_array, axis=0) | |
| # Function to predict wildfire probability using camera image | |
| def camera_cnn_predict(image_file): | |
| image = Image.open(BytesIO(image_file.read())).convert("RGB") | |
| preprocessed_image = preprocess_image(image) | |
| prediction = model.predict(preprocessed_image)[0][0] | |
| return prediction | |