genai-reward / templates /index.html
TheFrenchDemos's picture
Initial commit
9705a2a
<!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>