w-samik commited on
Commit
105adec
·
verified ·
1 Parent(s): bf20677

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +25 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load your model
7
+ model = tf.keras.models.load_model("disaster_mobilenet.keras")
8
+
9
+ # Your class names
10
+ CLASS_NAMES = ["collapsed_building", "fire", "flooded_areas", "normal", "traffic_incident"]
11
+
12
+ def predict(image):
13
+ # Preprocess
14
+ image = image.resize((96,96))
15
+ img_array = np.array(image)/255.0
16
+ img_array = np.expand_dims(img_array, 0) # batch
17
+
18
+ # Predict
19
+ preds = model.predict(img_array)
20
+ class_idx = np.argmax(preds[0])
21
+ return {CLASS_NAMES[i]: float(preds[0][i]) for i in range(len(CLASS_NAMES))}
22
+
23
+ # Gradio interface
24
+ iface = gr.Interface(fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Label())
25
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ pillow
4
+ numpy
5
+ python-multipart