Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# First, make sure you've installed required packages
|
| 2 |
+
# !pip install -U gradio transformers torch torchvision
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import requests
|
| 8 |
+
import torch
|
| 9 |
+
|
| 10 |
+
# Load the pipeline (auto-detects CUDA if available)
|
| 11 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 12 |
+
pipe = pipeline("image-classification", model="prithivMLmods/Deep-Fake-Detector-v2-Model", device=device)
|
| 13 |
+
|
| 14 |
+
def classify_image(image=None, url=None):
|
| 15 |
+
if image is None and not url:
|
| 16 |
+
return "Skill issue: You gave me nothing to work with."
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
if url:
|
| 20 |
+
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
| 21 |
+
elif image:
|
| 22 |
+
image = Image.fromarray(image).convert("RGB")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Bro... that ain't an image: {str(e)}"
|
| 25 |
+
|
| 26 |
+
result = pipe(image)
|
| 27 |
+
return {entry["label"]: round(entry["score"], 3) for entry in result}
|
| 28 |
+
|
| 29 |
+
# Set up the Gradio interface
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# 🔍 DeepFake Detector\nUpload an image or paste a URL. Let's see if you're being catfished.")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
image_input = gr.Image(type="numpy", label="Upload Image")
|
| 35 |
+
url_input = gr.Textbox(label="Or Enter Image URL")
|
| 36 |
+
|
| 37 |
+
submit_btn = gr.Button("🚨 Detect")
|
| 38 |
+
|
| 39 |
+
output = gr.Label(num_top_classes=2)
|
| 40 |
+
|
| 41 |
+
submit_btn.click(fn=classify_image, inputs=[image_input, url_input], outputs=output)
|
| 42 |
+
|
| 43 |
+
# Launch the app
|
| 44 |
+
demo.launch()
|