Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,11 +9,11 @@ logging.basicConfig(level=logging.INFO)
|
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
# Load the model and processor from Hugging Face
|
| 12 |
-
model = ViTForImageClassification.from_pretrained("
|
| 13 |
-
processor = ViTImageProcessor.from_pretrained("
|
| 14 |
|
| 15 |
-
def detect(image, confidence_threshold=0.
|
| 16 |
-
"""Detect deepfake content
|
| 17 |
if image is None:
|
| 18 |
raise gr.Error("Please upload an image to analyze")
|
| 19 |
|
|
@@ -21,7 +21,7 @@ def detect(image, confidence_threshold=0.7):
|
|
| 21 |
# Convert Gradio image (filepath) to PIL Image
|
| 22 |
pil_image = Image.open(image).convert("RGB")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
pil_image = pil_image.resize((224, 224), Image.Resampling.LANCZOS)
|
| 26 |
|
| 27 |
# Preprocess the image
|
|
@@ -97,17 +97,18 @@ MARKDOWN0 = """
|
|
| 97 |
<div class="header">
|
| 98 |
<h1>DeepFake Detection System</h1>
|
| 99 |
<p>Advanced AI-powered analysis for identifying manipulated media<br>
|
| 100 |
-
Powered by
|
| 101 |
-
|
| 102 |
</div>
|
| 103 |
"""
|
| 104 |
|
| 105 |
-
# Create Gradio interface
|
| 106 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
| 107 |
gr.Markdown(MARKDOWN0)
|
| 108 |
with gr.Row(elem_classes="container"):
|
| 109 |
with gr.Column(scale=1):
|
| 110 |
image = gr.Image(type='filepath', height=400, label="Upload Image")
|
|
|
|
| 111 |
detect_button = gr.Button("Analyze Image", elem_classes="button-gradient")
|
| 112 |
with gr.Column(scale=2):
|
| 113 |
overall = gr.Label(label="Confidence Score")
|
|
@@ -116,11 +117,11 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
| 116 |
|
| 117 |
detect_button.click(
|
| 118 |
fn=detect,
|
| 119 |
-
inputs=[image],
|
| 120 |
outputs=[overall, aigen, deepfake]
|
| 121 |
)
|
| 122 |
|
| 123 |
# Launch the application
|
| 124 |
demo.launch(
|
| 125 |
debug=True
|
| 126 |
-
)
|
|
|
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
# Load the model and processor from Hugging Face
|
| 12 |
+
model = ViTForImageClassification.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
| 13 |
+
processor = ViTImageProcessor.from_pretrained("prithivMLmods/Deep-Fake-Detector-Model")
|
| 14 |
|
| 15 |
+
def detect(image, confidence_threshold=0.5):
|
| 16 |
+
"""Detect deepfake content using prithivMLmods/Deep-Fake-Detector-Model"""
|
| 17 |
if image is None:
|
| 18 |
raise gr.Error("Please upload an image to analyze")
|
| 19 |
|
|
|
|
| 21 |
# Convert Gradio image (filepath) to PIL Image
|
| 22 |
pil_image = Image.open(image).convert("RGB")
|
| 23 |
|
| 24 |
+
# Resize to match ViT input requirements (224x224)
|
| 25 |
pil_image = pil_image.resize((224, 224), Image.Resampling.LANCZOS)
|
| 26 |
|
| 27 |
# Preprocess the image
|
|
|
|
| 97 |
<div class="header">
|
| 98 |
<h1>DeepFake Detection System</h1>
|
| 99 |
<p>Advanced AI-powered analysis for identifying manipulated media<br>
|
| 100 |
+
Powered by prithivMLmods/Deep-Fake-Detector-Model (Updated Jan 2025)<br>
|
| 101 |
+
Adjustable threshold for tuning detection sensitivity</p>
|
| 102 |
</div>
|
| 103 |
"""
|
| 104 |
|
| 105 |
+
# Create Gradio interface with threshold slider
|
| 106 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
| 107 |
gr.Markdown(MARKDOWN0)
|
| 108 |
with gr.Row(elem_classes="container"):
|
| 109 |
with gr.Column(scale=1):
|
| 110 |
image = gr.Image(type='filepath', height=400, label="Upload Image")
|
| 111 |
+
threshold = gr.Slider(0, 1, value=0.5, step=0.01, label="Confidence Threshold (Fake)")
|
| 112 |
detect_button = gr.Button("Analyze Image", elem_classes="button-gradient")
|
| 113 |
with gr.Column(scale=2):
|
| 114 |
overall = gr.Label(label="Confidence Score")
|
|
|
|
| 117 |
|
| 118 |
detect_button.click(
|
| 119 |
fn=detect,
|
| 120 |
+
inputs=[image, threshold],
|
| 121 |
outputs=[overall, aigen, deepfake]
|
| 122 |
)
|
| 123 |
|
| 124 |
# Launch the application
|
| 125 |
demo.launch(
|
| 126 |
debug=True
|
| 127 |
+
)
|