Adding expecteted labels
Browse files
app.py
CHANGED
@@ -49,7 +49,7 @@ data_transform = transforms.Compose([
|
|
49 |
])
|
50 |
|
51 |
# Prediction function
|
52 |
-
def predict(image, mode):
|
53 |
device = 'cpu'
|
54 |
|
55 |
# Apply transformations to the input image
|
@@ -72,13 +72,18 @@ def predict(image, mode):
|
|
72 |
elapsed_time = time.time() - start_time
|
73 |
|
74 |
predicted_class = class_names[preds[0]]
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
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
|
@@ -86,15 +91,20 @@ 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=
|
|
|
|
|
|
|
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__":
|
|
|
49 |
])
|
50 |
|
51 |
# Prediction function
|
52 |
+
def predict(image, mode, expected_output=None):
|
53 |
device = 'cpu'
|
54 |
|
55 |
# Apply transformations to the input image
|
|
|
72 |
elapsed_time = time.time() - start_time
|
73 |
|
74 |
predicted_class = class_names[preds[0]]
|
75 |
+
|
76 |
+
# Compare predicted and expected output
|
77 |
+
expected_output_message = f"Expected: {expected_output}" if expected_output else "Expected: Not Provided"
|
78 |
+
predicted_output_message = f"Predicted: {predicted_class}"
|
79 |
+
|
80 |
+
return predicted_output_message, expected_output_message, f"Time taken: {elapsed_time:.2f} seconds"
|
81 |
|
82 |
|
83 |
+
# Path to example images for "Fake" and "Real" classes along with expected outputs
|
84 |
example_images = [
|
85 |
+
["./data/fake/fake_1.jpeg", "Fake", "Fast"], # Fake example
|
86 |
+
["./data/real/real_1.jpg", "Real", "Fast"], # Real example
|
87 |
]
|
88 |
|
89 |
# Gradio interface
|
|
|
91 |
fn=predict,
|
92 |
inputs=[
|
93 |
gr.Image(type="filepath", label="Upload an Image"), # Image input
|
94 |
+
gr.Radio(choices=["Fast", "Secure"], label="Inference Mode", value="Fast"), # Inference mode
|
95 |
+
gr.Textbox(label="Expected Output", value=None, placeholder="Optional: Enter expected output (Fake/Real)") # Expected output (optional)
|
96 |
],
|
97 |
outputs=[
|
98 |
gr.Textbox(label="Prediction"), # Prediction output
|
99 |
+
gr.Textbox(label="Expected Output"), # Expected output for comparison
|
100 |
gr.Textbox(label="Time Taken") # Time taken output
|
101 |
],
|
102 |
+
examples=[ # Include expected outputs in examples
|
103 |
+
["./data/fake/fake_1.jpeg", "Fast", "Fake"], # Fake example with expected output
|
104 |
+
["./data/real/real_1.jpg", "Fast", "Real"], # Real example with expected output
|
105 |
+
],
|
106 |
title="Deepfake Detection Model",
|
107 |
+
description="Upload an image or select a sample and choose the inference mode (Fast or Secure). Compare the predicted result with the expected output."
|
108 |
)
|
109 |
|
110 |
if __name__ == "__main__":
|