adding example ussage
Browse files- __pycache__/custom_resnet.cpython-310.pyc +0 -0
- app.py +15 -5
- data/fake/fake_1.jpeg +0 -0
- data/fake/fake_12.jpg +0 -0
- data/fake/fake_64.jpg +0 -0
- data/real/real_1.jpg +0 -0
- data/real/real_63.jpg +0 -0
__pycache__/custom_resnet.cpython-310.pyc
ADDED
Binary file (13.9 kB). View file
|
|
app.py
CHANGED
@@ -4,6 +4,7 @@ import torch.nn as nn
|
|
4 |
from torchvision import transforms
|
5 |
from PIL import Image
|
6 |
import time
|
|
|
7 |
|
8 |
from concrete.fhe import Configuration
|
9 |
from concrete.ml.torch.compile import compile_torch_model
|
@@ -37,6 +38,7 @@ def load_secure_model(model):
|
|
37 |
)
|
38 |
return secure_model
|
39 |
|
|
|
40 |
model = load_model('models/deepfake_detection_model.pth', 'cpu')
|
41 |
secure_model = load_secure_model(model)
|
42 |
|
@@ -72,19 +74,27 @@ def predict(image, mode):
|
|
72 |
predicted_class = class_names[preds[0]]
|
73 |
return f"Predicted: {predicted_class}", f"Time taken: {elapsed_time:.2f} seconds"
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# Gradio interface
|
76 |
iface = gr.Interface(
|
77 |
fn=predict,
|
78 |
inputs=[
|
79 |
-
gr.Image(type="filepath", label="Upload an Image"), #
|
80 |
-
gr.Radio(choices=["Fast", "Secure"], label="Inference Mode", value="Fast") #
|
81 |
],
|
82 |
outputs=[
|
83 |
-
gr.Textbox(label="Prediction"), #
|
84 |
-
gr.Textbox(label="Time Taken") #
|
85 |
],
|
|
|
86 |
title="Deepfake Detection Model",
|
87 |
-
description="Upload an image
|
88 |
)
|
89 |
|
90 |
if __name__ == "__main__":
|
|
|
4 |
from torchvision import transforms
|
5 |
from PIL import Image
|
6 |
import time
|
7 |
+
import os
|
8 |
|
9 |
from concrete.fhe import Configuration
|
10 |
from concrete.ml.torch.compile import compile_torch_model
|
|
|
38 |
)
|
39 |
return secure_model
|
40 |
|
41 |
+
# Load models
|
42 |
model = load_model('models/deepfake_detection_model.pth', 'cpu')
|
43 |
secure_model = load_secure_model(model)
|
44 |
|
|
|
74 |
predicted_class = class_names[preds[0]]
|
75 |
return f"Predicted: {predicted_class}", f"Time taken: {elapsed_time:.2f} seconds"
|
76 |
|
77 |
+
|
78 |
+
# Path to example images for "Fake" and "Real" classes
|
79 |
+
example_images = [
|
80 |
+
["data/fake/fake_1.jpeg", "Fast"], # Fake example
|
81 |
+
["data/real/real_1.jpg", "Fast"], # Real example
|
82 |
+
]
|
83 |
+
|
84 |
# Gradio interface
|
85 |
iface = gr.Interface(
|
86 |
fn=predict,
|
87 |
inputs=[
|
88 |
+
gr.Image(type="filepath", label="Upload an Image"), # Image input
|
89 |
+
gr.Radio(choices=["Fast", "Secure"], label="Inference Mode", value="Fast") # Inference mode
|
90 |
],
|
91 |
outputs=[
|
92 |
+
gr.Textbox(label="Prediction"), # Prediction output
|
93 |
+
gr.Textbox(label="Time Taken") # Time taken output
|
94 |
],
|
95 |
+
examples=example_images, # Add default examples for Fake and Real images
|
96 |
title="Deepfake Detection Model",
|
97 |
+
description="Upload an image or select a sample and choose the inference mode (Fast or Secure)."
|
98 |
)
|
99 |
|
100 |
if __name__ == "__main__":
|
data/fake/fake_1.jpeg
ADDED
data/fake/fake_12.jpg
ADDED
data/fake/fake_64.jpg
ADDED
data/real/real_1.jpg
ADDED
data/real/real_63.jpg
ADDED