Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
from tensorflow.keras.models import load_model | |
from PIL import Image | |
# Load the model | |
model = load_model("hf_keras_model.keras") | |
class_names = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street'] | |
def predict_image(img): | |
img = img.resize((150, 150)) | |
img_array = np.array(img) / 255.0 | |
img_array = np.expand_dims(img_array, axis=0) | |
preds = model.predict(img_array)[0] | |
confidences = {class_names[i]: float(preds[i]) for i in range(6)} | |
return confidences | |
gr.Interface( | |
fn=predict_image, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Label(num_top_classes=3), | |
title="Intel Image Classifier", | |
description="Upload a landscape image and get predictions (buildings, forest, glacier, etc.)" | |
).launch() | |