Spaces:
Running
Running
Update index.html
Browse files- index.html +16 -13
index.html
CHANGED
|
@@ -35,14 +35,14 @@ small{color:#93a3b1}
|
|
| 35 |
</div>
|
| 36 |
</main>
|
| 37 |
<script type="module">
|
| 38 |
-
import {
|
| 39 |
const $ = id => document.getElementById(id);
|
| 40 |
const MODEL = 'buildborderless/CommunityForensics-DeepfakeDet-ViT';
|
| 41 |
-
let
|
| 42 |
async function load(){
|
| 43 |
-
if(
|
| 44 |
-
|
| 45 |
-
|
| 46 |
}
|
| 47 |
const TOOLS = [[/midjourney/i,'Midjourney'],[/dall[\s\-路]?e|openai/i,'OpenAI / DALL路E'],[/stable\s?diffusion|sdxl|automatic1111/i,'Stable Diffusion'],[/firefly|generative ?fill/i,'Adobe Firefly'],[/imagen|gemini|synthid/i,'Google AI'],[/leonardo\.?ai/i,'Leonardo AI'],[/comfyui/i,'ComfyUI'],[/ideogram/i,'Ideogram']];
|
| 48 |
function markers(bytes){
|
|
@@ -62,20 +62,23 @@ $('f').onchange = async e => {
|
|
| 62 |
$('pct').textContent = ''; $('b').style.width = '0'; $('m').innerHTML = ''; $('raw').textContent = '';
|
| 63 |
try {
|
| 64 |
const mk = markers(new Uint8Array(await file.arrayBuffer()));
|
| 65 |
-
|
| 66 |
$('v').textContent = 'Checking...';
|
| 67 |
-
const
|
| 68 |
-
const
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
mk.forEach(t => { const li = document.createElement('li'); li.textContent = t; $('m').appendChild(li); });
|
| 73 |
if(mk.length) $('v').textContent = 'AI markers found';
|
| 74 |
-
else if(ai === null) $('v').textContent = 'Result below';
|
| 75 |
else if(ai >= 0.85) $('v').textContent = 'Likely AI-generated';
|
| 76 |
else if(ai >= 0.5) $('v').textContent = 'Possibly AI';
|
| 77 |
else $('v').textContent = 'Likely a real photo';
|
| 78 |
-
|
|
|
|
| 79 |
} catch(err){
|
| 80 |
$('v').textContent = 'Could not analyze this image.';
|
| 81 |
$('raw').textContent = String(err);
|
|
|
|
| 35 |
</div>
|
| 36 |
</main>
|
| 37 |
<script type="module">
|
| 38 |
+
import { AutoProcessor, AutoModelForImageClassification, RawImage } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3';
|
| 39 |
const $ = id => document.getElementById(id);
|
| 40 |
const MODEL = 'buildborderless/CommunityForensics-DeepfakeDet-ViT';
|
| 41 |
+
let processor, model;
|
| 42 |
async function load(){
|
| 43 |
+
if(model) return;
|
| 44 |
+
processor = await AutoProcessor.from_pretrained(MODEL);
|
| 45 |
+
model = await AutoModelForImageClassification.from_pretrained(MODEL, { dtype: 'fp32' });
|
| 46 |
}
|
| 47 |
const TOOLS = [[/midjourney/i,'Midjourney'],[/dall[\s\-路]?e|openai/i,'OpenAI / DALL路E'],[/stable\s?diffusion|sdxl|automatic1111/i,'Stable Diffusion'],[/firefly|generative ?fill/i,'Adobe Firefly'],[/imagen|gemini|synthid/i,'Google AI'],[/leonardo\.?ai/i,'Leonardo AI'],[/comfyui/i,'ComfyUI'],[/ideogram/i,'Ideogram']];
|
| 48 |
function markers(bytes){
|
|
|
|
| 62 |
$('pct').textContent = ''; $('b').style.width = '0'; $('m').innerHTML = ''; $('raw').textContent = '';
|
| 63 |
try {
|
| 64 |
const mk = markers(new Uint8Array(await file.arrayBuffer()));
|
| 65 |
+
await load();
|
| 66 |
$('v').textContent = 'Checking...';
|
| 67 |
+
const image = await RawImage.read(url);
|
| 68 |
+
const inputs = await processor(image);
|
| 69 |
+
const { logits } = await model(inputs);
|
| 70 |
+
const z = Array.from(logits.data);
|
| 71 |
+
let ai;
|
| 72 |
+
if(z.length === 1){ ai = 1 / (1 + Math.exp(-z[0])); }
|
| 73 |
+
else { const m = Math.max(...z), ex = z.map(v => Math.exp(v - m)), s = ex.reduce((a,b) => a + b, 0); ai = ex[1] / s; }
|
| 74 |
+
$('raw').textContent = 'Raw model score: ' + z.map(v => v.toFixed(2)).join(', ');
|
| 75 |
mk.forEach(t => { const li = document.createElement('li'); li.textContent = t; $('m').appendChild(li); });
|
| 76 |
if(mk.length) $('v').textContent = 'AI markers found';
|
|
|
|
| 77 |
else if(ai >= 0.85) $('v').textContent = 'Likely AI-generated';
|
| 78 |
else if(ai >= 0.5) $('v').textContent = 'Possibly AI';
|
| 79 |
else $('v').textContent = 'Likely a real photo';
|
| 80 |
+
$('pct').textContent = 'Chance it is AI: ' + Math.round(ai*100) + '%';
|
| 81 |
+
$('b').style.width = Math.round(ai*100) + '%';
|
| 82 |
} catch(err){
|
| 83 |
$('v').textContent = 'Could not analyze this image.';
|
| 84 |
$('raw').textContent = String(err);
|