Update app.py
Browse files123456714 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677786 unmodified lines8586878889909110 unmodified lines1021031041051061071081 unmodified line1101111121131141151161171 unmodified line1191201211221231241251261271281291301311321331341351361371381391402 unmodified lines14314414514614714814914 unmodified lines1641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961975 unmodified lines2032042052062072081 unmodified line21021121221321421521681 unmodified lines298299300301302303import osimport subprocessimport tempfileimport jsonfrom flask import Flask, render_template_string, request, jsonifyfrom groq import Groq14 unmodified lines<style>/* --- PREMIUM MINIMALIST DARK THEME --- */:root {--bg-base: #09090b; /* Çox tünd, mat arxa plan */--bg-panel: #18181b; /* Panellər üçün biraz daha açıq */--border-color: #27272a; /* Kəskin və incə sərhədlər */--text-main: #fafafa;--text-muted: #a1a1aa;--accent: #3b82f6; /* Premium Vercel/Tailwind mavisinə yaxın */--ai-accent: #8b5cf6; /* Exypos üçün bənövşəyi premium ton */--radius: 6px; /* Daha ciddi, kəskin kənarlar */}* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }body { background-color: var(--bg-base); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }/* Fading Intro */body { animation: fadeIn 0.5s ease-in-out forwards; }@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }/* --- PANELLƏR VƏ LAYOUT --- */.panel {background: var(--bg-panel);border: 1px solid var(--border-color);border-radius: var(--radius);box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);}.top-bar { height: 50px; margin: 8px 8px 0 8px; display: flex; justify-content: space-between; align-items: center; padding: 0 16px; border: 1px solid var(--border-color); background: var(--bg-panel); border-radius: var(--radius); }.main-layout { display: flex; flex: 1; overflow: hidden; padding: 8px; gap: 8px; }.sidebar-left { width: 260px; display: flex; flex-direction: column; }.sidebar-right { width: 340px; display: flex; flex-direction: column; border-top: 2px solid var(--ai-accent); }.center-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }.bottom-panel { height: 280px; display: flex; flex-direction: column; border-radius: var(--radius); margin-top: 8px; }/* --- UI ELEMENTLƏRİ --- */.brand { font-size: 13px; font-weight: 600; letter-spacing: 1px; display: flex; align-items: center; gap: 10px; color: var(--text-main); }.brand span { color: var(--text-muted); font-weight: 400; }.controls { display: flex; align-items: center; gap: 8px; }.btn { background: transparent; color: var(--text-main); border: 1px solid var(--border-color); padding: 6px 12px; border-radius: 4px; cursor: pointer; transition: 0.2s; font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }.btn:hover { background: #27272a; border-color: #3f3f46; }.btn-run { background: var(--text-main); color: var(--bg-base); border: none; font-weight: 600; }.btn-run:hover { background: #e4e4e7; transform: none; box-shadow: none; } /* Sadə və kəskin */.panel-header { padding: 12px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }/* Explorer (Sol Panel) */#file-tree { padding: 12px; font-size: 13px; color: var(--text-main); }.file-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--text-muted); transition: 0.1s; }.file-item:hover { background: #27272a; color: var(--text-main); }.file-item.active { background: #27272a; color: var(--text-main); font-weight: 500; }/* Editor Area */#editor-container { flex: 1; background: var(--bg-panel); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-color); }6 unmodified lines.tab-content.active { display: flex; flex-direction: column; }#terminal-output { flex: 1; padding: 16px; font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 13px; color: #d4d4d8; overflow-y: auto; white-space: pre-wrap; line-height: 1.6; }.ps-cmd { color: var(--accent); font-weight: 600; }.ps-err { color: #ef4444; }.ps-ok { color: #22c55e; }10 unmodified lines.send-btn:hover { background: #e4e4e7; }/* AI Editor Actions */.ai-action-btn { background: var(--bg-base); color: var(--text-main); border: 1px solid var(--border-color); padding: 6px 10px; border-radius: 4px; font-size: 11px; font-weight: 500; cursor: pointer; margin-top: 8px; transition: 0.2s; display: flex; align-items: center; gap: 6px; }.ai-action-btn:hover { border-color: var(--text-main); }.terminal-ai-btn { background: transparent; border: 1px solid #ef4444; color: #ef4444; padding: 4px 10px; border-radius: 4px; cursor: pointer; margin-top: 5px; font-size: 11px; transition: 0.2s; display: inline-flex; align-items: center; gap: 4px; }.terminal-ai-btn:hover { background: #ef4444; color: #fff; }1 unmodified linepre { background: #000; padding: 12px; border-radius: 4px; overflow-x: auto; border: 1px solid var(--border-color); margin-top: 8px; }code { font-family: 'JetBrains Mono', 'Consolas', monospace; color: #e4e4e7; font-size: 12px; }/* Scrollbar təmizlənməsi */::-webkit-scrollbar { width: 8px; height: 8px; }::-webkit-scrollbar-track { background: var(--bg-base); }::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 4px; }::-webkit-scrollbar-thumb:hover { background: #52525b; }1 unmodified line<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script></head><body><div class="top-bar"><div class="brand"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 2 7 12 12 22 7 12 2"></polygon><polyline points="2 17 12 22 22 17"></polyline><polyline points="2 12 12 17 22 12"></polyline></svg>TWENTY OS <span>/ main.py</span></div><div class="controls"><button class="btn btn-run" onclick="runCode()"><i class="fa-solid fa-play" style="font-size: 10px;"></i> Run Code</button></div></div><div class="main-layout"><div class="panel sidebar-left" id="sidebar-left"><div class="panel-header">Explorer</div><div id="file-tree"><div class="file-item active"><i class="fa-brands fa-python" style="color:#eab308;"></i> main.py</div></div></div><div class="center-panel">2 unmodified lines<div class="panel bottom-panel" id="bottom-panel"><div class="bottom-tabs"><div class="tab active" onclick="switchTab('terminal')">Terminal</div><i class="fa-solid fa-broom" style="margin-left:auto; margin-right:16px; margin-top:10px; cursor:pointer; color:var(--text-muted); font-size: 12px;" onclick="clearTerminal()" title="Clear"></i></div><div class="tab-content active" id="tab-terminal"><div id="terminal-output"><span style="color:#52525b;">// Environment Ready.</span><br></div>14 unmodified lines</div><script>let editor;let lastAiCode = "";require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs' }});require(['vs/editor/editor.main'], function() {editor = monaco.editor.create(document.getElementById('editor-container'), {value: "# Welcome to Twenty Premium Workspace\\ndef main():\\n print('Hello, Engineer.')\\n\\nif __name__ == '__main__':\\n main()",language: 'python',theme: 'vs-dark', // Standart dark mövzu (daha peşəkar görünür)automaticLayout: true,fontSize: 14,fontFamily: "'JetBrains Mono', 'Consolas', monospace",minimap: { enabled: false },padding: { top: 16 },scrollBeyondLastLine: false,renderLineHighlight: "all",cursorBlinking: "smooth",cursorSmoothCaretAnimation: true});// Monaco Editor arxa planını bizim panel arxa planı ilə eyniləşdiririkmonaco.editor.defineTheme('twenty-dark', {base: 'vs-dark',inherit: true,rules: [],colors: { 'editor.background': '#18181b' }});monaco.editor.setTheme('twenty-dark');});function switchTab(tabId) {5 unmodified linesasync function runCode() {if(!editor) return;const code = editor.getValue();const term = document.getElementById('terminal-output');const isShell = code.trim().startsWith('!');1 unmodified lineif(isShell) {term.innerHTML += `<br><span class="ps-cmd">$</span> ${code.trim()}<br><span style="color:#52525b">Executing...</span>`;} else {term.innerHTML += `<br><span class="ps-cmd">user@twenty:~$</span> python main.py<br><span style="color:#52525b">Executing...</span>`;}term.scrollTop = term.scrollHeight;81 unmodified linesconst inputEl = document.getElementById('ai-input');inputEl.value = "Bu xətanı necə həll edim? Xəta: " + decodedError;askAI();}</script></body>12345614 unmodified lines212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091106 unmodified lines11711811912012112212310 unmodified lines1341351361371381391401 unmodified line1421431441451461471481491 unmodified line1511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831842 unmodified lines18718818919019119219314 unmodified lines2082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163175 unmodified lines3233243253263273283291 unmodified line33133233333433533633781 unmodified lines419420421422423424425426427428429import osimport subprocessimport tempfilefrom flask import Flask, render_template_string, request, jsonifyfrom groq import Groq14 unmodified lines<style>/* --- PREMIUM MINIMALIST DARK THEME --- */:root {--bg-base: #09090b;--bg-panel: #18181b;--border-color: #27272a;--text-main: #fafafa;--text-muted: #a1a1aa;--accent: #e4e4e7;--ai-accent: #8b5cf6;--radius: 6px;}* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }body { background-color: var(--bg-base); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }/* --- SADE "2 0" ANIMASIYASI --- */#splash {position: fixed; inset: 0; background: var(--bg-base); z-index: 9999;display: flex; flex-direction: column; align-items: center; justify-content: center;transition: opacity 0.5s ease-out;}.logo-container {display: flex; font-size: 80px; font-weight: 700; color: var(--text-main); font-family: 'JetBrains Mono', monospace;overflow: hidden;animation: syncWave 0.6s 0.6s cubic-bezier(0.25, 1, 0.5, 1);}.digit-2 { transform: translateX(-200px); opacity: 0; animation: slideHit 0.6s cubic-bezier(0.25, 1, 0.5, 1) forwards; }.digit-0 { transform: translateX(0); }.logo-text {font-size: 14px; letter-spacing: 12px; margin-top: 15px; opacity: 0; color: var(--text-muted); text-transform: uppercase;animation: fadeInText 1s 1s forwards; margin-left: 12px;}@keyframes slideHit {0% { transform: translateX(-200px); opacity: 0; }100% { transform: translateX(0); opacity: 1; }}@keyframes syncWave {0% { transform: translateX(0) scale(1); }25% { transform: translateX(8px) scale(1.02); }50% { transform: translateX(-4px) scale(0.98); }75% { transform: translateX(4px) scale(1.01); }100% { transform: translateX(0) scale(1); }}@keyframes fadeInText {0% { opacity: 0; letter-spacing: 8px; }100% { opacity: 1; letter-spacing: 16px; }}/* --- PANELLƏR VƏ LAYOUT --- */.panel {background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: var(--radius);}.top-bar { height: 50px; margin: 8px 8px 0 8px; display: flex; justify-content: space-between; align-items: center; padding: 0 16px; border: 1px solid var(--border-color); background: var(--bg-panel); border-radius: var(--radius); }.main-layout { display: flex; flex: 1; overflow: hidden; padding: 8px; gap: 8px; }.sidebar-left { width: 260px; display: flex; flex-direction: column; transition: width 0.3s, opacity 0.3s, padding 0.3s; white-space: nowrap; overflow: hidden; }.sidebar-right { width: 340px; display: flex; flex-direction: column; border-top: 2px solid var(--ai-accent); transition: width 0.3s, opacity 0.3s, padding 0.3s; white-space: nowrap; overflow: hidden; }.center-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; transition: flex 0.3s; }.bottom-panel { height: 280px; display: flex; flex-direction: column; border-radius: var(--radius); margin-top: 8px; }.collapsed { width: 0 !important; padding: 0 !important; opacity: 0 !important; border: none !important; margin: 0 !important; }/* --- UI ELEMENTLƏRİ --- */.brand { font-size: 13px; font-weight: 600; letter-spacing: 1px; display: flex; align-items: center; gap: 10px; color: var(--text-main); }.brand span { color: var(--text-muted); font-weight: 400; }.controls { display: flex; align-items: center; gap: 8px; }.icon-btn { background: transparent; color: var(--text-muted); border: none; font-size: 14px; cursor: pointer; transition: 0.2s; padding: 4px; border-radius: 4px; }.icon-btn:hover { color: var(--text-main); background: #27272a; }.btn { background: transparent; color: var(--text-main); border: 1px solid var(--border-color); padding: 6px 12px; border-radius: 4px; cursor: pointer; transition: 0.2s; font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }.btn:hover { background: #27272a; border-color: #3f3f46; }.btn-run { background: var(--text-main); color: var(--bg-base); border: none; font-weight: 600; }.btn-run:hover { background: #e4e4e7; }.panel-header { padding: 12px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }/* Explorer (Sol Panel - VFS) */#file-tree { flex: 1; padding: 12px; font-size: 13px; color: var(--text-main); overflow-y: auto; }.file-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--text-muted); transition: 0.1s; }.file-item:hover { background: #27272a; color: var(--text-main); }.file-item.active { background: #27272a; color: var(--text-main); font-weight: 500; border-left: 2px solid var(--accent); }.del-btn { opacity: 0; color: #ef4444; transition: 0.2s; font-size: 12px; }.file-item:hover .del-btn { opacity: 1; }/* Editor Area */#editor-container { flex: 1; background: var(--bg-panel); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-color); }6 unmodified lines.tab-content.active { display: flex; flex-direction: column; }#terminal-output { flex: 1; padding: 16px; font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 13px; color: #d4d4d8; overflow-y: auto; white-space: pre-wrap; line-height: 1.6; }.ps-cmd { color: var(--text-main); font-weight: 600; }.ps-err { color: #ef4444; }.ps-ok { color: #22c55e; }10 unmodified lines.send-btn:hover { background: #e4e4e7; }/* AI Editor Actions */.ai-action-btn { background: var(--bg-base); color: var(--text-main); border: 1px solid var(--border-color); padding: 6px 10px; border-radius: 4px; font-size: 11px; font-weight: 500; cursor: pointer; margin-top: 8px; transition: 0.2s; display: inline-flex; align-items: center; gap: 6px; }.ai-action-btn:hover { border-color: var(--text-main); }.terminal-ai-btn { background: transparent; border: 1px solid #ef4444; color: #ef4444; padding: 4px 10px; border-radius: 4px; cursor: pointer; margin-top: 5px; font-size: 11px; transition: 0.2s; display: inline-flex; align-items: center; gap: 4px; }.terminal-ai-btn:hover { background: #ef4444; color: #fff; }1 unmodified linepre { background: #000; padding: 12px; border-radius: 4px; overflow-x: auto; border: 1px solid var(--border-color); margin-top: 8px; }code { font-family: 'JetBrains Mono', 'Consolas', monospace; color: #e4e4e7; font-size: 12px; }/* Scrollbar */::-webkit-scrollbar { width: 6px; height: 6px; }::-webkit-scrollbar-track { background: var(--bg-base); }::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 4px; }::-webkit-scrollbar-thumb:hover { background: #52525b; }1 unmodified line<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script></head><body><div id="splash"><div class="logo-container"><div class="digit-2">2</div><div class="digit-0">0</div></div><div class="logo-text">TWENTY</div></div><div class="top-bar"><div class="brand"><button class="icon-btn" onclick="toggleSidebar('sidebar-left')" title="Explorer-i aç/bağla"><i class="fa-solid fa-folder-tree"></i></button><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 2 7 12 12 22 7 12 2"></polygon><polyline points="2 17 12 22 22 17"></polyline><polyline points="2 12 12 17 22 12"></polyline></svg>TWENTY OS <span id="current-file-label">/ main.py</span></div><div class="controls"><button class="icon-btn" onclick="toggleSidebar('sidebar-right')" title="Exypos-u aç/bağla"><i class="fa-solid fa-bolt" style="color: var(--ai-accent);"></i></button><button class="btn btn-run" onclick="runCode()"><i class="fa-solid fa-play" style="font-size: 10px;"></i> Run Code</button></div></div><div class="main-layout"><div class="panel sidebar-left" id="sidebar-left"><div class="panel-header">EXPLORER<i class="fa-solid fa-plus icon-btn" onclick="createFile()" title="Yeni Fayl"></i></div><div id="file-tree"></div></div><div class="center-panel">2 unmodified lines<div class="panel bottom-panel" id="bottom-panel"><div class="bottom-tabs"><div class="tab active" onclick="switchTab('terminal')">Terminal</div><i class="fa-solid fa-broom icon-btn" style="margin-left:auto; margin-right:8px; margin-top:8px;" onclick="clearTerminal()" title="Clear"></i></div><div class="tab-content active" id="tab-terminal"><div id="terminal-output"><span style="color:#52525b;">// Environment Ready.</span><br></div>14 unmodified lines</div><script>// --- SPLASH LOGIC ---window.onload = () => {setTimeout(() => {const splash = document.getElementById('splash');splash.style.opacity = '0';setTimeout(() => splash.remove(), 500);}, 2600); // 2.6 saniyəyə bitir (Tez və Kəskin)};// --- VIRTUAL FILE SYSTEM (VFS) ---let vfs = {"main.py": "# Welcome to Twenty Premium Workspace\\ndef main():\\n print('Hello, Engineer.')\\n\\nif __name__ == '__main__':\\n main()","utils.py": "def add(a, b):\\n return a + b\\n"};let currentFile = "main.py";let editor;let lastAiCode = "";function renderVFS() {const tree = document.getElementById('file-tree');tree.innerHTML = "";for (let fileName in vfs) {const isActive = (fileName === currentFile) ? 'active' : '';const fileDiv = document.createElement('div');fileDiv.className = `file-item ${isActive}`;let iconColor = fileName.endsWith('.py') ? '#eab308' : '#a1a1aa';let iconClass = fileName.endsWith('.py') ? 'fa-brands fa-python' : 'fa-solid fa-file';fileDiv.innerHTML = `<div style="display:flex; align-items:center; gap:8px; width:100%;" onclick="openFile('${fileName}')"><i class="${iconClass}" style="color:${iconColor};"></i> <span style="flex:1; overflow:hidden; text-overflow:ellipsis;">${fileName}</span></div><i class="fa-solid fa-trash del-btn" onclick="deleteFile('${fileName}', event)"></i>`;tree.appendChild(fileDiv);}document.getElementById('current-file-label').innerText = `/ ${currentFile}`;}function openFile(fileName) {if (editor) vfs[currentFile] = editor.getValue();currentFile = fileName;let lang = fileName.endsWith('.py') ? 'python' : 'plaintext';monaco.editor.setModelLanguage(editor.getModel(), lang);editor.setValue(vfs[fileName]);renderVFS();}function createFile() {let name = prompt("Yeni faylın adı (məs: test.py):");if (name && !vfs[name]) {vfs[name] = "# " + name + "\\n";openFile(name);}}function deleteFile(fileName, event) {event.stopPropagation();if (Object.keys(vfs).length <= 1) {alert("Sonuncu faylı silə bilməzsiniz!");return;}if (confirm(`'${fileName}' silinsin?`)) {delete vfs[fileName];if (currentFile === fileName) {openFile(Object.keys(vfs)[0]);} else {renderVFS();}}}// --- PANELS TOGGLE LOGIC ---function toggleSidebar(id) {document.getElementById(id).classList.toggle('collapsed');// Editorun ölçüsünü yenidən hesablaması üçün qısa gecikməsetTimeout(() => { if (editor) editor.layout(); }, 350);}// --- MONACO EDITOR İNİT ---require.config({ paths: { 'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs' }});require(['vs/editor/editor.main'], function() {editor = monaco.editor.create(document.getElementById('editor-container'), {value: vfs[currentFile],language: 'python',theme: 'vs-dark',automaticLayout: true,fontSize: 14,fontFamily: "'JetBrains Mono', 'Consolas', monospace",minimap: { enabled: false },padding: { top: 16 },scrollBeyondLastLine: false,renderLineHighlight: "all"});monaco.editor.defineTheme('twenty-dark', {base: 'vs-dark', inherit: true, rules: [], colors: { 'editor.background': '#18181b' }});monaco.editor.setTheme('twenty-dark');// Kod dəyişdikcə VFS-i yeniləeditor.onDidChangeModelContent(() => { vfs[currentFile] = editor.getValue(); });renderVFS();});function switchTab(tabId) {5 unmodified linesasync function runCode() {if(!editor) return;vfs[currentFile] = editor.getValue(); // Son dəyişikliyi yadda saxlaconst code = editor.getValue();const term = document.getElementById('terminal-output');const isShell = code.trim().startsWith('!');1 unmodified lineif(isShell) {term.innerHTML += `<br><span class="ps-cmd">$</span> ${code.trim()}<br><span style="color:#52525b">Executing...</span>`;} else {term.innerHTML += `<br><span class="ps-cmd">user@twenty:~$</span> python ${currentFile}<br><span style="color:#52525b">Executing...</span>`;}term.scrollTop = term.scrollHeight;81 unmodified linesconst inputEl = document.getElementById('ai-input');inputEl.value = "Bu xətanı necə həll edim? Xəta: " + decodedError;askAI();// Xəta soruşanda avtomatik AI panelini açırconst aiPanel = document.getElementById('sidebar-right');if(aiPanel.classList.contains('collapsed')) {toggleSidebar('sidebar-right');}}</script></body>
app.py+169-43