Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- README.md +2 -8
- app.py +36 -0
- mymodel.h5 +3 -0
- requirements.txt +0 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.27.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Image_Classifier_
|
| 3 |
+
app_file: app.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 4.27.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load the saved model
|
| 7 |
+
model = tf.keras.models.load_model('mymodel.h5')
|
| 8 |
+
|
| 9 |
+
# Define the labels
|
| 10 |
+
labels = ['Buildings', 'Forest', 'Sea']
|
| 11 |
+
|
| 12 |
+
# Define the image classification function
|
| 13 |
+
def classify_image(image):
|
| 14 |
+
# Preprocess the image
|
| 15 |
+
image = np.array(image)
|
| 16 |
+
image = tf.image.resize(image, (128, 128)) # Resize the image to match the input size of the model
|
| 17 |
+
image = tf.expand_dims(image, axis=0) # Add batch dimension
|
| 18 |
+
image = tf.keras.applications.resnet50.preprocess_input(image)
|
| 19 |
+
|
| 20 |
+
# Predict the class
|
| 21 |
+
predictions = model.predict(image).flatten()
|
| 22 |
+
|
| 23 |
+
# Get the predicted class label
|
| 24 |
+
predicted_class = labels[np.argmax(predictions)]
|
| 25 |
+
|
| 26 |
+
return predicted_class
|
| 27 |
+
|
| 28 |
+
# Define the Gradio interface
|
| 29 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
| 30 |
+
label_output = gr.Label()
|
| 31 |
+
|
| 32 |
+
# Create the Gradio interface
|
| 33 |
+
interface = gr.Interface(fn=classify_image, inputs=image_input, outputs=label_output, title="Image Classifier")
|
| 34 |
+
|
| 35 |
+
# Launch the interface
|
| 36 |
+
interface.launch()
|
mymodel.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7b080e26296e770721783f7029b33af1e9c90174c80decc599e2ad9e99103dcf
|
| 3 |
+
size 39713120
|
requirements.txt
ADDED
|
Binary file (4.89 kB). View file
|
|
|