Spaces:
Runtime error
Runtime error
Download app.py from seanerons/dress_code_detection: direct link, hf CLI and curl.
- Browser
- Download file 889 Bytes
-
https://huggingface.co/spaces/seanerons/dress_code_detection/resolve/main/app.py
- Command line
-
hf download hf://spaces/seanerons/dress_code_detection/app.py
-
curl -L -o app.py https://huggingface.co/spaces/seanerons/dress_code_detection/resolve/main/app.py
889 Bytes
| import gradio as gr | |
| import tensorflow as tf | |
| import tensorflow_hub as hub | |
| import numpy as np | |
| model = tf.keras.models.load_model("model.h5", custom_objects={'KerasLayer': hub.KerasLayer}) | |
| class_names = ['in dress code', 'not in dress code'] | |
| IMG_SIZE = 224 | |
| def preprocess_image(image): | |
| image = tf.convert_to_tensor(image, dtype=tf.float32) | |
| image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE)) / 255.0 | |
| return tf.expand_dims(image, axis=0) | |
| def predict_dress_code(image): | |
| processed = preprocess_image(image) | |
| preds = model.predict(processed) | |
| label = class_names[np.argmax(preds)] | |
| confidence = float(np.max(preds)) | |
| return f"{label} ({confidence:.2f})" | |
| iface = gr.Interface(fn=predict_dress_code, | |
| inputs=gr.Image(type="numpy"), | |
| outputs="text", | |
| title="Dress Code Violation Detector") | |
| iface.launch() | |