Spaces:
Runtime error
Runtime error
File size: 20,326 Bytes
d065b18 651b66f 1244a5c 651b66f ef996ab 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad d4dac67 781bbad ef996ab d065b18 651b66f 1244a5c 651b66f 781bbad 651b66f 2a53b60 781bbad 651b66f 781bbad 651b66f 2a53b60 ef996ab 651b66f 4c38f62 d4dac67 eb9597a 1244a5c 651b66f 1244a5c 651b66f ef996ab 781bbad d4dac67 781bbad d4dac67 781bbad d4dac67 781bbad d91cf7d d4dac67 d91cf7d d4dac67 d91cf7d d4dac67 d91cf7d d4dac67 d91cf7d d4dac67 d91cf7d 781bbad d4dac67 781bbad d4dac67 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 651b66f 781bbad 1244a5c 781bbad 651b66f 781bbad 4ef742d 781bbad 4ef742d 781bbad d91cf7d 781bbad 651b66f d065b18 8a4f752 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Fraud Score</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet" />
<!-- jsPDF & html2canvas for PDF export -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<style>
:root {
--apple-blue: #007aff;
--apple-gray: #f2f2f7;
--apple-border: #d1d1d6;
--apple-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--apple-gray);
color: #1c1c1e;
}
h1, h2, h5 { font-weight: 600; }
/* thumbnails */
.preset-image-container { overflow: hidden; margin-bottom: 12px; }
.preset-image {
width: 100%; border-radius: 12px; border: 2px solid transparent;
box-shadow: var(--apple-shadow); transition: transform .3s ease, border-color .3s ease; cursor: pointer;
}
.preset-image:hover { transform: scale(1.05); }
.preset-image.selected { border-color: var(--apple-blue); }
/* dropzone */
.dropzone {
border: 2px dashed var(--apple-border); border-radius: 16px; background: #fff;
padding: 20px; text-align: center; box-shadow: var(--apple-shadow);
}
/* preview */
.preview-image {
max-width: 220px; border-radius: 16px; box-shadow: var(--apple-shadow);
opacity: 0; transition: opacity .4s ease;
}
.preview-image.visible { opacity: 1; }
/* generic primary button (blue) */
.btn-primary { background: var(--apple-blue); border: none; font-weight: 500; }
.btn-primary:hover { background: #005ecb; }
/* validate button (light blue) */
.btn-validate { background: #8ec3ff; border: none; font-weight: 500; }
.btn-validate:disabled { background: #d0e5ff; cursor: not-allowed; }
/* gauge */
.jauge-container {
display: none; align-items: center; gap: 24px; margin-top: 24px;
}
.jauge {
width: 24px; height: 160px; border-radius: 12px; background: #e5e5ea;
position: relative; overflow: hidden; border: 1px solid var(--apple-border);
}
.jauge-level {
position: absolute; bottom: 0; width: 100%; border-radius: 12px;
background: var(--apple-blue); transition: height .6s ease, background .3s ease;
}
.jauge-labels {
font-size: 0.7rem; color: #636366; display: flex; flex-direction: column; justify-content: space-between; height: 160px;
}
/* icon column */
.icon-buttons {
display: none; flex-direction: column; gap: 16px; justify-content: center; align-items: center; margin-left: 12px;
}
.icon-buttons button { background: none; border: none; color: var(--apple-blue); font-size: 24px; cursor: pointer; }
/* section hidden until first preview shown */
#compareSection { margin-top: 40px; text-align: center; display: none; }
/* modal */
.modal-header { border-bottom: 1px solid var(--apple-border); }
.modal-footer { border-top: 1px solid var(--apple-border); }
</style>
</head>
<body>
<div class="container py-5">
<h1 class="text-center mb-1">Fraud Score</h1>
<p class="text-center text-muted mb-5 fs-5">Is my work used by generative AI ?</p>
<!-- selection rows -->
<div class="row g-5">
<!-- original -->
<div class="col-md-6">
<h5 class="text-center mb-3">Select Original Image</h5>
<div class="row">
<div class="col-4"><div class="preset-image-container"><img id="preset-1-1" src="/static/marilyn_1.jpg" class="preset-image" onclick="selectPreset(1,1)" alt="Original 1" /></div></div>
<div class="col-4"><div class="preset-image-container"><img id="preset-2-1" src="/static/star wars_1b.jpg" class="preset-image" onclick="selectPreset(2,1)" alt="Original 2" /></div></div>
<div class="col-4"><div class="preset-image-container"><img id="preset-3-1" src="/static/muhammad ali_1.jpg" class="preset-image" onclick="selectPreset(3,1)" alt="Original 3" /></div></div>
</div>
<div class="dropzone mt-3" id="dropzone1">
<p class="mb-2">Drag & Drop or Upload (.jpg/.png/.webp)</p>
<input type="file" id="fileInput1" accept="image/*" hidden />
<button class="btn btn-outline-secondary" onclick="document.getElementById('fileInput1').click()">Upload</button>
</div>
</div>
<!-- AI generated -->
<div class="col-md-6">
<h5 class="text-center mb-3">Select AI Generated Image</h5>
<div class="row">
<div class="col-4"><div class="preset-image-container"><img id="preset-1-2" src="/static/marilyn_2.png" class="preset-image" onclick="selectPreset(1,2)" alt="AI 1" /></div></div>
<div class="col-4"><div class="preset-image-container"><img id="preset-2-2" src="/static/star wars_2b.png" class="preset-image" onclick="selectPreset(2,2)" alt="AI 2" /></div></div>
<div class="col-4"><div class="preset-image-container"><img id="preset-3-2" src="/static/muhammad ali_2.png" class="preset-image" onclick="selectPreset(3,2)" alt="AI 3" /></div></div>
</div>
<div class="dropzone mt-3" id="dropzone2">
<p class="mb-2">Drag & Drop or Upload (.jpg/.png/.webp)</p>
<input type="file" id="fileInput2" accept="image/*" hidden />
<button class="btn btn-outline-secondary" onclick="document.getElementById('fileInput2').click()">Upload</button>
</div>
</div>
</div>
<!-- compare section -->
<div id="compareSection">
<div class="d-flex justify-content-center align-items-center gap-5 mt-5">
<img id="previewImage1" class="preview-image" alt="Original preview" />
<div class="d-flex flex-column align-items-center">
<div id="compareButtonContainer" class="mb-3"></div>
<div id="scoreBlock" style="display:none;">
<h2 class="fw-semibold mb-3">Fraud Score <span id="euclidVal" class="text-muted"></span>%</h2>
<div class="d-flex align-items-center gap-4">
<div class="jauge-container mx-auto" id="gaugeWrapper">
<div class="jauge"><div class="jauge-level" id="jaugeLevel"></div></div>
<div class="jauge-labels text-start">
<span>most certainly</span><span>very probably</span><span>probably</span><span>possibly</span><span>probably not</span><span>definitely not</span>
</div>
</div>
<div class="icon-buttons" id="iconButtons">
<button title="Print" onclick="generatePDF1()"><i class="fas fa-print"></i></button>
<button title="Certificate" data-bs-toggle="modal" data-bs-target="#certModal"><i class="fas fa-certificate"></i></button>
</div>
</div>
</div>
</div>
<img id="previewImage2" class="preview-image" alt="AI preview" />
</div>
<div id="results" class="mt-4"></div>
</div>
</div>
<!-- Certificate modal -->
<div class="modal fade" id="certModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form id="certForm" class="needs-validation" novalidate>
<div class="modal-header">
<h5 class="modal-title">Certificate details</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row g-3">
<div class="col-md-6">
<label for="firstName" class="form-label">First Name</label>
<input id="firstName" class="form-control" required>
</div>
<div class="col-md-6">
<label for="lastName" class="form-label">Last Name</label>
<input id="lastName" class="form-control" required>
</div>
<div class="col-md-6">
<label for="occupation" class="form-label">Occupation</label>
<input id="occupation" class="form-control" required>
</div>
<div class="col-md-6">
<label for="city" class="form-label">City</label>
<input id="city" class="form-control" required>
</div>
<div class="col-md-6">
<label for="state" class="form-label">State</label>
<input id="state" class="form-control" required>
</div>
<div class="col-md-6">
<label for="linkedin" class="form-label">LinkedIn URL</label>
<input id="linkedin" type="url" class="form-control" placeholder="https://www.linkedin.com/in/…" required>
</div>
<!-- Generative AI (datalist + free text) -->
<div class="col-12">
<label for="aiModel" class="form-label">Generative AI</label>
<!-- l’utilisateur peut taper librement ou choisir dans la liste -->
<input
id="aiModel"
list="aiList"
class="form-control"
placeholder="Select or type…"
required
>
<datalist id="aiList">
<option value="Adobe Firefly Image Model 4">
<option value="Bing Image Creator">
<option value="Canva Magic Media">
<option value="DALL E GPT4o Image">
<option value="Flux (F LUX 1)">
<option value="Ideogram 30">
<option value="Leonardo AI Phoenix">
<option value="Microsoft Designer">
<option value="Midjourney v6">
<option value="NightCafe Creator">
<option value="Playground AI">
<option value="Runway Gen3 Alpha">
<option value="Stable Diffusion 3">
</datalist>
</div>
<!-- check box -->
<div class="col-12">
<div class="form-check">
<input id="certCheck" class="form-check-input" type="checkbox" required>
<label class="form-check-label" for="certCheck">
I certify that the original image is my work and that the generated image was produced by the indicated generative AI, with the following prompt:
<span class="text-danger ms-1" aria-hidden="true">*</span>
</label>
</div>
</div>
<div class="col-12">
<textarea id="promptText" class="form-control" rows="3" placeholder="Prompt" required></textarea>
</div>
</div>
</div>
<!-- modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
<button id="validateBtn" type="submit" class="btn btn-validate" disabled>Validate & Generate PDF</button>
</div>
</form>
</div>
</div>
</div>
<!-- scripts -->
<script>
let file1 = null, file2 = null;
/* helper functions for selection */
function resetSelection(target){
for(let i=1;i<=3;i++){
const t=document.getElementById(`preset-${i}-${target}`);
if(t) t.classList.remove('selected');
}
}
function selectPreset(n,target){
const imgEl=document.getElementById(`preset-${n}-${target}`);
const src=imgEl.src;
fetch(src).then(r=>r.blob()).then(blob=>{
const f=new File([blob],src.split('/').pop(),{type:blob.type});
if(target===1){file1=f;}else{file2=f;}
updatePreview(blob,target);
resetSelection(target);
imgEl.classList.add('selected');
checkReady();
});
}
function updatePreview(blob,target){
const reader=new FileReader();
reader.onload=e=>{
const img=document.getElementById(`previewImage${target}`);
img.src=e.target.result;
img.classList.add('visible');
document.getElementById('compareSection').style.display='block';
};
reader.readAsDataURL(blob);
}
/* upload inputs */
document.getElementById('fileInput1').addEventListener('change',e=>{
if(e.target.files.length){file1=e.target.files[0];updatePreview(file1,1);resetSelection(1);checkReady();}
});
document.getElementById('fileInput2').addEventListener('change',e=>{
if(e.target.files.length){file2=e.target.files[0];updatePreview(file2,2);resetSelection(2);checkReady();}
});
/* enable calculate button */
function checkReady(){
const c=document.getElementById('compareButtonContainer');
c.innerHTML = (file1&&file2) ? '<button class="btn btn-primary" onclick="processImages()">Calculate Fraud Score</button>' : '';
}
/* fraud score API */
async function processImages(){
const fd=new FormData();
fd.append('image1',file1);
fd.append('image2',file2);
const resDiv=document.getElementById('results');
resDiv.innerHTML='<div class="spinner-border text-primary"></div>';
try{
const res=await fetch('/process',{method:'POST',body:fd});
const data=await res.json();
const euclid=parseFloat(data.distance);
const fraud=Math.min(100,Math.max(2,185-2.73*euclid));
document.getElementById('euclidVal').textContent=fraud.toFixed(1);
document.getElementById('scoreBlock').style.display='block';
/* gauge colour */
const g=document.getElementById('jaugeLevel');
g.style.height=`${Math.min(100,fraud)}%`;
g.style.backgroundColor = fraud>90?"#dc3545":fraud>75?"#fd7e14":fraud>60?"#ffc107":fraud>45?"#0dcaf0":fraud>30?"#0d6efd":"#198754";
document.getElementById('gaugeWrapper').style.display='flex';
document.getElementById('iconButtons').style.display='flex';
resDiv.innerHTML='';
}catch{resDiv.innerHTML='<div class="text-danger">Error processing images.</div>';}
}
/* validate button enable logic */
const validateBtn=document.getElementById('validateBtn');
const certCheck =document.getElementById('certCheck');
certCheck.addEventListener('change',()=>{ validateBtn.disabled = !certCheck.checked; });
/* certificate form submission */
document.getElementById('certForm').addEventListener('submit',e=>{
if(!certCheck.checked){ e.preventDefault(); certCheck.focus(); return; }
e.preventDefault();
const certData={
first : firstName.value.trim(),
last : lastName.value.trim(),
occupation : occupation.value.trim(),
city : city.value.trim(),
state : state.value.trim(),
linkedin : linkedin.value.trim(),
ai : aiModel.value,
prompt : promptText.value.trim()
};
bootstrap.Modal.getInstance(certModal).hide();
generatePDF2(certData);
});
/* PDF – simple fraud score */
async function generatePDF1(){
const {jsPDF}=window.jspdf;
const pdf=new jsPDF({unit:'pt',format:'a4'});
const pageW=pdf.internal.pageSize.getWidth(),margin=40,usableW=pageW-margin*2; let y=100;
pdf.setFont('helvetica','normal'); pdf.setFontSize(24); pdf.text('Fraud Score',pageW/2,y,{align:'center'});
y+=20; pdf.setFontSize(12); pdf.text('Is my work used by generative AI ?',pageW/2,y,{align:'center'});
y+=100;
const section=document.querySelector('#compareSection .d-flex'); const clone=section.cloneNode(true);
clone.querySelectorAll('button').forEach(b=>b.style.display='none'); document.body.appendChild(clone);
clone.style.cssText='position:absolute;left:-9999px;top:0;';
const canvas=await html2canvas(clone,{backgroundColor:null}); document.body.removeChild(clone);
const img=canvas.toDataURL('image/png'); const prop=pdf.getImageProperties(img);
const imgH=(prop.height*usableW)/prop.width; pdf.addImage(img,'PNG',margin,y,usableW,imgH);
y+=imgH+60; pdf.setFontSize(10);
const urlLines=pdf.splitTextToSize(`Calculated by: ${window.location.href}`,usableW);
pdf.text(urlLines,margin,y);
window.open(pdf.output('bloburl'),'_blank');
}
/* PDF – certificate */
async function generatePDF2(certData){
const {jsPDF}=window.jspdf;
const pdf=new jsPDF({unit:'pt',format:'a4'});
const pageW=pdf.internal.pageSize.getWidth(),margin=40,usableW=pageW-margin*2; let y=80;
pdf.setFont('helvetica','normal'); pdf.setFontSize(26); pdf.text('Certification',pageW/2,y,{align:'center'});
y+=22; pdf.setDrawColor('#d1d1d6'); pdf.line(margin,y,pageW-margin,y); y+=32;
const section=document.querySelector('#compareSection .d-flex'); const clone=section.cloneNode(true);
clone.querySelectorAll('button').forEach(b=>b.style.display='none'); document.body.appendChild(clone);
clone.style.cssText='position:absolute;left:-9999px;top:0;';
const canvas=await html2canvas(clone,{backgroundColor:null}); document.body.removeChild(clone);
const img=canvas.toDataURL('image/png'); const prop=pdf.getImageProperties(img);
const imgH=(prop.height*usableW)/prop.width; pdf.addImage(img,'PNG',margin,y,usableW,imgH); y+=imgH+40;
/* texte de certification */
pdf.setFontSize(12);
const paragraph = 'I hereby certify that the original picture shown on the left is my own work and that the AI generated picture shown on the right was produced by the generative AI indicated below, using the prompt that follows.';
// Couper automatiquement en lignes tenant dans la marge
const lines = pdf.splitTextToSize(paragraph, usableW);
pdf.text(lines, margin, y); // boucle interne automatique
y += lines.length * 14 + 40; // 14 pt ≈ interligne, puis espace
const labelX = margin + 50, valueX = margin + 150;
pdf.setFont('helvetica','normal'); pdf.text('Generative AI:',labelX,y); pdf.setFont('helvetica','italic'); pdf.text(certData.ai,valueX,y); y+=28;
pdf.setFont('helvetica','normal'); pdf.text('Prompt:',labelX,y); pdf.setFont('helvetica','italic');
const promptLines=pdf.splitTextToSize(certData.prompt,usableW-valueX);
pdf.text(promptLines,valueX,y); y+=promptLines.length*14+28;
pdf.setFont('helvetica','normal'); pdf.text('Name:',labelX,y); pdf.setFont('helvetica','italic'); pdf.text(`${certData.first} ${certData.last}`,valueX,y); y+=28;
pdf.setFont('helvetica','normal'); pdf.text('Occupation:',labelX,y); pdf.setFont('helvetica','italic'); pdf.text(certData.occupation,valueX,y); y+=28;
pdf.setFont('helvetica','normal'); pdf.text('City / State:',labelX,y); pdf.setFont('helvetica','italic'); pdf.text(`${certData.city}, ${certData.state}`,valueX,y); y+=28;
pdf.setFont('helvetica','normal'); pdf.text('LinkedIn:',labelX,y); pdf.setFont('helvetica','italic'); pdf.text(certData.linkedin,valueX,y); y+=40;
pdf.setFont('helvetica','normal'); pdf.text('Date:',labelX,y); pdf.setFont('helvetica','italic');
const usDate = new Date().toLocaleDateString('en-US', {
month: 'long', // e.g. “May”
day: 'numeric', // e.g. “4”
year: 'numeric' // e.g. “2025”
});
pdf.text(usDate, valueX, y);
y += 40;
const footer=pdf.splitTextToSize(`Fraud Score calculated by: ${window.location.href}`,usableW);
pdf.text(footer,margin,y);
window.open(pdf.output('bloburl'),'_blank');
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
|