Spaces:
Running
Running
Upload 3 files
Browse files- app.py +85 -0
- examples/1.jpg +0 -0
- examples/2.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import json
|
4 |
+
|
5 |
+
from gradio_client import Client, handle_file
|
6 |
+
backend = Client(os.getenv("BACKEND"), hf_token=os.getenv("TOKEN"))
|
7 |
+
|
8 |
+
def detect(image):
|
9 |
+
result_text = backend.predict(
|
10 |
+
image=handle_file(image),
|
11 |
+
api_name="/detect"
|
12 |
+
)
|
13 |
+
|
14 |
+
result = json.loads(result_text)
|
15 |
+
if result and result["status"] == "ok":
|
16 |
+
return result["overall"], result["aigen"], result["deepfake"]
|
17 |
+
else:
|
18 |
+
raise gr.Error("Error in processing image")
|
19 |
+
|
20 |
+
custom_css = """
|
21 |
+
.button-gradient {
|
22 |
+
background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c);
|
23 |
+
background-size: 400% 400%;
|
24 |
+
border: none;
|
25 |
+
padding: 14px 28px;
|
26 |
+
font-size: 16px;
|
27 |
+
font-weight: bold;
|
28 |
+
color: white;
|
29 |
+
border-radius: 10px;
|
30 |
+
cursor: pointer;
|
31 |
+
transition: 0.3s ease-in-out;
|
32 |
+
animation: gradientAnimation 2s infinite linear;
|
33 |
+
box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6);
|
34 |
+
}
|
35 |
+
|
36 |
+
@keyframes gradientAnimation {
|
37 |
+
0% { background-position: 0% 50%; }
|
38 |
+
25% { background-position: 50% 100%; }
|
39 |
+
50% { background-position: 100% 50%; }
|
40 |
+
75% { background-position: 50% 0%; }
|
41 |
+
100% { background-position: 0% 50%; }
|
42 |
+
}
|
43 |
+
|
44 |
+
.button-gradient:hover {
|
45 |
+
transform: scale(1.05);
|
46 |
+
box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8);
|
47 |
+
}
|
48 |
+
"""
|
49 |
+
|
50 |
+
MARKDOWN0 = """
|
51 |
+
# DeepFake Detector - ❤️Like above if this space helps
|
52 |
+
#### [Learn more about our solutions.](https://faceonlive.com)
|
53 |
+
"""
|
54 |
+
MARKDOWN3 = """
|
55 |
+
<div align="right"><a href="https://faceonlive.com/face-search-online" target='_blank' style='font-size: 16px;'>Reverse Face Search</div><br/>
|
56 |
+
<div align="right"><a href="https://faceonlive.com/reverse-image-search" target='_blank' style='font-size: 16px;'>Reverse Image Search</div>
|
57 |
+
"""
|
58 |
+
lbl_overall = gr.Label(label = "Overall")
|
59 |
+
lbl_aigen = gr.Label(label = "Generative AI Model")
|
60 |
+
lbl_deepfake = gr.Label(label = "Face Manipulation")
|
61 |
+
|
62 |
+
with gr.Blocks(css=custom_css) as demo:
|
63 |
+
gr.Markdown(MARKDOWN0)
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column(scale=1) as col1:
|
66 |
+
image = gr.Image(type='filepath', height=360)
|
67 |
+
detect_button = gr.Button("Detect", elem_classes="button-gradient")
|
68 |
+
gr.Examples(['examples/1.jpg', 'examples/2.jpg'], inputs=image, cache_examples=True, fn=detect, outputs = [lbl_overall, lbl_aigen, lbl_deepfake])
|
69 |
+
with gr.Column(scale=2) as col2:
|
70 |
+
lbl_overall.render()
|
71 |
+
with gr.Row():
|
72 |
+
with gr.Column():
|
73 |
+
lbl_aigen.render()
|
74 |
+
with gr.Column():
|
75 |
+
lbl_deepfake.render()
|
76 |
+
gr.HTML(MARKDOWN3)
|
77 |
+
with gr.Row():
|
78 |
+
with gr.Column(scale=1):
|
79 |
+
gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FDeep-Fake-Detector"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FDeep-Fake-Detector&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
|
80 |
+
with gr.Column(scale=5):
|
81 |
+
html = gr.HTML()
|
82 |
+
|
83 |
+
detect_button.click(detect, inputs=[image], outputs=[lbl_overall, lbl_aigen, lbl_deepfake], api_name=False)
|
84 |
+
|
85 |
+
demo.queue(api_open=False, default_concurrency_limit=8).launch(server_name="0.0.0.0", show_api=False)
|
examples/1.jpg
ADDED
![]() |
examples/2.jpg
ADDED
![]() |