Spaces:
Running
Running
File size: 2,743 Bytes
af4e59d 4d76dee af4e59d 4d76dee af4e59d 4d76dee af4e59d 4d76dee af4e59d 4d76dee af4e59d 4d76dee af4e59d 4d76dee af4e59d |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Image Checker</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>AI Image Checker</h1>
<form id="image-checker-form" enctype="multipart/form-data">
<div class="file-input">
<label for="image-upload">Upload an image to check if it's AI-generated:</label>
<input type="file" id="image-upload" name="image" accept="image/*" required>
</div>
<button type="submit">Check Image</button>
</form>
<div id="result" class="result"></div>
</div>
<script>
const form = document.getElementById('image-checker-form');
const resultDiv = document.getElementById('result');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const file = formData.get('image');
if (!file) {
resultDiv.textContent = 'Please upload an image.';
return;
}
resultDiv.textContent = 'Checking...';
try {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = async function () {
const base64Image = reader.result.split(',')[1]; // Get base64 image without metadata
const response = await fetch('https://api-inference.huggingface.co/models/Organika/sdxl-detector', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_HUGGINGFACE_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
inputs: base64Image,
options: {
wait_for_model: true
}
})
});
const result = await response.json();
if (response.ok) {
const isAI = result[0]?.label === "AI-generated";
if (isAI) {
resultDiv.textContent = "This image is AI-generated.";
} else {
resultDiv.textContent = "This image is not AI-generated.";
}
} else {
resultDiv.textContent = "Error occurred: " + result.error;
}
};
} catch (error) {
resultDiv.textContent = "Error occurred while checking the image.";
}
});
</script>
</body>
</html> |