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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE html>
<html>
<head>
    <title>Reward Simulator</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
    <style>
        html {
            scroll-behavior: smooth;
        }
        .metric-row {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            padding: 4px;
            margin: 2px 0;
            font-family: monospace;
            font-size: 12px;
            align-items: center;
        }
        .metric-label {
            flex: 1 1 auto;
            text-align: left;
            padding-right: 5px;
            min-width: 150px;
        }
        .metric-value {
            flex: 0 0 60px;
            text-align: right;
            font-weight: 500;
        }
        .result-card {
            margin-bottom: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        .preset-image-container {
            width: 100%;
            position: relative;
            overflow: hidden;
        }
        .preset-image {
            cursor: pointer;
            transition: transform 0.2s;
            width: 100%;
            height: auto;
            max-height: none;
            object-fit: contain;
        }
        .preset-image:hover {
            transform: scale(1.05);
        }
        .dropzone {
            border: 2px dashed #ccc;
            border-radius: 4px;
            padding: 20px;
            text-align: center;
            background: #f8f9fa;
            margin: 20px 0;
        }
        .dropzone.dragover {
            background: #e9ecef;
            border-color: #0d6efd;
        }
        [data-tooltip] {
            position: relative;
            cursor: help;
        }
        [data-tooltip]:hover:after {
            content: attr(data-tooltip);
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            background: #333;
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            white-space: pre-wrap;
            width: 200px;
            z-index: 1000;
        }
        .image-caption {
            font-style: italic;
            font-size: 0.8rem;
            color: #666;
            margin-top: 5px;
            text-align: center;
        }
        .loading-container {
            text-align: center;
            padding: 40px;
            background: #f8f9fa;
            border-radius: 8px;
            margin: 20px 0;
        }
        .loading-spinner {
            width: 3rem;
            height: 3rem;
            margin-bottom: 1rem;
        }
        .loading-text {
            color: #6c757d;
            font-size: 1.1rem;
        }

        .preview-image {
            max-height: 400px;
            width: auto;
            display: block;
            margin: 0 auto;
        }
        .result-image {
            cursor: pointer;
            transition: transform 0.2s;
            max-height: 150px;
            object-fit: contain;
        }
        .result-image:hover {
            transform: scale(1.05);
        }

        @media (max-width: 768px) {
            .preset-image-container {
                width: 100%;
                padding-bottom: 100%; /* Creates a square aspect ratio */
                position: relative;
            }
            .preset-image {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
            .result-card {
                flex-direction: column !important;
            }
            .result-card .image-container {
                flex-basis: 100% !important;
                max-width: 100% !important;
                margin-bottom: 15px;
            }
            .result-card .metrics-container {
                flex-basis: 100% !important;
                max-width: 100% !important;
                padding-left: 0 !important;
            }
            .result-card img {
                max-height: 200px !important;
                width: 100%;
                object-fit: cover;
            }
            .col-md-4 {
                margin-bottom: 20px;
            }
            #previewContainer {
                margin-bottom: 20px;
                text-align: center;
            }
            #imagePreview {
                max-width: 100%;
                height: auto;
                margin: 0 auto;
            }
            .sticky-top {
                position: relative !important;
            }
        }
    </style>
</head>
<body>
    <div class="container mt-4">
        <h1>Reward Simulator</h1>
        
        <div class="row mt-4">
            <!-- Preset Images -->
            <div class="col-12 mb-4">
                <h5>Select an AI-generated image</h5>
                <div class="row">
                    <div class="col-md-4">
                        <div class="preset-image-container">
                            <img src="/static/1.webp" class="preset-image" 
                                 onclick="selectPreset(1)" alt="Preset 1">
                        </div>
                        <div class="image-caption">A vibrant red rose in full bloom, macro photograph</div>
                    </div>
                    <div class="col-md-4">
                        <div class="preset-image-container">
                            <img src="/static/2.webp" class="preset-image" 
                                 onclick="selectPreset(2)" alt="Preset 2">
                        </div>
                        <div class="image-caption">Fluffy orange cat with green eyes, close-up portrait</div>
                    </div>
                    <div class="col-md-4">
                        <div class="preset-image-container">
                            <img src="/static/3.webp" class="preset-image" 
                                 onclick="selectPreset(3)" alt="Preset 3">
                        </div>
                        <div class="image-caption">Underwater scene featuring fish swimming among aquatic plants, realistic, 4k</div>
                    </div>
                </div>
            </div>

            <!-- Upload Zone -->
            <div class="col-12 mb-4">
                <div class="dropzone" id="dropzone">
                    <p>Or drag and drop an image here</p>
                    <input type="file" id="fileInput" class="form-control" accept="image/*" hidden>
                    <button class="btn btn-outline-primary" onclick="document.getElementById('fileInput').click()">
                        Select File
                    </button>
                </div>
            </div>

            <!-- Parameters -->
            <div class="col-12 mb-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <button class="btn btn-link w-100 text-start text-decoration-none" 
                                    type="button" 
                                    data-bs-toggle="collapse" 
                                    data-bs-target="#parametersCollapse" 
                                    aria-expanded="false" 
                                    aria-controls="parametersCollapse">
                                <i class="bi bi-gear"></i> Advanced Parameters
                            </button>
                        </h5>
                    </div>
                    <div class="collapse" id="parametersCollapse">
                        <div class="card-body">
                            <form id="imageForm">
                                <div id="parametersContainer">
                                    <!-- Will be populated by JavaScript -->
                                </div>
                                <button type="submit" class="btn btn-primary">Update</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Results -->
            <div class="col-12">
                <div class="row">
                    <div id="previewContainer" class="col-md-3" style="display: none;">
                        <div class="sticky-top pt-3">
                            <img id="imagePreview" class="img-fluid mb-3 preview-image">
                        </div>
                    </div>
                    <div id="results" class="col-md-9">
                        <!-- Will be populated by JavaScript -->
                    </div>
                </div>
            </div>
        </div>

        <!-- Helper Section -->
        <div class="row mt-5">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h5>Learn more</h5>
                    </div>
                    <div class="card-body">

                        <h6>How it works</h6>
                        <ol>
                            <li>Select or upload an image that represents AI-generated content</li>
                            <li>The system finds similar images that might have influenced the generation in a database of 10M images (Open Images)</li>
                            <li>Based on your parameters, it calculates potential rewards for:
                                <ul>
                                    <li>Original image authors</li>
                                    <li>Rights owners (e.g., stock photo companies, galleries)</li>
                                </ul>
                            </li>
                        </ol>

                        <h6>Warning</h6>
                        <ol>
                            <li>This demonstrator calculates similarities using the Open Images database alone. However, the image generators do not specify whether they have been trained with datasets from this database. As a result, calculations can be more or less biased depending on the generator used.</li>
                            <li>Furthermore, the infrastructures used are designed for limited use. More generally, this demonstrator is proposed for teaching and academic purposes. Its designers decline all responsibility for the relevance of the results, as well as for the user experience, which are provided without guarantee.</li>
                        </ol>

                        <h6 class="mt-4">Key assumptions</h6>
                        <ul>
                            <li>Attribution scores indicate the level of influence of training images</li>
                            <li>Rewards are distributed based on subscription revenue</li>
                            <li>Calculations use simplified models and are for demonstration purposes</li>
                        </ul>

                        <h6 class="mt-4">Use cases</h6>
                        <ul>
                            <li>Explore fair compensation models for AI training data</li>
                            <li>Simulate different revenue sharing scenarios</li>
                            <li>Understand the relationship between model training and attribution</li>
                        </ul>

                        <h6 class="mt-4">Technical details</h6>
                        <p class="small">
                            Image similarity search powered by DINOv2 and FAISS.
                            DINOv2 is used to extract image features of all the images in the database (10M images from Open Images).
                            FAISS is used to perform efficient similarity search to find the most similar images to the input image, and output the attribution scores.
                            <ul class="small text-muted">
                                <li><a href="https://github.com/facebookresearch/dinov2" target="_blank">DINOv2</a> - Vision transformer for image feature extraction</li>
                                <li><a href="https://github.com/facebookresearch/faiss" target="_blank">FAISS</a> - Efficient similarity search library, more specifically:
                                    <ul>
                                        <li>HNSW (Hierarchical Navigable Small World) for approximate nearest neighbor search</li>
                                        <li>PQ (Product Quantization) for memory-efficient vector compression</li>
                                    </ul>
                                </li>
                            </ul>
                        </p>

                        <div class="d-flex flex-wrap gap-3 mb-4">
                            <a href="/static/ia_gen_droits_auteur.pdf" class="btn btn-outline-primary" download>
                                <i class="bi bi-file-earmark-pdf"></i> <span id="downloadReportText">Download the Controv3rse report</span>
                            </a>
                            <a href="/static/Reg_Summary.pdf" class="btn btn-outline-primary" download>
                                <i class="bi bi-file-earmark-pdf"></i> Regulatory Summary
                            </a>
                            <a href="/static/RO_Summary.pdf" class="btn btn-outline-primary" download>
                                <i class="bi bi-file-earmark-pdf"></i> Rights Owners Summary
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Footer Section -->
        <div class="row mt-5">
            <div class="col-12">
                <footer>
                    <p class="text-center text-muted">
                        &copy; 2025 Reward Simulator. Apache 2.0.
                    </p>
                </footer>
            </div>
        </div>
    </div>

    <script src="/static/js/parameters.js"></script>
    <script>
        // Add this new function at the beginning of your script section
        function scrollToResults() {
            const resultsDiv = document.getElementById('results');
            if (resultsDiv) {
                resultsDiv.scrollIntoView({ behavior: 'smooth', block: 'start' });
            }
        }

        // Add this at the beginning of your script section
        function initializeParameters() {
            const container = document.getElementById('parametersContainer');
            Object.entries(PARAMETERS).forEach(([key, param]) => {
                container.innerHTML += `
                    <div class="mb-3">
                        <label class="form-label" data-tooltip="${param.tooltip}">${param.label}</label>
                        <input type="number" class="form-control" name="${key}" value="${param.defaultValue}">
                    </div>
                `;
            });
        }

        // Call this when the document loads
        document.addEventListener('DOMContentLoaded', () => {
            initializeParameters();
            // Check if URL has a hash to prevent unwanted scrolling
            if (!window.location.hash) {
                window.scrollTo(0, 0);
            }
        });

        // Process image with default or custom parameters
        async function processImage(imageData, useDefaultParams = true) {
            const resultsDiv = document.getElementById('results');
            resultsDiv.innerHTML = `
                <div class="loading-container">
                    <div class="spinner-border loading-spinner text-primary" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                    <div class="loading-text">Processing image...</div>
                </div>`;
            
            // Scroll to results immediately when processing starts
            setTimeout(scrollToResults, 100);
            
            try {
                const formData = new FormData();
                
                if (imageData instanceof Blob) {
                    formData.append('image', imageData, 'image.jpg');
                } else if (typeof imageData === 'number') {
                    // For preset images, use the preset endpoint
                    const response = await fetch(`/select_preset/${imageData}`);
                    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
                    const data = await response.json();
                    updateResults(data);
                    return;
                }
                
                if (!useDefaultParams) {
                    // Add form parameters if not using defaults
                    const form = document.getElementById('imageForm');
                    const formElements = new FormData(form);
                    for (let [key, value] of formElements.entries()) {
                        formData.append(key, value);
                    }
                }

                const response = await fetch('/process', {
                    method: 'POST',
                    body: formData
                });
                
                if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
                const data = await response.json();
                updateResults(data);
                
            } catch (error) {
                console.error('Error:', error);
                resultsDiv.innerHTML = `
                    <div class="alert alert-danger" role="alert">
                        <i class="bi bi-exclamation-triangle me-2"></i>
                        Error: ${error.message}
                    </div>`;
            }
        }

        // Update results display - remove the scroll behavior from here
        function updateResults(data) {
            if (!data || !data.results || !Array.isArray(data.results)) {
                throw new Error('Invalid response format from server');
            }
            
            const selectedImage = document.getElementById('imagePreview');
            document.getElementById('results').innerHTML = `
                ${data.results.map((result, i) => `
                    <div class="result-card d-flex flex-row">
                        <div class="image-container" style="flex-basis: 25%; max-width: 25%;">
                            <a href="${result.other.flickr_url}" target="_blank">
                                <img src="${result.image_url}" class="img-fluid result-image" alt="Similar image ${i+1}">
                            </a>
                        </div>
                        <div class="metrics-container" style="flex-basis: 75%; max-width: 75%; padding-left: 20px;">
                            <div class="metric-row">
                                <span class="metric-label">Attribution:</span>
                                <span class="metric-value">${result.rewards.attribution}</span>
                            </div>
                            <div class="metric-row">
                                <span class="metric-label">Author Monthly Reward:</span>
                                <span class="metric-value">${result.rewards.author_month_reward}</span>
                            </div>
                            <div class="metric-row">
                                <span class="metric-label">Right Owner Monthly Reward:</span>
                                <span class="metric-value">${result.rewards.ro_month_reward}</span>
                            </div>
                            <div class="metric-row">
                                <span class="metric-label">Author:</span>
                                <span class="metric-value">${result.other.realname || result.other.username}</span>
                            </div>
                        </div>
                    </div>
                `).join('')}
            `;
        }

        // Preset image selection handler
        function selectPreset(presetNumber) {
            document.getElementById('imagePreview').src = `/static/${presetNumber}.webp`;
            document.getElementById('previewContainer').style.display = 'block';
            processImage(presetNumber);
        }

        // File input handler
        document.getElementById('fileInput').addEventListener('change', (e) => {
            const file = e.target.files[0];
            if (file && file.type.startsWith('image/')) {
                const reader = new FileReader();
                reader.onload = (event) => {
                    document.getElementById('imagePreview').src = event.target.result;
                    document.getElementById('previewContainer').style.display = 'block';
                    // Process image immediately with default parameters
                    fetch(event.target.result)
                        .then(res => res.blob())
                        .then(blob => processImage(blob));
                };
                reader.readAsDataURL(file);
            }
        });

        // Form submit handler for custom parameters
        document.getElementById('imageForm').onsubmit = async (e) => {
            e.preventDefault();
            const imagePreview = document.getElementById('imagePreview');
            if (imagePreview && imagePreview.src) {
                const response = await fetch(imagePreview.src);
                const blob = await response.blob();
                processImage(blob, false);  // Process with custom parameters
            }
        };

        const dropzone = document.getElementById('dropzone');
        dropzone.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropzone.classList.add('dragover');
        });
        dropzone.addEventListener('dragleave', () => {
            dropzone.classList.remove('dragover');
        });
        dropzone.addEventListener('drop', (e) => {
            e.preventDefault();
            dropzone.classList.remove('dragover');
            const file = e.dataTransfer.files[0];
            if (file && file.type.startsWith('image/')) {
                const reader = new FileReader();
                reader.onload = (event) => {
                    document.getElementById('imagePreview').src = event.target.result;
                    document.getElementById('previewContainer').style.display = 'block';
                    // Process image immediately with default parameters
                    fetch(event.target.result)
                        .then(res => res.blob())
                        .then(blob => processImage(blob));
                };
                reader.readAsDataURL(file);
            }
        });
    </script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>