undefined - Initial Deployment
Browse files- README.md +7 -5
- index.html +291 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: tool-python-sandbox
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: gray
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,291 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Python Sandbox Environment</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<style>
|
| 10 |
+
/* Custom styles that can't be easily done with Tailwind */
|
| 11 |
+
.code-editor {
|
| 12 |
+
font-family: 'Fira Code', 'Courier New', monospace;
|
| 13 |
+
font-size: 14px;
|
| 14 |
+
line-height: 1.5;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.output-container {
|
| 18 |
+
max-height: 300px;
|
| 19 |
+
overflow-y: auto;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
/* Custom scrollbar */
|
| 23 |
+
.output-container::-webkit-scrollbar {
|
| 24 |
+
width: 8px;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.output-container::-webkit-scrollbar-track {
|
| 28 |
+
background: #f1f1f1;
|
| 29 |
+
border-radius: 10px;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.output-container::-webkit-scrollbar-thumb {
|
| 33 |
+
background: #888;
|
| 34 |
+
border-radius: 10px;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.output-container::-webkit-scrollbar-thumb:hover {
|
| 38 |
+
background: #555;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Loading animation */
|
| 42 |
+
@keyframes pulse {
|
| 43 |
+
0%, 100% {
|
| 44 |
+
opacity: 1;
|
| 45 |
+
}
|
| 46 |
+
50% {
|
| 47 |
+
opacity: 0.5;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.animate-pulse {
|
| 52 |
+
animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
| 53 |
+
}
|
| 54 |
+
</style>
|
| 55 |
+
</head>
|
| 56 |
+
<body class="bg-gray-100 min-h-screen">
|
| 57 |
+
<div class="container mx-auto px-4 py-8">
|
| 58 |
+
<!-- Header -->
|
| 59 |
+
<header class="mb-8 text-center">
|
| 60 |
+
<h1 class="text-4xl font-bold text-indigo-700 mb-2">Python Sandbox Environment</h1>
|
| 61 |
+
<p class="text-gray-600">Write and execute Python code safely in your browser</p>
|
| 62 |
+
</header>
|
| 63 |
+
|
| 64 |
+
<!-- Main Content -->
|
| 65 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
| 66 |
+
<!-- Code Editor Section -->
|
| 67 |
+
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
|
| 68 |
+
<div class="bg-gray-800 px-4 py-3 flex justify-between items-center">
|
| 69 |
+
<div class="flex items-center space-x-2">
|
| 70 |
+
<div class="w-3 h-3 rounded-full bg-red-500"></div>
|
| 71 |
+
<div class="w-3 h-3 rounded-full bg-yellow-500"></div>
|
| 72 |
+
<div class="w-3 h-3 rounded-full bg-green-500"></div>
|
| 73 |
+
</div>
|
| 74 |
+
<span class="text-gray-300 text-sm font-mono">main.py</span>
|
| 75 |
+
<div class="w-8"></div> <!-- Spacer for alignment -->
|
| 76 |
+
</div>
|
| 77 |
+
<div class="p-1 bg-gray-800">
|
| 78 |
+
<textarea id="code-editor" class="code-editor w-full h-96 bg-gray-900 text-gray-100 p-4 resize-none focus:outline-none" spellcheck="false"># Welcome to Python Sandbox!
|
| 79 |
+
# Write your Python code here and click "Run Code"
|
| 80 |
+
|
| 81 |
+
def greet(name):
|
| 82 |
+
return f"Hello, {name}!"
|
| 83 |
+
|
| 84 |
+
print(greet("World"))
|
| 85 |
+
|
| 86 |
+
# Try some math:
|
| 87 |
+
result = 42 * 3.14
|
| 88 |
+
print(f"The answer is {result}")
|
| 89 |
+
|
| 90 |
+
# Or a simple loop:
|
| 91 |
+
for i in range(5):
|
| 92 |
+
print(f"Counting: {i}")</textarea>
|
| 93 |
+
</div>
|
| 94 |
+
<div class="bg-gray-100 px-4 py-3 flex justify-between items-center">
|
| 95 |
+
<div class="flex items-center space-x-2 text-sm text-gray-600">
|
| 96 |
+
<i class="fas fa-info-circle"></i>
|
| 97 |
+
<span>Python 3.8</span>
|
| 98 |
+
</div>
|
| 99 |
+
<div class="flex space-x-2">
|
| 100 |
+
<button id="clear-btn" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-md hover:bg-gray-400 transition">
|
| 101 |
+
<i class="fas fa-trash-alt mr-2"></i>Clear
|
| 102 |
+
</button>
|
| 103 |
+
<button id="run-btn" class="px-6 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition flex items-center">
|
| 104 |
+
<i class="fas fa-play mr-2"></i>Run Code
|
| 105 |
+
</button>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<!-- Output Section -->
|
| 111 |
+
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
|
| 112 |
+
<div class="bg-gray-800 px-4 py-3 flex justify-between items-center">
|
| 113 |
+
<div class="flex items-center space-x-2">
|
| 114 |
+
<i class="fas fa-terminal text-gray-300"></i>
|
| 115 |
+
<span class="text-gray-300 text-sm font-mono">Output</span>
|
| 116 |
+
</div>
|
| 117 |
+
<button id="copy-output-btn" class="text-gray-300 hover:text-white text-sm">
|
| 118 |
+
<i class="far fa-copy mr-1"></i>Copy
|
| 119 |
+
</button>
|
| 120 |
+
</div>
|
| 121 |
+
<div id="output-container" class="output-container bg-gray-900 text-gray-100 p-4 h-96 font-mono whitespace-pre-wrap">
|
| 122 |
+
<div class="text-gray-500">
|
| 123 |
+
<p>Output will appear here after execution...</p>
|
| 124 |
+
<p class="mt-2">Try writing some Python code and click "Run Code"!</p>
|
| 125 |
+
</div>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="bg-gray-100 px-4 py-3 flex justify-between items-center">
|
| 128 |
+
<div class="flex items-center space-x-2 text-sm text-gray-600">
|
| 129 |
+
<i class="fas fa-shield-alt"></i>
|
| 130 |
+
<span>Sandboxed Environment</span>
|
| 131 |
+
</div>
|
| 132 |
+
<div class="text-sm text-gray-600">
|
| 133 |
+
<span id="execution-time">Ready</span>
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
</div>
|
| 138 |
+
|
| 139 |
+
<!-- Features Section -->
|
| 140 |
+
<div class="mt-12 grid grid-cols-1 md:grid-cols-3 gap-6">
|
| 141 |
+
<div class="bg-white p-6 rounded-xl shadow-md">
|
| 142 |
+
<div class="text-indigo-600 text-2xl mb-3">
|
| 143 |
+
<i class="fas fa-lock"></i>
|
| 144 |
+
</div>
|
| 145 |
+
<h3 class="font-bold text-lg mb-2">Safe Execution</h3>
|
| 146 |
+
<p class="text-gray-600">Your code runs in a secure sandbox environment with restricted access to system resources.</p>
|
| 147 |
+
</div>
|
| 148 |
+
<div class="bg-white p-6 rounded-xl shadow-md">
|
| 149 |
+
<div class="text-indigo-600 text-2xl mb-3">
|
| 150 |
+
<i class="fas fa-bolt"></i>
|
| 151 |
+
</div>
|
| 152 |
+
<h3 class="font-bold text-lg mb-2">Fast Results</h3>
|
| 153 |
+
<p class="text-gray-600">Get immediate feedback with our cloud-powered execution environment.</p>
|
| 154 |
+
</div>
|
| 155 |
+
<div class="bg-white p-6 rounded-xl shadow-md">
|
| 156 |
+
<div class="text-indigo-600 text-2xl mb-3">
|
| 157 |
+
<i class="fas fa-code"></i>
|
| 158 |
+
</div>
|
| 159 |
+
<h3 class="font-bold text-lg mb-2">Python 3.8</h3>
|
| 160 |
+
<p class="text-gray-600">Supports most Python 3.8 features and standard libraries.</p>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<!-- Footer -->
|
| 165 |
+
<footer class="mt-12 text-center text-gray-600 text-sm">
|
| 166 |
+
<p>This is a simulated sandbox environment. For security reasons, some system operations are restricted.</p>
|
| 167 |
+
<p class="mt-2">© 2023 Python Sandbox Environment</p>
|
| 168 |
+
</footer>
|
| 169 |
+
</div>
|
| 170 |
+
|
| 171 |
+
<script>
|
| 172 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 173 |
+
const codeEditor = document.getElementById('code-editor');
|
| 174 |
+
const runBtn = document.getElementById('run-btn');
|
| 175 |
+
const clearBtn = document.getElementById('clear-btn');
|
| 176 |
+
const copyOutputBtn = document.getElementById('copy-output-btn');
|
| 177 |
+
const outputContainer = document.getElementById('output-container');
|
| 178 |
+
const executionTime = document.getElementById('execution-time');
|
| 179 |
+
|
| 180 |
+
// Sample code snippets
|
| 181 |
+
const codeSnippets = [
|
| 182 |
+
{ name: "Hello World", code: 'print("Hello, World!")' },
|
| 183 |
+
{ name: "Fibonacci", code: 'def fib(n):\n a, b = 0, 1\n for _ in range(n):\n print(a, end=" ")\n a, b = b, a + b\n\nfib(10)' },
|
| 184 |
+
{ name: "Factorial", code: 'def factorial(n):\n return 1 if n <= 1 else n * factorial(n-1)\n\nprint(factorial(5))' },
|
| 185 |
+
{ name: "Prime Check", code: 'def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True\n\nprint([x for x in range(20) if is_prime(x)])' }
|
| 186 |
+
];
|
| 187 |
+
|
| 188 |
+
// Run code button click handler
|
| 189 |
+
runBtn.addEventListener('click', async function() {
|
| 190 |
+
const code = codeEditor.value.trim();
|
| 191 |
+
|
| 192 |
+
if (!code) {
|
| 193 |
+
outputContainer.innerHTML = '<div class="text-red-400">Error: No code to execute</div>';
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
// Show loading state
|
| 198 |
+
runBtn.disabled = true;
|
| 199 |
+
runBtn.innerHTML = '<i class="fas fa-spinner animate-spin mr-2"></i>Running...';
|
| 200 |
+
outputContainer.innerHTML = '<div class="flex items-center text-gray-500"><i class="fas fa-spinner animate-spin mr-2"></i>Executing your code...</div>';
|
| 201 |
+
executionTime.textContent = 'Executing...';
|
| 202 |
+
|
| 203 |
+
try {
|
| 204 |
+
// Simulate API call with timeout
|
| 205 |
+
const startTime = performance.now();
|
| 206 |
+
|
| 207 |
+
// In a real implementation, you would call an actual API here
|
| 208 |
+
// For this demo, we'll simulate execution with a timeout
|
| 209 |
+
const simulatedResult = await simulateCodeExecution(code);
|
| 210 |
+
const endTime = performance.now();
|
| 211 |
+
const elapsedTime = (endTime - startTime).toFixed(2);
|
| 212 |
+
|
| 213 |
+
// Display results
|
| 214 |
+
outputContainer.innerHTML = simulatedResult;
|
| 215 |
+
executionTime.textContent = `Execution time: ${elapsedTime}ms`;
|
| 216 |
+
} catch (error) {
|
| 217 |
+
outputContainer.innerHTML = `<div class="text-red-400">Error: ${error.message}</div>`;
|
| 218 |
+
executionTime.textContent = 'Error occurred';
|
| 219 |
+
} finally {
|
| 220 |
+
runBtn.disabled = false;
|
| 221 |
+
runBtn.innerHTML = '<i class="fas fa-play mr-2"></i>Run Code';
|
| 222 |
+
}
|
| 223 |
+
});
|
| 224 |
+
|
| 225 |
+
// Clear button click handler
|
| 226 |
+
clearBtn.addEventListener('click', function() {
|
| 227 |
+
codeEditor.value = '';
|
| 228 |
+
outputContainer.innerHTML = '<div class="text-gray-500">Output will appear here after execution...</div>';
|
| 229 |
+
executionTime.textContent = 'Ready';
|
| 230 |
+
});
|
| 231 |
+
|
| 232 |
+
// Copy output button click handler
|
| 233 |
+
copyOutputBtn.addEventListener('click', function() {
|
| 234 |
+
const range = document.createRange();
|
| 235 |
+
range.selectNode(outputContainer);
|
| 236 |
+
window.getSelection().removeAllRanges();
|
| 237 |
+
window.getSelection().addRange(range);
|
| 238 |
+
document.execCommand('copy');
|
| 239 |
+
window.getSelection().removeAllRanges();
|
| 240 |
+
|
| 241 |
+
// Show copied feedback
|
| 242 |
+
const originalText = copyOutputBtn.innerHTML;
|
| 243 |
+
copyOutputBtn.innerHTML = '<i class="fas fa-check mr-1"></i>Copied!';
|
| 244 |
+
setTimeout(() => {
|
| 245 |
+
copyOutputBtn.innerHTML = originalText;
|
| 246 |
+
}, 2000);
|
| 247 |
+
});
|
| 248 |
+
|
| 249 |
+
// Function to simulate code execution
|
| 250 |
+
function simulateCodeExecution(code) {
|
| 251 |
+
return new Promise((resolve, reject) => {
|
| 252 |
+
setTimeout(() => {
|
| 253 |
+
try {
|
| 254 |
+
// This is a simulation - in a real app, you'd call an API
|
| 255 |
+
if (code.includes('import os') || code.includes('import sys') ||
|
| 256 |
+
code.includes('__import__') || code.includes('eval(') ||
|
| 257 |
+
code.includes('exec(') || code.includes('open(')) {
|
| 258 |
+
throw new Error('Restricted operation detected');
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Simulate different outputs based on code content
|
| 262 |
+
if (code.includes('print("Hello, World!")')) {
|
| 263 |
+
resolve('<div class="text-green-400">Hello, World!</div>');
|
| 264 |
+
} else if (code.includes('fib(')) {
|
| 265 |
+
resolve('<div class="text-green-400">0 1 1 2 3 5 8 13 21 34</div>');
|
| 266 |
+
} else if (code.includes('factorial(')) {
|
| 267 |
+
resolve('<div class="text-green-400">120</div>');
|
| 268 |
+
} else if (code.includes('is_prime(')) {
|
| 269 |
+
resolve('<div class="text-green-400">[2, 3, 5, 7, 11, 13, 17, 19]</div>');
|
| 270 |
+
} else {
|
| 271 |
+
// Default simulated output
|
| 272 |
+
const defaultOutput = code.split('\n')
|
| 273 |
+
.filter(line => line.trim() && !line.trim().startsWith('#'))
|
| 274 |
+
.map(line => `<div class="text-green-400">${line.trim()}</div>`)
|
| 275 |
+
.join('');
|
| 276 |
+
|
| 277 |
+
resolve(defaultOutput || '<div class="text-green-400">Code executed successfully (simulated)</div>');
|
| 278 |
+
}
|
| 279 |
+
} catch (err) {
|
| 280 |
+
reject(err);
|
| 281 |
+
}
|
| 282 |
+
}, 1000); // Simulate network delay
|
| 283 |
+
});
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
// Add example selector (would be more elaborate in a real implementation)
|
| 287 |
+
console.log('Try these example snippets:', codeSnippets);
|
| 288 |
+
});
|
| 289 |
+
</script>
|
| 290 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Midwintertroll/tool-python-sandbox" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 291 |
+
</html>
|