File size: 1,058 Bytes
3facb92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from tensorflow.keras.models import load_model
from PIL import Image
import numpy as np

# Load the model
model = load_model('./model.h5')

def detect_image(input_image):
    img = Image.fromarray(input_image).resize((256, 256))
    img_array = np.array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)

    prediction = model.predict(img_array)[0][0]
    probability_real = prediction * 100
    probability_ai = (1 - prediction) * 100

    if probability_real > probability_ai:
        result = 'Input Image is Real'
        confidence = probability_real
    else:
        result = 'Input Image is AI Generated'
        confidence = probability_ai

    return result, confidence

demo = gr.Interface(
    fn=detect_image,
    inputs=gr.Image(type="numpy", shape=(256, 256)),
    outputs=[gr.Textbox(label="Result"), gr.Textbox(label="Confidence (%)")],
    title="Deepfake Detection",
    description="Upload an image to detect if it's real or AI generated."
)

# Deploy the interface on Gradio Hub
demo.launch(share=True)