Spaces:
Runtime error
Runtime error
Commit
·
d065b18
1
Parent(s):
d9d5d76
Update templates/index.html
Browse filesla version précédente avait supprimé l'affichage des deux fois trois images.
- templates/index.html +155 -23
templates/index.html
CHANGED
@@ -1,49 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<script>
|
2 |
let file1 = null;
|
3 |
let file2 = null;
|
4 |
|
5 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
const reader = new FileReader();
|
7 |
reader.onload = (event) => {
|
8 |
-
|
9 |
-
document.getElementById(previewId).innerHTML = `
|
10 |
<img src="${event.target.result}" class="preview-image"/>
|
11 |
`;
|
12 |
};
|
13 |
-
reader.readAsDataURL(
|
14 |
-
|
15 |
-
// Vérifie si les deux images sont sélectionnées pour afficher le bouton
|
16 |
-
checkReadyToCompare();
|
17 |
}
|
18 |
|
19 |
document.getElementById('fileInput1').addEventListener('change', (e) => {
|
20 |
file1 = e.target.files[0];
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
});
|
25 |
|
26 |
document.getElementById('fileInput2').addEventListener('change', (e) => {
|
27 |
file2 = e.target.files[0];
|
28 |
-
|
29 |
-
|
30 |
-
}
|
31 |
});
|
32 |
|
33 |
function checkReadyToCompare() {
|
34 |
-
const
|
35 |
if (file1 && file2) {
|
36 |
-
|
37 |
-
<button class="btn btn-primary" onclick="processImages()">Compare Images</button>
|
38 |
`;
|
39 |
} else {
|
40 |
-
|
41 |
}
|
42 |
}
|
43 |
|
44 |
async function processImages() {
|
45 |
if (!file1 || !file2) {
|
46 |
-
alert('Please select two images first
|
47 |
return;
|
48 |
}
|
49 |
|
@@ -54,10 +184,8 @@
|
|
54 |
const resultsDiv = document.getElementById('results');
|
55 |
resultsDiv.innerHTML = `
|
56 |
<div class="loading-container">
|
57 |
-
<div class="spinner-border
|
58 |
-
|
59 |
-
</div>
|
60 |
-
<div class="loading-text">Processing images...</div>
|
61 |
</div>`;
|
62 |
|
63 |
try {
|
@@ -82,8 +210,12 @@
|
|
82 |
console.error('Error:', error);
|
83 |
resultsDiv.innerHTML = `
|
84 |
<div class="alert alert-danger" role="alert">
|
85 |
-
|
86 |
</div>`;
|
87 |
}
|
88 |
}
|
89 |
</script>
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>Compare Two Images</title>
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
8 |
+
<style>
|
9 |
+
.preset-image-container {
|
10 |
+
width: 100%;
|
11 |
+
overflow: hidden;
|
12 |
+
margin-bottom: 10px;
|
13 |
+
}
|
14 |
+
.preset-image {
|
15 |
+
width: 100%;
|
16 |
+
height: auto;
|
17 |
+
cursor: pointer;
|
18 |
+
transition: transform 0.2s;
|
19 |
+
border-radius: 8px;
|
20 |
+
}
|
21 |
+
.preset-image:hover {
|
22 |
+
transform: scale(1.05);
|
23 |
+
}
|
24 |
+
.dropzone {
|
25 |
+
border: 2px dashed #ccc;
|
26 |
+
padding: 20px;
|
27 |
+
text-align: center;
|
28 |
+
margin-top: 10px;
|
29 |
+
border-radius: 8px;
|
30 |
+
background-color: #f9f9f9;
|
31 |
+
}
|
32 |
+
.preview-image {
|
33 |
+
width: 100%;
|
34 |
+
height: auto;
|
35 |
+
margin-top: 10px;
|
36 |
+
border-radius: 8px;
|
37 |
+
}
|
38 |
+
.loading-container {
|
39 |
+
text-align: center;
|
40 |
+
margin-top: 20px;
|
41 |
+
}
|
42 |
+
.loading-text {
|
43 |
+
margin-top: 10px;
|
44 |
+
font-size: 18px;
|
45 |
+
color: #555;
|
46 |
+
}
|
47 |
+
</style>
|
48 |
+
</head>
|
49 |
+
|
50 |
+
<body>
|
51 |
+
<div class="container my-4">
|
52 |
+
<h1 class="text-center">Compare Two Images</h1>
|
53 |
+
|
54 |
+
<div class="row mt-4">
|
55 |
+
|
56 |
+
<!-- Column 1: Original Image -->
|
57 |
+
<div class="col-md-6">
|
58 |
+
<h5 class="text-center">Select Original Image</h5>
|
59 |
+
<div class="row">
|
60 |
+
<div class="col-4">
|
61 |
+
<div class="preset-image-container">
|
62 |
+
<img src="/static/1.webp" class="preset-image" onclick="selectPreset(1, 1)" alt="Original 1">
|
63 |
+
</div>
|
64 |
+
</div>
|
65 |
+
<div class="col-4">
|
66 |
+
<div class="preset-image-container">
|
67 |
+
<img src="/static/2.webp" class="preset-image" onclick="selectPreset(2, 1)" alt="Original 2">
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
<div class="col-4">
|
71 |
+
<div class="preset-image-container">
|
72 |
+
<img src="/static/3.webp" class="preset-image" onclick="selectPreset(3, 1)" alt="Original 3">
|
73 |
+
</div>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
<div class="dropzone" id="dropzone1">
|
77 |
+
<p>Or drag and drop an image here</p>
|
78 |
+
<input type="file" id="fileInput1" accept="image/*" hidden>
|
79 |
+
<button class="btn btn-outline-primary" onclick="document.getElementById('fileInput1').click()">Upload Original</button>
|
80 |
+
</div>
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<!-- Column 2: AI Generated Image -->
|
84 |
+
<div class="col-md-6">
|
85 |
+
<h5 class="text-center">Select AI Generated Image</h5>
|
86 |
+
<div class="row">
|
87 |
+
<div class="col-4">
|
88 |
+
<div class="preset-image-container">
|
89 |
+
<img src="/static/4.webp" class="preset-image" onclick="selectPreset(4, 2)" alt="AI 1">
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
<div class="col-4">
|
93 |
+
<div class="preset-image-container">
|
94 |
+
<img src="/static/5.webp" class="preset-image" onclick="selectPreset(5, 2)" alt="AI 2">
|
95 |
+
</div>
|
96 |
+
</div>
|
97 |
+
<div class="col-4">
|
98 |
+
<div class="preset-image-container">
|
99 |
+
<img src="/static/6.webp" class="preset-image" onclick="selectPreset(6, 2)" alt="AI 3">
|
100 |
+
</div>
|
101 |
+
</div>
|
102 |
+
</div>
|
103 |
+
<div class="dropzone" id="dropzone2">
|
104 |
+
<p>Or drag and drop an image here</p>
|
105 |
+
<input type="file" id="fileInput2" accept="image/*" hidden>
|
106 |
+
<button class="btn btn-outline-primary" onclick="document.getElementById('fileInput2').click()">Upload AI Image</button>
|
107 |
+
</div>
|
108 |
+
</div>
|
109 |
+
|
110 |
+
</div>
|
111 |
+
|
112 |
+
<!-- Compare Button -->
|
113 |
+
<div id="compareButtonContainer" class="text-center my-4"></div>
|
114 |
+
|
115 |
+
<!-- Result -->
|
116 |
+
<div id="results" class="mt-5"></div>
|
117 |
+
|
118 |
+
</div>
|
119 |
+
|
120 |
+
<!-- Scripts -->
|
121 |
<script>
|
122 |
let file1 = null;
|
123 |
let file2 = null;
|
124 |
|
125 |
+
function selectPreset(presetNumber, target) {
|
126 |
+
fetch(`/static/${presetNumber}.webp`)
|
127 |
+
.then(res => res.blob())
|
128 |
+
.then(blob => {
|
129 |
+
const file = new File([blob], `preset${presetNumber}.webp`, { type: blob.type });
|
130 |
+
if (target === 1) {
|
131 |
+
file1 = file;
|
132 |
+
updatePreview('dropzone1', blob);
|
133 |
+
} else {
|
134 |
+
file2 = file;
|
135 |
+
updatePreview('dropzone2', blob);
|
136 |
+
}
|
137 |
+
})
|
138 |
+
.then(() => checkReadyToCompare());
|
139 |
+
}
|
140 |
+
|
141 |
+
function updatePreview(dropzoneId, blob) {
|
142 |
const reader = new FileReader();
|
143 |
reader.onload = (event) => {
|
144 |
+
document.getElementById(dropzoneId).innerHTML = `
|
|
|
145 |
<img src="${event.target.result}" class="preview-image"/>
|
146 |
`;
|
147 |
};
|
148 |
+
reader.readAsDataURL(blob);
|
|
|
|
|
|
|
149 |
}
|
150 |
|
151 |
document.getElementById('fileInput1').addEventListener('change', (e) => {
|
152 |
file1 = e.target.files[0];
|
153 |
+
updatePreview('dropzone1', file1);
|
154 |
+
checkReadyToCompare();
|
|
|
155 |
});
|
156 |
|
157 |
document.getElementById('fileInput2').addEventListener('change', (e) => {
|
158 |
file2 = e.target.files[0];
|
159 |
+
updatePreview('dropzone2', file2);
|
160 |
+
checkReadyToCompare();
|
|
|
161 |
});
|
162 |
|
163 |
function checkReadyToCompare() {
|
164 |
+
const container = document.getElementById('compareButtonContainer');
|
165 |
if (file1 && file2) {
|
166 |
+
container.innerHTML = `
|
167 |
+
<button class="btn btn-primary btn-lg" onclick="processImages()">Compare Images</button>
|
168 |
`;
|
169 |
} else {
|
170 |
+
container.innerHTML = '';
|
171 |
}
|
172 |
}
|
173 |
|
174 |
async function processImages() {
|
175 |
if (!file1 || !file2) {
|
176 |
+
alert('Please select two images first!');
|
177 |
return;
|
178 |
}
|
179 |
|
|
|
184 |
const resultsDiv = document.getElementById('results');
|
185 |
resultsDiv.innerHTML = `
|
186 |
<div class="loading-container">
|
187 |
+
<div class="spinner-border text-primary" role="status"></div>
|
188 |
+
<div class="loading-text">Processing...</div>
|
|
|
|
|
189 |
</div>`;
|
190 |
|
191 |
try {
|
|
|
210 |
console.error('Error:', error);
|
211 |
resultsDiv.innerHTML = `
|
212 |
<div class="alert alert-danger" role="alert">
|
213 |
+
${error.message}
|
214 |
</div>`;
|
215 |
}
|
216 |
}
|
217 |
</script>
|
218 |
+
|
219 |
+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
|
220 |
+
</body>
|
221 |
+
</html>
|