CoolFace
Apppublic

got2kk/aaaa

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py40 linesDownload Raw Back to root
1from keras.models import load_model2from PIL import Image, ImageOps3import numpy as np4import gradio as gr5 6# Load the model7model = load_model("keras_model.h5", compile=False)8 9# Load class labels and remove newline characters10class_names = [class_name.strip() for class_name in open("labels.txt", "r").readlines()]11 12def greet(*images):13    results = []14 15    for img in images:16        data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)17 18        image = Image.fromarray(img).convert('RGB')19        size = (224, 224)20        image = ImageOps.fit(image, size, Image.ANTIALIAS)21 22        image_array = np.asarray(image)23        normalized_image_array = (image_array.astype(np.float32) / 127.0) - 124        data[0] = normalized_image_array25 26        prediction = model.predict(data)27 28        max_index = np.argmax(prediction)29        class_name = class_names[max_index]30 31        results.append(class_name)32 33    return results34 35# Update Gradio interface to accept multiple image inputs36demo = gr.Interface(fn=greet, inputs=["webcam"] * 3, outputs="text", live=True)37 38demo.launch(debug=True, share=True)39 40