File size: 889 Bytes
2fb9583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()