File size: 939 Bytes
11abef1
 
 
2295c8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
import tensorflow as tf
print("TensorFlow is installed:", tf.__version__)

import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load trained model
model = tf.keras.models.load_model("eurosat_cnn_model.h5")

# Define class labels
class_labels = [
    "AnnualCrop", "Forest", "Highway", "Industrial", "Pasture",
    "PermanentCrop", "Residential", "River", "SeaLake", "HerbaceousVegetation"
]

# Function to process image and make predictions
def predict_image(image):
    image = image.resize((64, 64))  # Resize image
    img_array = np.array(image) / 255.0  # Normalize
    img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension
    
    prediction = model.predict(img_array)  # Predict
    return {class_labels[i]: float(prediction[0][i]) for i in range(len(class_labels))}

# Create Gradio Interface
iface = gr.Interface(fn=predict_image, inputs="image", outputs="label")
iface.launch()