Spaces:
Running
Running
File size: 3,732 Bytes
9f5f16b | 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 | ) {
if (!file.type.startsWith('image/')) {
addLog('错误:请上传有效的图像文件。', 'system');
return;
}
const reader = new FileReader();
reader.onload = (e) => {
imagePreview.src = e.target.result;
imagePreview.style.display = 'block';
imagePreviewContainer.style.display = 'block';
uploadZone.style.display = 'none';
imageStatus.classList.add('active');
isImageLoaded = true;
analyzeBtn.disabled = false;
addLog('图像已成功加载。', 'user');
addLog('等待用户启动分析进程...', 'system');
};
reader.readAsDataURL(file);
}
// 2. 模拟 Agent 分析过程
analyzeBtn.addEventListener('click', async () => {
if (!isImageLoaded) return;
// UI 更新:禁用按钮,显示进度条
analyzeBtn.disabled = true;
analyzeBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> 分析中...';
progressContainer.style.display = 'block';
agentThinking.style.display = 'block';
agentStatus.classList.add('processing');
// 模拟步骤
const steps = [
{ text: '正在初始化视觉编码器...', delay: 500 },
{ text: '正在提取图像特征向量...', delay: 1500 },
{ text: '正在调用大语言模型 (LLM) 进行推理...', delay: 2500 },
{ text: '正在综合分析结果...', delay: 3500 }
];
for (let i = 0; i < steps.length; i++) {
await wait(steps[i].delay);
progressBar.style.width = `${((i + 1) / steps.length) * 100}%`;
addLog(steps[i].text, 'system');
thinkingText.textContent = steps[i].text;
}
// 完成
await wait(500);
progressBar.style.width = '100%';
addLog('分析完成!', 'agent');
agentStatus.classList.remove('processing');
agentStatus.classList.add('active'); // 确保显示为活跃状态
// 模拟生成最终结果
thinkingText.textContent = "分析完成。图像检测到包含高科技设备、电路板以及复杂的几何结构。";
analyzeBtn.innerHTML = '<i class="fa-solid fa-check"></i> 分析完成';
analyzeBtn.style.backgroundColor = 'var(--success-color)';
});
// 辅助函数:添加日志
function addLog(message, type) {
const entry = document.createElement('div');
entry.className = `log-entry ${type}`;
let icon = '';
if (type === 'system') icon = '<i class="fa-solid fa-terminal"></i>';
if (type === 'user') icon = '<i class="fa-solid fa-user"></i>';
if (type === 'agent') icon = '<i class="fa-solid fa-robot"></i>';
entry.innerHTML = `${icon} <span>${message}</span>`;
logContainer.appendChild(entry);
logContainer.scrollTop = logContainer.scrollHeight;
}
// 辅助函数:等待
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
})();
</script>
</body>
</html> |