Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import tensorflow as tf
|
| 4 |
+
from tensorflow import keras
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
siamese = keras.models.load_model("siamese_model.keras")
|
| 8 |
+
|
| 9 |
+
# Load stored images for comparison
|
| 10 |
+
stored_images = [
|
| 11 |
+
np.load("mun_image.npy"), # Preprocessed image of Munzali
|
| 12 |
+
np.load("bas_image.npy"), # Preprocessed image of Bash
|
| 13 |
+
np.load("usa_image.npy"), # Preprocessed image of Usama
|
| 14 |
+
]
|
| 15 |
+
stored_imgs = [np.expand_dims(img, axis=0) for img in stored_images]
|
| 16 |
+
|
| 17 |
+
# Inference function
|
| 18 |
+
def check_membership(uploaded_image):
|
| 19 |
+
uploaded_image = np.expand_dims(uploaded_image, axis=0)
|
| 20 |
+
predictions = [siamese.predict([uploaded_image, img])[0][0] for img in stored_imgs]
|
| 21 |
+
if predictions[0] < 0.5:
|
| 22 |
+
return "You are welcome Munzali"
|
| 23 |
+
elif predictions[1] < 0.5:
|
| 24 |
+
return "You are welcome Ahmad"
|
| 25 |
+
elif predictions[2] < 0.5:
|
| 26 |
+
return "You are welcome Usama"
|
| 27 |
+
else:
|
| 28 |
+
return "You are not a member"
|
| 29 |
+
|
| 30 |
+
# Gradio interface
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=check_membership,
|
| 33 |
+
inputs=gr.Image(shape=(160, 160)),
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Siamese Network Membership Check",
|
| 36 |
+
description="Upload an image to check if you are a member.",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
iface.launch()
|