Spaces:
Sleeping
Sleeping
File size: 3,200 Bytes
325d9cd 7dbd0ae 4d27d80 f044415 4d27d80 f8077ca 4d27d80 6d89dc3 4d27d80 f044415 4d27d80 f8077ca 325d9cd 4d27d80 325d9cd 4d27d80 7dbd0ae 4d27d80 325d9cd f8077ca 7dbd0ae 4d27d80 325d9cd 4d27d80 325d9cd 4d27d80 325d9cd 4d27d80 2c91647 f8077ca 325d9cd 6d89dc3 4d27d80 6d89dc3 4d27d80 6d89dc3 4d27d80 f044415 325d9cd f044415 325d9cd 4d27d80 325d9cd 4d27d80 325d9cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | import gradio as gr
from transformers import pipeline
import torch
# Initialize the deepfake detection pipeline
print("Loading Jerry's detection system...")
pipe = pipeline(
"image-classification",
model="prithivMLmods/Deep-Fake-Detector-v2-Model",
device=0 if torch.cuda.is_available() else -1
)
print("Jerry is ready!")
def detect_deepfake(image):
"""
Analyze an image to detect if it's a deepfake
"""
if image is None:
return "Please upload an image first!"
# Get predictions from the model
results = pipe(image)
# Format the results
output_text = "π **Jerry's Analysis Results:**\n\n"
for result in results:
label = result['label']
confidence = result['score'] * 100
# Create a visual confidence bar
bar_length = int(confidence / 5)
bar = "β" * bar_length + "β" * (20 - bar_length)
output_text += f"**{label}**: {confidence:.2f}%\n"
output_text += f"{bar}\n\n"
# Add a conclusion
top_result = results[0]
if top_result['score'] > 0.7:
certainty = "high"
elif top_result['score'] > 0.5:
certainty = "moderate"
else:
certainty = "low"
output_text += f"\nπ― **Jerry's Verdict:** {top_result['label']} (with {certainty} confidence)"
return output_text
# Create the Gradio interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown(
"""
# π΅οΈ Jerry - Deepfake Detector
### Your AI-Powered Image Authenticity Analyzer
Upload an image and let Jerry analyze it to determine if it's authentic or artificially generated!
"""
)
with gr.Row():
with gr.Column(scale=1):
image_input = gr.Image(
label="Upload Image for Analysis",
type="pil",
height=400
)
analyze_btn = gr.Button(
"π Analyze with Jerry",
variant="primary",
size="lg"
)
with gr.Column(scale=1):
output_text = gr.Markdown(
label="Detection Results",
value="Upload an image and click 'Analyze with Jerry' to begin!"
)
gr.Markdown(
"""
---
### π‘ Tips for Best Results:
- Upload clear, high-quality images
- Works best with photos of faces or people
- Supports common image formats (JPG, PNG, etc.)
### β οΈ Important Note:
Jerry provides analysis based on AI detection patterns. Results should be used as guidance, not absolute proof.
"""
)
# Connect the button to the function
analyze_btn.click(
fn=detect_deepfake,
inputs=image_input,
outputs=output_text
)
# Also allow Enter key or automatic analysis
image_input.change(
fn=detect_deepfake,
inputs=image_input,
outputs=output_text
)
# Launch the app
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False
) |