Spaces:
Sleeping
Sleeping
Intial commit
Browse files- app.py +39 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the models
|
7 |
+
model1 = tf.keras.models.load_model('face_detection_model1.h5')
|
8 |
+
model2 = tf.keras.models.load_model('face_detection_model2.h5')
|
9 |
+
|
10 |
+
def preprocess_image(image):
|
11 |
+
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
12 |
+
img = img.resize((150, 150))
|
13 |
+
img_array = np.array(img) / 255.0
|
14 |
+
return np.expand_dims(img_array, axis=0)
|
15 |
+
|
16 |
+
def predict_image(image):
|
17 |
+
preprocessed_image = preprocess_image(image)
|
18 |
+
|
19 |
+
# Make predictions using both models
|
20 |
+
pred1 = model1.predict(preprocessed_image)[0][0]
|
21 |
+
pred2 = model2.predict(preprocessed_image)[0][0]
|
22 |
+
|
23 |
+
# Average the predictions
|
24 |
+
avg_pred = (pred1 + pred2) / 2
|
25 |
+
|
26 |
+
result = "Real" if avg_pred > 0.5 else "Fake"
|
27 |
+
confidence = avg_pred if avg_pred > 0.5 else 1 - avg_pred
|
28 |
+
|
29 |
+
return f"{result} (Confidence: {confidence:.2f})"
|
30 |
+
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=predict_image,
|
33 |
+
inputs=gr.Image(),
|
34 |
+
outputs="text",
|
35 |
+
title="Real vs Fake Face Detection",
|
36 |
+
description="Upload an image to determine if it's a real or fake face."
|
37 |
+
)
|
38 |
+
|
39 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow==2.9.1
|
2 |
+
gradio==3.32.0
|
3 |
+
Pillow==9.5.0
|
4 |
+
numpy==1.24.3
|