Spaces:
Runtime error
Runtime error
SivaResearch
commited on
Commit
Β·
6214a3a
1
Parent(s):
aae709d
updated
Browse files- .gitattributes +1 -9
- .gitignore +1 -0
- README.md +6 -6
- app.py +49 -0
- examples.zip +3 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
@@ -2,34 +2,26 @@
|
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
5 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
10 |
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
12 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
13 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
14 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
15 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
16 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
17 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
18 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
19 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
20 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
21 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
22 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
23 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
examples/
|
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title: Detection
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Deepfake Detection
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.0.14
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import torch.nn.functional as F
|
4 |
+
from facenet_pytorch import MTCNN, InceptionResnetV1
|
5 |
+
import os
|
6 |
+
import numpy as np
|
7 |
+
from PIL import Image
|
8 |
+
import zipfile
|
9 |
+
import cv2
|
10 |
+
from pytorch_grad_cam import GradCAM
|
11 |
+
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
|
12 |
+
from pytorch_grad_cam.utils.image import show_cam_on_image
|
13 |
+
from transformers import pipeline
|
14 |
+
with zipfile.ZipFile("examples.zip","r") as zip_ref:
|
15 |
+
zip_ref.extractall(".")
|
16 |
+
|
17 |
+
pipe = pipeline(model="SivaResearch/Fake_Detection",trust_remote_code=True)
|
18 |
+
|
19 |
+
EXAMPLES_FOLDER = 'examples'
|
20 |
+
examples_names = os.listdir(EXAMPLES_FOLDER)
|
21 |
+
examples = []
|
22 |
+
for example_name in examples_names:
|
23 |
+
example_path = os.path.join(EXAMPLES_FOLDER, example_name)
|
24 |
+
label = example_name.split('_')[0]
|
25 |
+
example = {
|
26 |
+
'path': example_path,
|
27 |
+
'label': label
|
28 |
+
}
|
29 |
+
examples.append(example)
|
30 |
+
np.random.shuffle(examples) # shuffle
|
31 |
+
|
32 |
+
def predict(input_image:Image.Image, true_label:str):
|
33 |
+
out = pipe.predict(input_image)
|
34 |
+
confidences,face_with_mask = out["confidences"], out["face_with_mask"]
|
35 |
+
return confidences, true_label, face_with_mask
|
36 |
+
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=predict,
|
39 |
+
inputs=[
|
40 |
+
gr.Image(label="Input Image", type="filepath"),
|
41 |
+
"text"
|
42 |
+
],
|
43 |
+
outputs=[
|
44 |
+
gr.Label(label="Class"),
|
45 |
+
"text",
|
46 |
+
gr.Image(label="Face with Explainability")
|
47 |
+
],
|
48 |
+
examples=[[examples[i]["path"], examples[i]["label"]] for i in range(10)]
|
49 |
+
).launch()
|
examples.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9c719c2f16bad2e71d0d33d6ae59fa646dac82a812e1a90578c4b97ef6e8f36c
|
3 |
+
size 28750945
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
Pillow
|
3 |
+
facenet-pytorch
|
4 |
+
torch
|
5 |
+
opencv-python
|
6 |
+
grad-cam
|
7 |
+
transformers
|