update
Browse files
app.py
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load trained model
|
| 7 |
+
model = tf.keras.models.load_model("eurosat_cnn_model.h5")
|
| 8 |
+
|
| 9 |
+
# Define class labels
|
| 10 |
+
class_labels = [
|
| 11 |
+
"AnnualCrop", "Forest", "Highway", "Industrial", "Pasture",
|
| 12 |
+
"PermanentCrop", "Residential", "River", "SeaLake", "HerbaceousVegetation"
|
| 13 |
+
]
|
| 14 |
+
|
| 15 |
+
# Function to process image and make predictions
|
| 16 |
+
def predict_image(image):
|
| 17 |
+
image = image.resize((64, 64)) # Resize image
|
| 18 |
+
img_array = np.array(image) / 255.0 # Normalize
|
| 19 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
| 20 |
+
|
| 21 |
+
prediction = model.predict(img_array) # Predict
|
| 22 |
+
return {class_labels[i]: float(prediction[0][i]) for i in range(len(class_labels))}
|
| 23 |
+
|
| 24 |
+
# Create Gradio Interface
|
| 25 |
+
iface = gr.Interface(fn=predict_image, inputs="image", outputs="label")
|
| 26 |
+
iface.launch()
|