Jayce-Ping's picture
Add files using upload-large-folder tool
436c9ff verified
raw
history blame
8.69 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Ranking</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.rank-btn {
padding: 5px 15px;
cursor: pointer;
border: 2px solid #4CAF50;
background-color: white;
color: #4CAF50;
border-radius: 4px;
font-weight: bold;
min-width: 60px;
}
.rank-btn.ranked {
background-color: #4CAF50;
color: white;
border-color: #4CAF50;
}
.rank-btn:hover {
opacity: 0.8;
}
.submit-btn {
margin-top: 20px;
padding: 10px 30px;
background-color: #2196F3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.submit-btn:hover {
background-color: #0b7dda;
}
.submit-btn:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
.show-annotation-btn {
margin-top: 10px;
padding: 8px 20px;
background-color: #FF9800;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.show-annotation-btn:hover {
background-color: #F57C00;
}
.annotation-status {
display: inline-block;
margin-left: 15px;
padding: 5px 12px;
background-color: #4CAF50;
color: white;
border-radius: 4px;
font-size: 14px;
font-weight: bold;
}
/* 消息提示样式 */
.message-box {
position: fixed;
top: 20px;
right: 20px;
padding: 15px 25px;
border-radius: 4px;
font-size: 16px;
font-weight: bold;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1000;
display: none;
animation: slideIn 0.3s ease-out;
}
.message-box.success {
background-color: #4CAF50;
color: white;
}
.message-box.error {
background-color: #f44336;
color: white;
}
.message-box.show {
display: block;
}
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
.message-box.hiding {
animation: slideOut 0.3s ease-out;
}
/* 固定在右上角的分页条 */
.page-control {
position: fixed;
top: 20px;
right: 20px;
background: rgba(255,255,255,0.9);
border: 1px solid #ddd;
padding: 8px 12px;
border-radius: 6px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
z-index: 999;
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
}
.page-control input {
width: 60px;
padding: 3px 5px;
border: 1px solid #ccc;
border-radius: 4px;
}
.page-control button {
padding: 4px 8px;
background-color: #2196F3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.page-control button:hover {
background-color: #0b7dda;
}
</style>
<script>
let rankCounter = 1;
const rankedImages = new Map();
let allCompareImages = [];
function initializeCompareImages() {
allCompareImages = [];
const rankButtons = document.querySelectorAll('.rank-btn');
rankButtons.forEach(btn => {
const imagePath = btn.getAttribute('data-image');
const filename = imagePath.split('/').pop();
if (!allCompareImages.includes(filename)) {
allCompareImages.push(filename);
}
});
}
window.addEventListener('DOMContentLoaded', function() {
initializeCompareImages();
});
/* 这里省略 rankImage、loadExistingAnnotation、showMessage、submitRanking 的原有实现 */
/* ... 你的原始脚本保持不变 ... */
// 新增跳转函数
function jumpToPage(event) {
event.preventDefault();
const input = document.getElementById('pageInput');
let page = parseInt(input.value);
if (isNaN(page) || page < 1) page = 1;
if (page > {{ total_pages }}) page = {{ total_pages }};
window.location.href = "/?page=" + page;
return false;
}
</script>
</head>
<body>
<!-- 消息提示框 -->
<div id="messageBox" class="message-box"></div>
<!-- 固定在右上角的分页控制条 -->
<div class="page-control">
<span>{{ page }}/{{ total_pages }}</span>
<form id="pageJumpForm" onsubmit="return jumpToPage(event)" style="display:inline;">
<input type="number" id="pageInput" min="1" max="{{ total_pages }}" value="{{ page }}">
<button type="submit">跳转</button>
</form>
</div>
<h1>Image Ranking</h1>
<form id="rankingForm" action="/sort" method="POST" onsubmit="return submitRanking(event)">
{% for item in data %}
<div>
{% if item.prompt %}
<div style="background-color: #f0f0f0; padding: 15px; margin-bottom: 20px; border-radius: 4px; border-left: 4px solid #2196F3;">
<h2 style="margin-top: 0; color: #333;">Prompt:</h2>
<p style="font-size: 16px; line-height: 1.6; margin-bottom: 0; color: #555;">{{ item.prompt }}</p>
</div>
{% endif %}
<h3>Reference Image: {{ item.ref_image }}
{% if item.is_annotated %}
<span class="annotation-status">已标注</span>
{% endif %}
</h3>
<p>Folder: {{ item.folder }}</p>
<img src="{{ item.ref_image }}" alt="ref_image" width="200">
<input type="hidden" name="ref_image" value="{{ item.ref_image }}">
{% if item.is_annotated %}
<button type="button" class="show-annotation-btn"
data-loaded="false"
onclick='loadExistingAnnotation(this, "{{ item.folder }}", "{{ item.ref_image.split("/")[-1] }}", {{ item.existing_rank_images|tojson|safe }})'>
显示已有标注
</button>
{% endif %}
<h4>Compare Images:</h4>
<div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-start;">
{% for compare_image in item.compare_images %}
<div class="image-item" style="display: flex; flex-direction: column; align-items: center; gap: 5px;">
<img src="{{ compare_image }}" alt="compare_image" width="100">
<button type="button"
class="rank-btn"
data-image="{{ compare_image }}"
onclick="rankImage(this, '{{ compare_image }}')">
排序
</button>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
<button type="submit" class="submit-btn">提交排序</button>
</form>
<div style="margin-top: 20px;">
{% if page > 1 %}
<a href="/?page={{ page - 1 }}" style="margin-right: 10px;">上一页</a>
{% endif %}
{% if page < total_pages %}
<a href="/?page={{ page + 1 }}">下一页</a>
{% endif %}
</div>
</body>
</html>