goldenbrown commited on
Commit
4b51510
1 Parent(s): e46249a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +47 -18
index.html CHANGED
@@ -20,31 +20,60 @@
20
  </div>
21
 
22
  <script>
23
- const form = document.getElementById('image-checker-form');
24
- const resultDiv = document.getElementById('result');
25
 
26
- form.addEventListener('submit', async (e) => {
27
- e.preventDefault();
28
-
29
- const formData = new FormData(form);
30
- resultDiv.textContent = 'Checking...';
31
 
32
- try {
33
- const response = await fetch('your_model_endpoint', {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  method: 'POST',
35
- body: formData
 
 
 
 
 
 
 
 
 
36
  });
37
 
38
  const result = await response.json();
39
- if (result.is_ai_generated) {
40
- resultDiv.textContent = "This image is AI-generated.";
 
 
 
 
 
 
41
  } else {
42
- resultDiv.textContent = "This image is not AI-generated.";
43
  }
44
- } catch (error) {
45
- resultDiv.textContent = "Error occurred while checking the image.";
46
- }
47
- });
48
- </script>
 
49
  </body>
50
  </html>
 
20
  </div>
21
 
22
  <script>
23
+ const form = document.getElementById('image-checker-form');
24
+ const resultDiv = document.getElementById('result');
25
 
26
+ form.addEventListener('submit', async (e) => {
27
+ e.preventDefault();
 
 
 
28
 
29
+ const formData = new FormData(form);
30
+ const file = formData.get('image');
31
+
32
+ if (!file) {
33
+ resultDiv.textContent = 'Please upload an image.';
34
+ return;
35
+ }
36
+
37
+ resultDiv.textContent = 'Checking...';
38
+
39
+ try {
40
+ const reader = new FileReader();
41
+ reader.readAsDataURL(file);
42
+
43
+ reader.onloadend = async function () {
44
+ const base64Image = reader.result.split(',')[1]; // Get base64 image without metadata
45
+
46
+ const response = await fetch('https://api-inference.huggingface.co/models/Organika/sdxl-detector', {
47
  method: 'POST',
48
+ headers: {
49
+ 'Authorization': 'Bearer YOUR_HUGGINGFACE_API_KEY',
50
+ 'Content-Type': 'application/json'
51
+ },
52
+ body: JSON.stringify({
53
+ inputs: base64Image,
54
+ options: {
55
+ wait_for_model: true
56
+ }
57
+ })
58
  });
59
 
60
  const result = await response.json();
61
+
62
+ if (response.ok) {
63
+ const isAI = result[0]?.label === "AI-generated";
64
+ if (isAI) {
65
+ resultDiv.textContent = "This image is AI-generated.";
66
+ } else {
67
+ resultDiv.textContent = "This image is not AI-generated.";
68
+ }
69
  } else {
70
+ resultDiv.textContent = "Error occurred: " + result.error;
71
  }
72
+ };
73
+ } catch (error) {
74
+ resultDiv.textContent = "Error occurred while checking the image.";
75
+ }
76
+ });
77
+ </script>
78
  </body>
79
  </html>