sonuprasad commited on
Commit
311f9bc
1 Parent(s): 3928bba

Upload 2 files

Browse files
Files changed (2) hide show
  1. Hugging_Deepfake.py +36 -0
  2. requirements.txt +4 -0
Hugging_Deepfake.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tensorflow.keras.models import load_model
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load the model
7
+ model = load_model('./model.h5')
8
+
9
+ def detect_image(input_image):
10
+ img = Image.fromarray(input_image).resize((256, 256))
11
+ img_array = np.array(img) / 255.0
12
+ img_array = np.expand_dims(img_array, axis=0)
13
+
14
+ prediction = model.predict(img_array)[0][0]
15
+ probability_real = prediction * 100
16
+ probability_ai = (1 - prediction) * 100
17
+
18
+ if probability_real > probability_ai:
19
+ result = 'Input Image is Real'
20
+ confidence = probability_real
21
+ else:
22
+ result = 'Input Image is AI Generated'
23
+ confidence = probability_ai
24
+
25
+ return result, confidence
26
+
27
+ demo = gr.Interface(
28
+ fn=detect_image,
29
+ inputs=gr.Image(type="numpy", shape=(256, 256)),
30
+ outputs=[gr.Textbox(label="Result"), gr.Textbox(label="Confidence (%)")],
31
+ title="Deepfake Detection",
32
+ description="Upload an image to detect if it's real or AI generated."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ pillow
4
+ numpy