HebaAllah commited on
Commit
3f19bd4
·
verified ·
1 Parent(s): 7b812ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load your pre-trained model
7
+ def load_model():
8
+ model = tf.keras.models.load_model('depi-graduation-project (1).ipynb') # Replace with your model's path
9
+ return model
10
+
11
+ model = load_model()
12
+
13
+ # Define the labels (categories)
14
+ labels = ['Water', 'Cloudy', 'Desert', 'Green Area']
15
+
16
+ # Function to preprocess the image and predict the class
17
+ def classify_image(image):
18
+ img = image.resize((128, 128)) # Resize the image
19
+ img = np.array(img) / 255.0 # Normalize the image
20
+ img = np.expand_dims(img, axis=0) # Add batch dimension
21
+ prediction = model.predict(img)
22
+ predicted_class = labels[np.argmax(prediction)]
23
+
24
+ # Prepare output with probabilities
25
+ return {labels[i]: float(prediction[0][i]) for i in range(len(labels))}
26
+
27
+ # Define the Gradio interface
28
+ image_input = gr.inputs.Image(shape=(128, 128))
29
+ label_output = gr.outputs.Label(num_top_classes=4)
30
+
31
+ # Launch the interface
32
+ gr.Interface(fn=classify_image,
33
+ inputs=image_input,
34
+ outputs=label_output,
35
+ title="Satellite Image Classification",
36
+ description="Classify satellite images into four types: Water, Cloudy, Desert, Green Area").launch()