CodeRafay commited on
Commit
b4c0acb
ยท
verified ยท
1 Parent(s): c7f63d8

deploy space gradio

Browse files
Files changed (3) hide show
  1. README.md +12 -9
  2. app.py +58 -0
  3. requirements.txt +1 -0
README.md CHANGED
@@ -1,15 +1,18 @@
1
  ---
2
- title: Deepfake Detect
3
- emoji: ๐Ÿ‘
4
- colorFrom: blue
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 6.30.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
11
  license: mit
12
- short_description: Open-source face deepfake detector for images and videos.
 
 
13
  ---
14
 
15
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
1
  ---
2
+ title: deepfake-detect
3
+ emoji: ๐Ÿ”
4
+ colorFrom: gray
5
+ colorTo: red
6
  sdk: gradio
7
+ sdk_version: 5.49.1
 
8
  app_file: app.py
 
9
  license: mit
10
+ models:
11
+ - CodeRafay/deepfake-detect
12
+ short_description: Detect face deepfakes in images and videos
13
  ---
14
 
15
+ Upload an image or video to get a fake score per face, with a per-frame chart for videos.
16
+ It uses the latest model from [CodeRafay/deepfake-detect](https://huggingface.co/CodeRafay/deepfake-detect): unseen-dataset (Celeb-DF v2) AUC 0.914.
17
+
18
+ **A score is evidence, not proof.** The model is for research use only. Code and full write-up: https://github.com/CodeRafay/deepfake-detect
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Hugging Face Space (Gradio + ZeroGPU). For local use, the Streamlit app is deepfake_detect/app.py."""
2
+ import gradio as gr
3
+ import pandas as pd
4
+ import spaces
5
+
6
+ from deepfake_detect import Detector
7
+ from deepfake_detect.faces import draw_faces
8
+
9
+ # ZeroGPU: load once onto "cuda" at startup; a real GPU is attached only while a @spaces.GPU function runs
10
+ det = Detector(device="cuda")
11
+
12
+ ABOUT = """# deepfake-detect
13
+ Upload an image or a video. Every face is scored by a CLIP ViT-L/14 with tuned LayerNorms
14
+ ([model](https://huggingface.co/CodeRafay/deepfake-detect): 0.914 AUC on unseen Celeb-DF v2).
15
+ **A score is evidence, not proof.** Compression, lighting and new kinds of fakes all shift it.
16
+ Don't make decisions about people based on this alone. [Code and write-up](https://github.com/CodeRafay/deepfake-detect)"""
17
+
18
+
19
+ def verdict(r):
20
+ return {"fake": r["score"], "real": 1 - r["score"]}
21
+
22
+
23
+ @spaces.GPU(duration=60)
24
+ def scan_image(rgb):
25
+ if rgb is None:
26
+ return None, None, None
27
+ r = det.predict_image(rgb)
28
+ return verdict(r), draw_faces(rgb, r), r
29
+
30
+
31
+ @spaces.GPU(duration=120)
32
+ def scan_video(path):
33
+ if path is None:
34
+ return None, None, None
35
+ r = det.predict_video(path)
36
+ return verdict(r), pd.DataFrame(r["frames"]), r
37
+
38
+
39
+ with gr.Blocks(title="deepfake-detect") as demo:
40
+ gr.Markdown(ABOUT)
41
+ with gr.Tab("Image"):
42
+ with gr.Row():
43
+ img = gr.Image(type="numpy", label="Image")
44
+ with gr.Column():
45
+ img_label = gr.Label(label="Verdict")
46
+ img_out = gr.Image(label="Faces (red = above threshold)")
47
+ img_json = gr.JSON(label="Raw result")
48
+ img.change(scan_image, img, [img_label, img_out, img_json])
49
+ with gr.Tab("Video"):
50
+ with gr.Row():
51
+ vid = gr.Video(label="Video")
52
+ with gr.Column():
53
+ vid_label = gr.Label(label="Verdict")
54
+ vid_plot = gr.LinePlot(x="time", y="score", y_lim=[0, 1], label="Fake score per sampled frame")
55
+ vid_json = gr.JSON(label="Raw result")
56
+ vid.change(scan_video, vid, [vid_label, vid_plot, vid_json])
57
+
58
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ deepfake-detect @ git+https://github.com/CodeRafay/deepfake-detect