import gradio as gr import tensorflow as tf from PIL import Image import numpy as np # Load the models model1 = tf.keras.models.load_model('face_detection_model1.h5') model2 = tf.keras.models.load_model('face_detection_model2.h5') def preprocess_image(image): img = Image.fromarray(image.astype('uint8'), 'RGB') img = img.resize((150, 150)) img_array = np.array(img) / 255.0 return np.expand_dims(img_array, axis=0) def predict_image(image): preprocessed_image = preprocess_image(image) # Make predictions using both models pred1 = model1.predict(preprocessed_image)[0][0] pred2 = model2.predict(preprocessed_image)[0][0] # Average the predictions avg_pred = (pred1 + pred2) / 2 result = "Real" if avg_pred > 0.5 else "Fake" confidence = avg_pred if avg_pred > 0.5 else 1 - avg_pred return f"{result} (Confidence: {confidence:.2f})" iface = gr.Interface( fn=predict_image, inputs=gr.Image(), outputs="text", title="Real vs Fake Face Detection", description="Upload an image to determine if it's a real or fake face." ) iface.launch()