Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import tensorflow_hub as hub
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
model = tf.keras.models.load_model("model.h5", custom_objects={'KerasLayer': hub.KerasLayer})
|
| 7 |
+
class_names = ['in dress code', 'not in dress code']
|
| 8 |
+
IMG_SIZE = 224
|
| 9 |
+
|
| 10 |
+
def preprocess_image(image):
|
| 11 |
+
image = tf.convert_to_tensor(image, dtype=tf.float32)
|
| 12 |
+
image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE)) / 255.0
|
| 13 |
+
return tf.expand_dims(image, axis=0)
|
| 14 |
+
|
| 15 |
+
def predict_dress_code(image):
|
| 16 |
+
processed = preprocess_image(image)
|
| 17 |
+
preds = model.predict(processed)
|
| 18 |
+
label = class_names[np.argmax(preds)]
|
| 19 |
+
confidence = float(np.max(preds))
|
| 20 |
+
return f"{label} ({confidence:.2f})"
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(fn=predict_dress_code,
|
| 23 |
+
inputs=gr.Image(type="numpy"),
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="Dress Code Violation Detector")
|
| 26 |
+
|
| 27 |
+
iface.launch()
|