Spaces:
Sleeping
Sleeping
File size: 758 Bytes
31d3a68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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()
|