Spaces:
Sleeping
Sleeping
create the file
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load the model
|
7 |
+
model = load_model("hf_keras_model.keras")
|
8 |
+
class_names = ['buildings', 'forest', 'glacier', 'mountain', 'sea', 'street']
|
9 |
+
|
10 |
+
def predict_image(img):
|
11 |
+
img = img.resize((150, 150))
|
12 |
+
img_array = np.array(img) / 255.0
|
13 |
+
img_array = np.expand_dims(img_array, axis=0)
|
14 |
+
preds = model.predict(img_array)[0]
|
15 |
+
confidences = {class_names[i]: float(preds[i]) for i in range(6)}
|
16 |
+
return confidences
|
17 |
+
|
18 |
+
gr.Interface(
|
19 |
+
fn=predict_image,
|
20 |
+
inputs=gr.Image(type="pil"),
|
21 |
+
outputs=gr.Label(num_top_classes=3),
|
22 |
+
title="Intel Image Classifier",
|
23 |
+
description="Upload a landscape image and get predictions (buildings, forest, glacier, etc.)"
|
24 |
+
).launch()
|