Spaces:
Sleeping
Sleeping
File size: 1,129 Bytes
9aac0c5 2b3c229 9aac0c5 2b3c229 9aac0c5 2b3c229 9aac0c5 |
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 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
from huggingface_hub import from_pretrained_keras
import tensorflow as tf
import numpy as np
# Load models from Hugging Face Hub
model1 = from_pretrained_keras("arsath-sm/real-fake-face-detection-model1")
model2 = from_pretrained_keras("arsath-sm/real-fake-face-detection-model2")
def preprocess_image(image):
img = tf.image.resize(image, (150, 150))
img = img / 255.0
return tf.expand_dims(img, 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() |