Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 8,964 Bytes
8b6a4c9 |
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 |
SANDBOX_HTML_TEMPLATE = """
<style>
@import url('https://fonts.googleapis.com/css2?family=Oxanium:wght@200..800&display=swap');
</style>
<h1 style="color:var(--color-accent);margin:0;">Open Computer Agent - <i>Powered by <a href="https://github.com/huggingface/smolagents">smolagents</a></i><h1>
<div class="sandbox-container" style="margin:0;">
<div class="status-bar">
<div class="status-indicator {status_class}"></div>
<div class="status-text">{status_text}</div>
</div>
<iframe id="sandbox-iframe"
src="{stream_url}"
class="sandbox-iframe"
style="display: block;"
allowfullscreen>
</iframe>
<img src="https://huggingface.co/datasets/mfarre/servedfiles/resolve/main/blue_screen_of_death.gif" class="bsod-image" style="display: none;"/>
<img src="https://huggingface.co/datasets/m-ric/images/resolve/main/HUD_thom.png" class="sandbox-frame" />
</div>
"""
SANDBOX_CSS_TEMPLATE = """
.modal-container {
margin: var(--size-16) auto!important;
}
.sandbox-container {
position: relative;
width: 910px;
overflow: hidden;
margin: auto;
}
.sandbox-container {
height: 800px;
}
.sandbox-frame {
display: none;
position: absolute;
top: 0;
left: 0;
width: 910px;
height: 800px;
pointer-events:none;
}
.sandbox-iframe, .bsod-image {
position: absolute;
width: <<WIDTH>>px;
height: <<HEIGHT>>px;
border: 4px solid #444444;
transform-origin: 0 0;
}
/* Colored label for task textbox */
.primary-color-label label span {
font-weight: bold;
color: var(--color-accent);
}
/* Status indicator light */
.status-bar {
display: flex;
flex-direction: row;
align-items: center;
flex-align:center;
z-index: 100;
}
.status-indicator {
width: 15px;
height: 15px;
border-radius: 50%;
}
.status-text {
font-size: 16px;
font-weight: bold;
padding-left: 8px;
text-shadow: none;
}
.status-interactive {
background-color: #2ecc71;
animation: blink 2s infinite;
}
.status-view-only {
background-color: #e74c3c;
}
.status-error {
background-color: #e74c3c;
animation: blink-error 1s infinite;
}
@keyframes blink-error {
0% { background-color: rgba(231, 76, 60, 1); }
50% { background-color: rgba(231, 76, 60, 0.4); }
100% { background-color: rgba(231, 76, 60, 1); }
}
@keyframes blink {
0% { background-color: rgba(46, 204, 113, 1); } /* Green at full opacity */
50% { background-color: rgba(46, 204, 113, 0.4); } /* Green at 40% opacity */
100% { background-color: rgba(46, 204, 113, 1); } /* Green at full opacity */
}
#chatbot {
height:1000px!important;
}
#chatbot .role {
max-width:95%
}
#chatbot .bubble-wrap {
overflow-y: visible;
}
.logo-container {
display: flex;
flex-direction: column;
align-items: flex-start;
width: 100%;
box-sizing: border-box;
gap: 5px;
.logo-item {
display: flex;
align-items: center;
padding: 0 30px;
gap: 10px;
text-decoration: none!important;
color: #f59e0b;
font-size:17px;
}
.logo-item:hover {
color: #935f06!important;
}
"""
FOOTER_HTML = """
<h3 style="text-align: center; margin-top:50px;"><i>Powered by open source:</i></h2>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="logo-container">
<a class="logo-item" href="https://github.com/huggingface/smolagents"><i class="fa fa-github"></i>smolagents</a>
<a class="logo-item" href="https://huggingface.co/Qwen/Qwen2-VL-72B-Instruct"><i class="fa fa-github"></i>Qwen2-VL-72B</a>
<a class="logo-item" href="https://github.com/e2b-dev/desktop"><i class="fa fa-github"></i>E2B Desktop</a>
</div>
"""
CUSTOM_JS = """function() {
document.body.classList.add('dark');
// Function to check if sandbox is timing out
const checkSandboxTimeout = function() {
const timeElement = document.getElementById('sandbox-creation-time');
if (timeElement) {
const creationTime = parseFloat(timeElement.getAttribute('data-time'));
const timeoutValue = parseFloat(timeElement.getAttribute('data-timeout'));
const currentTime = Math.floor(Date.now() / 1000); // Current time in seconds
const elapsedTime = currentTime - creationTime;
console.log("Sandbox running for: " + elapsedTime + " seconds of " + timeoutValue + " seconds");
// If we've exceeded the timeout, show BSOD
if (elapsedTime >= timeoutValue) {
console.log("Sandbox timeout! Showing BSOD");
showBSOD('Error');
// Don't set another timeout, we're done checking
return;
}
}
// Continue checking every 5 seconds
setTimeout(checkSandboxTimeout, 5000);
};
const showBSOD = function(statusText = 'Error') {
console.log("Showing BSOD with status: " + statusText);
const iframe = document.getElementById('sandbox-iframe');
const bsod = document.getElementById('bsod-image');
if (iframe && bsod) {
iframe.style.display = 'none';
bsod.style.display = 'block';
// Update status indicator
const statusIndicator = document.querySelector('.status-indicator');
const statusTextElem = document.querySelector('.status-text');
if (statusIndicator) {
statusIndicator.className = 'status-indicator status-error';
}
if (statusTextElem) {
statusTextElem.innerText = statusText;
}
}
};
const resetBSOD = function() {
console.log("Resetting BSOD display");
const iframe = document.getElementById('sandbox-iframe');
const bsod = document.getElementById('bsod-image');
if (iframe && bsod) {
if (bsod.style.display === 'block') {
// BSOD is currently showing, reset it
iframe.style.display = 'block';
bsod.style.display = 'none';
console.log("BSOD reset complete");
return true; // Indicates reset was performed
}
}
return false; // No reset needed
};
// Function to monitor for error messages
const monitorForErrors = function() {
console.log("Error monitor started");
const resultsInterval = setInterval(function() {
const resultsElements = document.querySelectorAll('textarea, .output-text');
for (let elem of resultsElements) {
const content = elem.value || elem.innerText || '';
if (content.includes('Error running agent')) {
console.log("Error detected!");
showBSOD('Error');
clearInterval(resultsInterval);
break;
}
}
}, 1000);
};
// Start monitoring for timeouts immediately
checkSandboxTimeout();
// Start monitoring for errors
setTimeout(monitorForErrors, 3000);
// Also monitor for errors after button clicks
document.addEventListener('click', function(e) {
if (e.target.tagName === 'BUTTON') {
if (e.target.innerText === "Let's go!") {
resetBSOD();
}
setTimeout(monitorForErrors, 3000);
}
});
// Set up an interval to click the refresh button every 5 seconds
setInterval(function() {
const btn = document.getElementById('refresh-log-btn');
if (btn) btn.click();
}, 5000);
// Force dark mode
const params = new URLSearchParams(window.location.search);
if (!params.has('__theme')) {
params.set('__theme', 'dark');
window.location.search = params.toString();
}
}
"""
def apply_theme(minimalist_mode: bool):
if not minimalist_mode:
return """
<style>
.sandbox-frame {
display: block!important;
}
.sandbox-iframe, .bsod-image {
/* top: 73px; */
top: 99px;
/* left: 74px; */
left: 110px;
}
.sandbox-iframe {
transform: scale(0.535);
}
.status-bar {
position: absolute;
bottom: 88px;
left: 355px;
}
.status-text {
color: #fed244;
}
</style>
"""
else:
return """
<style>
.sandbox-container {
height: 700px!important;
}
.sandbox-iframe {
transform: scale(0.7);
}
</style>
"""
|