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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
LEADERBOARD_PATH = "leaderboard.csv"
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def load_leaderboard():
|
| 8 |
+
try:
|
| 9 |
+
return pd.read_csv(LEADERBOARD_PATH)
|
| 10 |
+
except FileNotFoundError:
|
| 11 |
+
return pd.DataFrame([{"Status": "No leaderboard data available"}])
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def style_leaderboard(df: pd.DataFrame):
|
| 15 |
+
"""Return styled HTML with highlighted best performers and professional formatting."""
|
| 16 |
+
if df.empty:
|
| 17 |
+
return "<p>No data available.</p>"
|
| 18 |
+
|
| 19 |
+
num_cols = [c for c in df.columns if c not in ["Rank", "Model"]]
|
| 20 |
+
|
| 21 |
+
def highlight_best(s):
|
| 22 |
+
if pd.api.types.is_numeric_dtype(s):
|
| 23 |
+
max_val = s.max()
|
| 24 |
+
return ['color: #6AA84F; font-weight: 600;' if v == max_val else '' for v in s]
|
| 25 |
+
return ['' for _ in s]
|
| 26 |
+
df = df.reset_index(drop=True)
|
| 27 |
+
styled = (df.style.apply(highlight_best, subset=num_cols, axis=0).format(precision=1).hide(axis='index'))
|
| 28 |
+
|
| 29 |
+
# Professional table styling
|
| 30 |
+
html = styled.to_html()
|
| 31 |
+
return f"""
|
| 32 |
+
<div style="margin: 20px 0;">
|
| 33 |
+
<div style="overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);">
|
| 34 |
+
<style>
|
| 35 |
+
table {{
|
| 36 |
+
width: 100%;
|
| 37 |
+
border-collapse: collapse;
|
| 38 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 39 |
+
}}
|
| 40 |
+
th {{
|
| 41 |
+
font-weight: 600;
|
| 42 |
+
padding: 16px 12px;
|
| 43 |
+
text-align: left;
|
| 44 |
+
border-bottom: 2px solid #e2e8f0;
|
| 45 |
+
font-size: 14px;
|
| 46 |
+
}}
|
| 47 |
+
td {{
|
| 48 |
+
padding: 12px;
|
| 49 |
+
border-bottom: 1px solid #f1f5f9;
|
| 50 |
+
font-size: 14px;
|
| 51 |
+
}}
|
| 52 |
+
tr:hover {{
|
| 53 |
+
background-color: #7c7d7e;
|
| 54 |
+
}}
|
| 55 |
+
</style>
|
| 56 |
+
{html}
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def leaderboard_view():
|
| 63 |
+
df = load_leaderboard()
|
| 64 |
+
return style_leaderboard(df)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# ---------------- Gradio UI ---------------- #
|
| 68 |
+
|
| 69 |
+
with gr.Blocks(css="""
|
| 70 |
+
.gradio-container {
|
| 71 |
+
max-width: 1200px !important;
|
| 72 |
+
margin: auto;
|
| 73 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 74 |
+
}
|
| 75 |
+
#title-image {
|
| 76 |
+
margin: 20px auto;
|
| 77 |
+
display: block;
|
| 78 |
+
max-width: 800px;
|
| 79 |
+
}
|
| 80 |
+
.gr-markdown h1 {
|
| 81 |
+
color: #1e293b;
|
| 82 |
+
font-weight: 700;
|
| 83 |
+
margin-bottom: 16px;
|
| 84 |
+
}
|
| 85 |
+
.gr-markdown h2 {
|
| 86 |
+
color: #334155;
|
| 87 |
+
font-weight: 600;
|
| 88 |
+
margin-top: 24px;
|
| 89 |
+
margin-bottom: 12px;
|
| 90 |
+
}
|
| 91 |
+
.gr-markdown h3 {
|
| 92 |
+
color: #475569;
|
| 93 |
+
font-weight: 600;
|
| 94 |
+
margin-bottom: 8px;
|
| 95 |
+
}
|
| 96 |
+
.gr-markdown p {
|
| 97 |
+
color: #64748b;
|
| 98 |
+
line-height: 1.6;
|
| 99 |
+
}
|
| 100 |
+
.gr-tab-nav button {
|
| 101 |
+
font-weight: 500;
|
| 102 |
+
}
|
| 103 |
+
""") as demo:
|
| 104 |
+
# Banner image
|
| 105 |
+
gr.Image("title.png", elem_id="title-image", show_label=False)
|
| 106 |
+
|
| 107 |
+
# Professional introduction
|
| 108 |
+
gr.Markdown("""
|
| 109 |
+
# DFBench: The Image Deepfake Detection Benchmark 2025
|
| 110 |
+
|
| 111 |
+
DFBench provides a standardized evaluation framework for computer vision deepfake detection systems.
|
| 112 |
+
This leaderboard focuses on image deepfake detection, e.g. the output of text-to-image and image-to-image models.
|
| 113 |
+
|
| 114 |
+
**Objectives:**
|
| 115 |
+
- Allow fair comparison between deepfake detection models on unseen test data
|
| 116 |
+
- Advance the state-of-the-art in synthetic media identification
|
| 117 |
+
|
| 118 |
+
This benchmark serves the academic and industry research community by providing consistent evaluation standards for deepfake detection methodologies.
|
| 119 |
+
""")
|
| 120 |
+
|
| 121 |
+
with gr.Tab("Leaderboard"):
|
| 122 |
+
gr.Markdown("## Current Performance Rankings")
|
| 123 |
+
gr.HTML(leaderboard_view())
|
| 124 |
+
gr.Markdown("""
|
| 125 |
+
*Leaderboard is updated upon validation of new submissions. All results are evaluated using standardized metrics on the official test dataset.*
|
| 126 |
+
""")
|
| 127 |
+
|
| 128 |
+
with gr.Tab("Submission Guidelines"):
|
| 129 |
+
gr.Markdown("""
|
| 130 |
+
# Model Submission Process
|
| 131 |
+
|
| 132 |
+
**Official Dataset:** [DFBench / Image-Deepfake-Detection-25](https://huggingface.co/datasets/DFBench/Image-Deepfake-Detection-25)
|
| 133 |
+
|
| 134 |
+
The evaluation dataset comprises **2,920 images** with binary classification labels:
|
| 135 |
+
- **Real:** Authentic, unmodified images
|
| 136 |
+
- **Fake:** AI-generated or synthetically modified content
|
| 137 |
+
|
| 138 |
+
---
|
| 139 |
+
|
| 140 |
+
## Submission Requirements
|
| 141 |
+
|
| 142 |
+
### File Format
|
| 143 |
+
Submit predictions as a CSV file with the following structure: `filename,label`.
|
| 144 |
+
- `filename`: Exact filename as provided in the dataset
|
| 145 |
+
- `label`: Binary classification result (`real` or `fake`)
|
| 146 |
+
|
| 147 |
+
For example:
|
| 148 |
+
|
| 149 |
+
```
|
| 150 |
+
filename,label
|
| 151 |
+
1.jpg,fake
|
| 152 |
+
2.jpeg,real
|
| 153 |
+
3.webp,fake
|
| 154 |
+
...
|
| 155 |
+
2920.png,fake
|
| 156 |
+
```
|
| 157 |
+
### Submission Process
|
| 158 |
+
|
| 159 |
+
1. **Prediction Generation**: Generate predictions for all 2,920 test images
|
| 160 |
+
2. **File Preparation**: Format results according to specification above
|
| 161 |
+
3. **Submission**: Send your CSV file submission to: **submission@dfbench.com**. The name of the file should correspond to the leaderboard model name, e.g. `Model_This_name.csv` will be included as `Model This name` in the leaderboard.
|
| 162 |
+
|
| 163 |
+
### Evaluation Timeline
|
| 164 |
+
- Submissions are processed within 5-7 business days
|
| 165 |
+
- Results are validated against ground truth labels
|
| 166 |
+
- Approved submissions are added to the public leaderboard
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
## Technical Notes
|
| 171 |
+
- Model names will be formatted for display (underscores converted to spaces)
|
| 172 |
+
- Each research group may submit one set of scores per month
|
| 173 |
+
- All submissions undergo automated validation before leaderboard inclusion
|
| 174 |
+
|
| 175 |
+
## Legal Notes
|
| 176 |
+
- The authors reserve the right to not publish or to remove a submission at their discretion
|
| 177 |
+
- Submissions may be excluded if found to violate ethical guidelines, contain malicious content, or appear fraudulent
|
| 178 |
+
- Benchmark maintainers may adjust evaluation protocols as the dataset and task evolve
|
| 179 |
+
- No warranties are provided regarding benchmark results, which are intended strictly for research and comparison purposes
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
For technical inquiries regarding the evaluation process, please contact the benchmark maintainers through the submission email.
|
| 183 |
+
""")
|
| 184 |
+
|
| 185 |
+
if __name__ == "__main__":
|
| 186 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|