Sonu Prasad
commited on
Update Hugging_Deepfake.py
Browse files- Hugging_Deepfake.py +36 -36
Hugging_Deepfake.py
CHANGED
|
@@ -1,36 +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 |
-
|
| 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 |
+
# Deploy the interface on Gradio Hub
|
| 36 |
+
demo.launch(share=True)
|