Spaces:
Running
Running
AMontiB
commited on
Commit
Β·
65d0705
1
Parent(s):
c4321f9
update
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +19 -38
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -34,29 +34,12 @@ if os.environ.get("SPACE_ID"):
|
|
| 34 |
# Available detectors based on launcher.py
|
| 35 |
DETECTORS = ['ALL', 'R50_TF', 'R50_nodown', 'CLIP-D', 'P2G', 'NPR']
|
| 36 |
|
| 37 |
-
# Performance weights from Table III (Non-shared) and Table IV (Social Media: FB, TL, X)
|
| 38 |
-
# Weights are averaged between Non-shared and Social Media performance.
|
| 39 |
-
# R50_TF (R50-E2P):
|
| 40 |
-
# Real (TNR): (0.98 + 0.91) / 2 = 0.95
|
| 41 |
-
# Fake (TPR): (0.85 + 0.65) / 2 = 0.75
|
| 42 |
-
# R50_nodown (R50-ND):
|
| 43 |
-
# Real (TNR): (1.00 + 0.97) / 2 = 0.98
|
| 44 |
-
# Fake (TPR): (0.79 + 0.76) / 2 = 0.77
|
| 45 |
-
# CLIP-D:
|
| 46 |
-
# Real (TNR): (0.97 + 0.94) / 2 = 0.95
|
| 47 |
-
# Fake (TPR): (0.93 + 0.91) / 2 = 0.92
|
| 48 |
-
# P2G:
|
| 49 |
-
# Real (TNR): (1.00 + 1.00) / 2 = 1.00
|
| 50 |
-
# Fake (TPR): (0.91 + 0.56) / 2 = 0.74
|
| 51 |
-
# NPR:
|
| 52 |
-
# Real (TNR): (0.99 + 1.00) / 2 = 1.00
|
| 53 |
-
# Fake (TPR): (0.60 + 0.12) / 2 = 0.36
|
| 54 |
DETECTOR_WEIGHTS = {
|
| 55 |
-
'
|
| 56 |
-
'
|
| 57 |
-
'
|
| 58 |
-
'P2G':
|
| 59 |
-
'NPR':
|
| 60 |
}
|
| 61 |
|
| 62 |
def process_image(image_path):
|
|
@@ -187,15 +170,13 @@ def predict(image_path, detector_name):
|
|
| 187 |
# Weighted Voting logic
|
| 188 |
# Only count vote if confidence > 0.6
|
| 189 |
if score > 0.6:
|
| 190 |
-
|
| 191 |
if pred == 'fake':
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
total_weight_used += w
|
| 195 |
elif pred == 'real':
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
total_weight_used += w
|
| 199 |
|
| 200 |
# Majority Voting
|
| 201 |
if votes_real > votes_fake:
|
|
@@ -302,7 +283,7 @@ with demo:
|
|
| 302 |
|
| 303 |
### Understanding the Results produced by "ALL"
|
| 304 |
* Runs all available detectors (R50_TF, R50_nodown, CLIP-D, P2G, NPR) sequentially on the input image.
|
| 305 |
-
* Produces a **Weighted Majority Vote** verdict (Real/Fake). Each model's vote is weighted by
|
| 306 |
* You can find the specific weights used for each model in the **"βοΈ Weight Details"** menu below.
|
| 307 |
* Also generates a **Confidence Plot** visualizing each model's score and a textual **Explanation** of the consensus.
|
| 308 |
* In the plot, **Green** bars indicate a **Real** prediction, while **Red** bars indicate a **Fake** prediction.
|
|
@@ -336,15 +317,15 @@ with demo:
|
|
| 336 |
with gr.Accordion("βοΈ Weight Details", open=False):
|
| 337 |
gr.Markdown(f"""
|
| 338 |
### **Detector Weights**
|
| 339 |
-
|
| 340 |
|
| 341 |
-
| Detector |
|
| 342 |
-
| :--- | :---: |
|
| 343 |
-
| **
|
| 344 |
-
| **
|
| 345 |
-
| **
|
| 346 |
-
| **P2G** | {DETECTOR_WEIGHTS['P2G']
|
| 347 |
-
| **NPR** | {DETECTOR_WEIGHTS['NPR']
|
| 348 |
""")
|
| 349 |
|
| 350 |
with gr.Accordion("π Model Details", open=False):
|
|
|
|
| 34 |
# Available detectors based on launcher.py
|
| 35 |
DETECTORS = ['ALL', 'R50_TF', 'R50_nodown', 'CLIP-D', 'P2G', 'NPR']
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
DETECTOR_WEIGHTS = {
|
| 38 |
+
'CLIP-D': 0.30,
|
| 39 |
+
'R50_TF': 0.25,
|
| 40 |
+
'R50_nodown': 0.20,
|
| 41 |
+
'P2G': 0.15,
|
| 42 |
+
'NPR': 0.10
|
| 43 |
}
|
| 44 |
|
| 45 |
def process_image(image_path):
|
|
|
|
| 170 |
# Weighted Voting logic
|
| 171 |
# Only count vote if confidence > 0.6
|
| 172 |
if score > 0.6:
|
| 173 |
+
weight = DETECTOR_WEIGHTS.get(det, 0.0)
|
| 174 |
if pred == 'fake':
|
| 175 |
+
votes_fake += weight * score
|
| 176 |
+
total_weight_used += weight
|
|
|
|
| 177 |
elif pred == 'real':
|
| 178 |
+
votes_real += weight * score
|
| 179 |
+
total_weight_used += weight
|
|
|
|
| 180 |
|
| 181 |
# Majority Voting
|
| 182 |
if votes_real > votes_fake:
|
|
|
|
| 283 |
|
| 284 |
### Understanding the Results produced by "ALL"
|
| 285 |
* Runs all available detectors (R50_TF, R50_nodown, CLIP-D, P2G, NPR) sequentially on the input image.
|
| 286 |
+
* Produces a **Weighted Majority Vote** verdict (Real/Fake). Each model's vote is weighted by a fixed importance score (summing to 1) based on user ranking **and its confidence score**. Only confident predictions (> 0.6) are counted.
|
| 287 |
* You can find the specific weights used for each model in the **"βοΈ Weight Details"** menu below.
|
| 288 |
* Also generates a **Confidence Plot** visualizing each model's score and a textual **Explanation** of the consensus.
|
| 289 |
* In the plot, **Green** bars indicate a **Real** prediction, while **Red** bars indicate a **Fake** prediction.
|
|
|
|
| 317 |
with gr.Accordion("βοΈ Weight Details", open=False):
|
| 318 |
gr.Markdown(f"""
|
| 319 |
### **Detector Weights**
|
| 320 |
+
The weights are assigned based on the ranking (based on the results of [TrueFake: A Real World Case Dataset of Last Generation Fake Images also Shared on Social Networks](https://arxiv.org/pdf/2504.20658)): **CLIP-D > R50_TF > R50_nodown > P2G > NPR**, such that their sum equals 1.
|
| 321 |
|
| 322 |
+
| Detector | Weight |
|
| 323 |
+
| :--- | :---: |
|
| 324 |
+
| **CLIP-D** | {DETECTOR_WEIGHTS['CLIP-D']:.2f} |
|
| 325 |
+
| **R50_TF** | {DETECTOR_WEIGHTS['R50_TF']:.2f} |
|
| 326 |
+
| **R50_nodown** | {DETECTOR_WEIGHTS['R50_nodown']:.2f} |
|
| 327 |
+
| **P2G** | {DETECTOR_WEIGHTS['P2G']:.2f} |
|
| 328 |
+
| **NPR** | {DETECTOR_WEIGHTS['NPR']:.2f} |
|
| 329 |
""")
|
| 330 |
|
| 331 |
with gr.Accordion("π Model Details", open=False):
|