Spaces:
Runtime error
Runtime error
Upload 2 files
Browse filesinitial commits
- app.py +31 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2
|
| 5 |
+
|
| 6 |
+
def preprocess_image(image):
|
| 7 |
+
image = cv2.resize(image, (224, 224)) # Resize to model input size
|
| 8 |
+
image = image / 255.0 # Normalize to [0,1] range
|
| 9 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
| 10 |
+
return image
|
| 11 |
+
|
| 12 |
+
# Load trained model
|
| 13 |
+
model = tf.keras.models.load_model("xception_deepfake_image.h5")
|
| 14 |
+
|
| 15 |
+
def predict_deepfake(image):
|
| 16 |
+
image = preprocess_image(image)
|
| 17 |
+
prediction = model.predict(image)[0][0] # Model outputs probability
|
| 18 |
+
label = "FAKE" if prediction > 0.5 else "REAL"
|
| 19 |
+
confidence = prediction if label == "FAKE" else 1 - prediction
|
| 20 |
+
return {"REAL": float(1 - prediction), "FAKE": float(prediction)}
|
| 21 |
+
|
| 22 |
+
# Create Gradio Interface
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=predict_deepfake,
|
| 25 |
+
inputs=gr.Image(type="numpy"),
|
| 26 |
+
outputs=gr.Label(num_top_classes=2),
|
| 27 |
+
title="DeepFake Image Detector",
|
| 28 |
+
description="Upload an image to check if it's REAL or FAKE",
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch()
|
requirements.txt
ADDED
|
File without changes
|