Spaces:
Sleeping
Sleeping
Download app.py from w-samik/Disaster_Detection: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/spaces/w-samik/Disaster_Detection/resolve/main/app.py
- Command line
-
hf download hf://spaces/w-samik/Disaster_Detection/app.py
-
curl -L -o app.py https://huggingface.co/spaces/w-samik/Disaster_Detection/resolve/main/app.py
758 Bytes
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Load your model | |
| model = tf.keras.models.load_model("disaster_mobilenet.keras") | |
| # Your class names | |
| CLASS_NAMES = ["collapsed_building", "fire", "flooded_areas", "normal", "traffic_incident"] | |
| def predict(image): | |
| # Preprocess | |
| image = image.resize((96,96)) | |
| img_array = np.array(image)/255.0 | |
| img_array = np.expand_dims(img_array, 0) # batch | |
| # Predict | |
| preds = model.predict(img_array) | |
| class_idx = np.argmax(preds[0]) | |
| return {CLASS_NAMES[i]: float(preds[0][i]) for i in range(len(CLASS_NAMES))} | |
| # Gradio interface | |
| iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label()) | |
| iface.launch() | |