Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| import cv2 | |
| def preprocess_image(image): | |
| image = cv2.resize(image, (224, 224)) # Resize to model input size | |
| image = image / 255.0 # Normalize to [0,1] range | |
| image = np.expand_dims(image, axis=0) # Add batch dimension | |
| return image | |
| # Load trained model | |
| model = tf.keras.models.load_model("xception_deepfake_image.h5") | |
| def predict_deepfake(image): | |
| image = preprocess_image(image) | |
| prediction = model.predict(image)[0][0] # Model outputs probability | |
| label = "FAKE" if prediction > 0.5 else "REAL" | |
| confidence = prediction if label == "FAKE" else 1 - prediction | |
| return {"REAL": float(1 - prediction), "FAKE": float(prediction)} | |
| # Create Gradio Interface | |
| demo = gr.Interface( | |
| fn=predict_deepfake, | |
| inputs=gr.Image(type="numpy"), | |
| outputs=gr.Label(num_top_classes=2), | |
| title="DeepFake Image Detector", | |
| description="Upload an image to check if it's REAL or FAKE", | |
| ) | |
| demo.launch() | |