Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,18 @@ import gradio as gr
|
|
3 |
import json
|
4 |
from gradio_client import Client, handle_file
|
5 |
|
6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
try:
|
8 |
-
backend = Client(
|
9 |
except Exception as e:
|
10 |
raise Exception(f"Failed to initialize backend client: {str(e)}")
|
11 |
|
@@ -24,7 +33,6 @@ def detect(image):
|
|
24 |
if not result or result.get("status") != "ok":
|
25 |
raise gr.Error("Analysis failed: Invalid response from backend")
|
26 |
|
27 |
-
# Format results professionally
|
28 |
overall = f"{result['overall']}% Confidence"
|
29 |
aigen = f"{result['aigen']}% (AI-Generated Content Likelihood)"
|
30 |
deepfake = f"{result['deepfake']}% (Face Manipulation Likelihood)"
|
@@ -36,7 +44,9 @@ def detect(image):
|
|
36 |
except Exception as e:
|
37 |
raise gr.Error(f"Analysis error: {str(e)}")
|
38 |
|
39 |
-
#
|
|
|
|
|
40 |
custom_css = """
|
41 |
.container {
|
42 |
max-width: 1200px;
|
@@ -72,94 +82,30 @@ custom_css = """
|
|
72 |
50% { background-position: 100% 50%; }
|
73 |
100% { background-position: 0% 50%; }
|
74 |
}
|
75 |
-
.label {
|
76 |
-
font-weight: 600;
|
77 |
-
color: #34495e;
|
78 |
-
background: #f8f9fa;
|
79 |
-
padding: 10px;
|
80 |
-
border-radius: 5px;
|
81 |
-
margin: 5px 0;
|
82 |
-
}
|
83 |
-
.footer {
|
84 |
-
color: #7f8c8d;
|
85 |
-
font-size: 14px;
|
86 |
-
margin-top: 20px;
|
87 |
-
}
|
88 |
"""
|
89 |
|
90 |
-
# Professional content
|
91 |
MARKDOWN0 = """
|
92 |
<div class="header">
|
93 |
<h1>DeepFake Detection System</h1>
|
94 |
<p>Advanced AI-powered analysis for identifying manipulated media</p>
|
95 |
</div>
|
96 |
-
<div style="margin: 15px 0;">
|
97 |
-
<a href="https://faceonlive.com/deepfake-detector" target="_blank" style="color: #3498db; text-decoration: none;">
|
98 |
-
Learn About Our Technology
|
99 |
-
</a>
|
100 |
-
</div>
|
101 |
-
"""
|
102 |
-
|
103 |
-
MARKDOWN3 = """
|
104 |
-
<div class="footer">
|
105 |
-
<p>Additional Tools:</p>
|
106 |
-
<div style="margin: 10px 0;">
|
107 |
-
<a href="https://faceonlive.com/face-search-online" target="_blank" style="color: #3498db; text-decoration: none; margin-right: 15px;">
|
108 |
-
Face Search Technology
|
109 |
-
</a>
|
110 |
-
<a href="https://faceonlive.com/reverse-image-search" target="_blank" style="color: #3498db; text-decoration: none;">
|
111 |
-
Reverse Image Search
|
112 |
-
</a>
|
113 |
-
</div>
|
114 |
-
<p>© 2025 FaceOnLive - All Rights Reserved</p>
|
115 |
-
</div>
|
116 |
"""
|
117 |
|
118 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
119 |
gr.Markdown(MARKDOWN0)
|
120 |
-
|
121 |
with gr.Row(elem_classes="container"):
|
122 |
with gr.Column(scale=1):
|
123 |
-
image = gr.Image(
|
124 |
-
|
125 |
-
height=400,
|
126 |
-
label="Upload Image for Analysis",
|
127 |
-
interactive=True
|
128 |
-
)
|
129 |
-
detect_button = gr.Button(
|
130 |
-
"Analyze Image",
|
131 |
-
elem_classes="button-gradient"
|
132 |
-
)
|
133 |
-
gr.Examples(
|
134 |
-
examples=['examples 1.jpg', 'examples 2.jpg'],
|
135 |
-
inputs=image,
|
136 |
-
outputs=['overall', 'aigen', 'deepfake'],
|
137 |
-
fn=detect,
|
138 |
-
cache_examples=True
|
139 |
-
)
|
140 |
-
|
141 |
with gr.Column(scale=2):
|
142 |
-
overall = gr.Label(label="Confidence Score"
|
143 |
-
|
144 |
-
|
145 |
-
deepfake = gr.Label(label="Face Manipulation", elem_classes="label")
|
146 |
-
|
147 |
-
gr.Markdown(MARKDOWN3)
|
148 |
-
|
149 |
-
# Visitor badge
|
150 |
-
gr.HTML("""
|
151 |
-
<div style="margin-top: 20px;">
|
152 |
-
<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FDeep-Fake-Detector">
|
153 |
-
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FFaceOnLive%2FDeep-Fake-Detector&labelColor=%233495db&countColor=%232ecc71&style=flat" />
|
154 |
-
</a>
|
155 |
-
</div>
|
156 |
-
""")
|
157 |
|
158 |
detect_button.click(
|
159 |
fn=detect,
|
160 |
inputs=[image],
|
161 |
-
outputs=[overall, aigen, deepfake]
|
162 |
-
_js="() => {return [document.querySelector('input[type=file]').files[0]]}"
|
163 |
)
|
164 |
|
165 |
demo.queue(api_open=False, concurrency_count=8).launch(
|
|
|
3 |
import json
|
4 |
from gradio_client import Client, handle_file
|
5 |
|
6 |
+
# Validate environment variables and initialize backend client
|
7 |
+
BACKEND_URL = os.getenv("BACKEND")
|
8 |
+
HF_TOKEN = os.getenv("TOKEN")
|
9 |
+
|
10 |
+
if not BACKEND_URL:
|
11 |
+
raise ValueError(
|
12 |
+
"BACKEND environment variable is not set. "
|
13 |
+
"Please set it to the backend URL (e.g., 'https://your-backend-url')"
|
14 |
+
)
|
15 |
+
|
16 |
try:
|
17 |
+
backend = Client(BACKEND_URL, hf_token=HF_TOKEN)
|
18 |
except Exception as e:
|
19 |
raise Exception(f"Failed to initialize backend client: {str(e)}")
|
20 |
|
|
|
33 |
if not result or result.get("status") != "ok":
|
34 |
raise gr.Error("Analysis failed: Invalid response from backend")
|
35 |
|
|
|
36 |
overall = f"{result['overall']}% Confidence"
|
37 |
aigen = f"{result['aigen']}% (AI-Generated Content Likelihood)"
|
38 |
deepfake = f"{result['deepfake']}% (Face Manipulation Likelihood)"
|
|
|
44 |
except Exception as e:
|
45 |
raise gr.Error(f"Analysis error: {str(e)}")
|
46 |
|
47 |
+
# [Rest of your CSS and UI code remains the same...]
|
48 |
+
# I'll include just the essential setup part here for brevity
|
49 |
+
|
50 |
custom_css = """
|
51 |
.container {
|
52 |
max-width: 1200px;
|
|
|
82 |
50% { background-position: 100% 50%; }
|
83 |
100% { background-position: 0% 50%; }
|
84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
"""
|
86 |
|
|
|
87 |
MARKDOWN0 = """
|
88 |
<div class="header">
|
89 |
<h1>DeepFake Detection System</h1>
|
90 |
<p>Advanced AI-powered analysis for identifying manipulated media</p>
|
91 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
"""
|
93 |
|
94 |
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
95 |
gr.Markdown(MARKDOWN0)
|
|
|
96 |
with gr.Row(elem_classes="container"):
|
97 |
with gr.Column(scale=1):
|
98 |
+
image = gr.Image(type='filepath', height=400, label="Upload Image")
|
99 |
+
detect_button = gr.Button("Analyze Image", elem_classes="button-gradient")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
with gr.Column(scale=2):
|
101 |
+
overall = gr.Label(label="Confidence Score")
|
102 |
+
aigen = gr.Label(label="AI-Generated Content")
|
103 |
+
deepfake = gr.Label(label="Face Manipulation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
detect_button.click(
|
106 |
fn=detect,
|
107 |
inputs=[image],
|
108 |
+
outputs=[overall, aigen, deepfake]
|
|
|
109 |
)
|
110 |
|
111 |
demo.queue(api_open=False, concurrency_count=8).launch(
|