Spaces:
Runtime error
Runtime error
Create index.html
Browse files- index.html +116 -0
index.html
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Deepfake Detection</title>
|
5 |
+
<style>
|
6 |
+
body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
|
7 |
+
.upload-container { border: 2px dashed #ccc; padding: 20px; text-align: center; margin-bottom: 20px; }
|
8 |
+
#preview { max-width: 100%; margin-top: 10px; display: none; }
|
9 |
+
#results { margin-top: 20px; padding: 15px; border-radius: 5px; display: none; }
|
10 |
+
.real { background-color: #d4edda; color: #155724; }
|
11 |
+
.fake { background-color: #f8d7da; color: #721c24; }
|
12 |
+
.progress { display: none; margin: 10px 0; }
|
13 |
+
</style>
|
14 |
+
</head>
|
15 |
+
<body>
|
16 |
+
<h1>Deepfake Detection</h1>
|
17 |
+
<p>Upload an image to check if it's real or AI-generated</p>
|
18 |
+
|
19 |
+
<div class="upload-container">
|
20 |
+
<input type="file" id="fileInput" accept="image/*">
|
21 |
+
<p>or drag and drop image here</p>
|
22 |
+
<img id="preview" alt="Image preview">
|
23 |
+
</div>
|
24 |
+
|
25 |
+
<div class="progress" id="progress">
|
26 |
+
Analyzing image... <progress></progress>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
<div id="results"></div>
|
30 |
+
|
31 |
+
<script>
|
32 |
+
const fileInput = document.getElementById('fileInput');
|
33 |
+
const preview = document.getElementById('preview');
|
34 |
+
const resultsDiv = document.getElementById('results');
|
35 |
+
const progressDiv = document.getElementById('progress');
|
36 |
+
|
37 |
+
fileInput.addEventListener('change', function(e) {
|
38 |
+
const file = e.target.files[0];
|
39 |
+
if (file) {
|
40 |
+
handleFile(file);
|
41 |
+
}
|
42 |
+
});
|
43 |
+
|
44 |
+
// Handle drag and drop
|
45 |
+
document.addEventListener('dragover', function(e) {
|
46 |
+
e.preventDefault();
|
47 |
+
document.querySelector('.upload-container').style.borderColor = '#666';
|
48 |
+
});
|
49 |
+
|
50 |
+
document.addEventListener('dragleave', function() {
|
51 |
+
document.querySelector('.upload-container').style.borderColor = '#ccc';
|
52 |
+
});
|
53 |
+
|
54 |
+
document.addEventListener('drop', function(e) {
|
55 |
+
e.preventDefault();
|
56 |
+
document.querySelector('.upload-container').style.borderColor = '#ccc';
|
57 |
+
if (e.dataTransfer.files.length) {
|
58 |
+
handleFile(e.dataTransfer.files[0]);
|
59 |
+
}
|
60 |
+
});
|
61 |
+
|
62 |
+
function handleFile(file) {
|
63 |
+
if (!file.type.match('image.*')) {
|
64 |
+
alert('Please upload an image file');
|
65 |
+
return;
|
66 |
+
}
|
67 |
+
|
68 |
+
// Show preview
|
69 |
+
const reader = new FileReader();
|
70 |
+
reader.onload = function(e) {
|
71 |
+
preview.src = e.target.result;
|
72 |
+
preview.style.display = 'block';
|
73 |
+
analyzeImage(file);
|
74 |
+
};
|
75 |
+
reader.readAsDataURL(file);
|
76 |
+
}
|
77 |
+
|
78 |
+
async function analyzeImage(file) {
|
79 |
+
progressDiv.style.display = 'block';
|
80 |
+
resultsDiv.style.display = 'none';
|
81 |
+
|
82 |
+
const formData = new FormData();
|
83 |
+
formData.append('file', file);
|
84 |
+
|
85 |
+
try {
|
86 |
+
const response = await fetch('http://localhost:5000/detect', {
|
87 |
+
method: 'POST',
|
88 |
+
body: formData
|
89 |
+
});
|
90 |
+
|
91 |
+
const data = await response.json();
|
92 |
+
|
93 |
+
if (data.error) {
|
94 |
+
throw new Error(data.error);
|
95 |
+
}
|
96 |
+
|
97 |
+
// Display results
|
98 |
+
resultsDiv.className = data.result.toLowerCase();
|
99 |
+
resultsDiv.innerHTML = `
|
100 |
+
<h2>Result: ${data.result} (${data.confidence}% confidence)</h2>
|
101 |
+
<p>Real probability: ${data.real_probability}%</p>
|
102 |
+
<p>Fake probability: ${data.fake_probability}%</p>
|
103 |
+
`;
|
104 |
+
resultsDiv.style.display = 'block';
|
105 |
+
|
106 |
+
} catch (error) {
|
107 |
+
resultsDiv.className = '';
|
108 |
+
resultsDiv.innerHTML = `<p>Error: ${error.message}</p>`;
|
109 |
+
resultsDiv.style.display = 'block';
|
110 |
+
} finally {
|
111 |
+
progressDiv.style.display = 'none';
|
112 |
+
}
|
113 |
+
}
|
114 |
+
</script>
|
115 |
+
</body>
|
116 |
+
</html>
|