Spaces:
Sleeping
Sleeping
| 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() | |