Sid26Roy commited on
Commit
8234152
·
verified ·
1 Parent(s): aa1a670

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ import os
6
+
7
+ # Load the trained model
8
+ model = tf.keras.models.load_model("eff_model.h5")
9
+
10
+ # Same normalization you used in training
11
+ def preprocess_image(image: Image.Image):
12
+ image = image.resize((512, 512)).convert("RGB")
13
+ image = np.array(image).astype(np.float32) / 255.0
14
+
15
+ mean = np.array([0.44101639, 0.45513914, 0.40195001])
16
+ std = np.array([0.28792392, 0.29775171, 0.29840153])
17
+
18
+ image = (image - mean) / std
19
+ image = np.expand_dims(image, axis=0) # Add batch dimension
20
+ return image
21
+
22
+ def predict(image: Image.Image):
23
+ processed = preprocess_image(image)
24
+ prediction = model.predict(processed)[0][0] # sigmoid output
25
+
26
+ label = "🌋 Volcanic Eruption" if prediction > 0.5 else "✅ No Eruption"
27
+ confidence = f"{prediction:.2%}" if prediction > 0.5 else f"{(1 - prediction):.2%}"
28
+ return f"{label} (Confidence: {confidence})"
29
+
30
+ # Gradio Interface
31
+ interface = gr.Interface(
32
+ fn=predict,
33
+ inputs=gr.Image(type="pil", label="Upload Satellite Image"),
34
+ outputs=gr.Textbox(label="Prediction"),
35
+ title="Volcanic Eruption Detection",
36
+ description="Upload a satellite image to detect a volcanic eruption using EfficientNetB7."
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ interface.launch()