Update app.py
Browse files1234569 unmodified lines1617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274281 unmodified line4304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634642 unmodified lines4674684694704714724734744754764774784794801 unmodified line48248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351412 unmodified lines5275285295305315325335345355365375385395405415425435445455465475485495505515525535545554 unmodified lines560561562563564565566567568569570571572573574575576577578579580581582583584585586587import osimport subprocessimport tempfilefrom flask import Flask, render_template_string, request, jsonifyfrom groq import Groq9 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Twenty IDE | Ultimate Liquid</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"><style>/* CSS Dəyişənləri (Gecə/Gündüz Modu üçün) */:root {--bg-base: #050505;--bg-panel: rgba(15, 15, 20, 0.6);--border-color: rgba(255, 255, 255, 0.1);--text-main: #f4f4f5;--text-muted: #888899;--accent: #00f2fe;--liquid-1: #00f2fe;--liquid-2: #4facfe;--editor-bg: rgba(0,0,0,0.4);--radius: 12px;}.light-mode {--bg-base: #f0f2f5;--bg-panel: rgba(255, 255, 255, 0.7);--border-color: rgba(0, 0, 0, 0.1);--text-main: #111827;--text-muted: #6b7280;--accent: #0284c7;--liquid-1: #bae6fd;--liquid-2: #e0f2fe;--editor-bg: rgba(255,255,255,0.5);}* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }body { background-color: var(--bg-base); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; transition: background 0.5s; }/* LIQUID (MAYE) ARXA PLAN ANİMASİYASI */.liquid-bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg-base); transition: 0.5s; }.shape {position: absolute; filter: blur(60px); opacity: 0.4;animation: liquidMorph 15s ease-in-out infinite alternate;}.shape-1 { width: 50vw; height: 50vw; background: var(--liquid-1); top: -10%; left: -10%; border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%; }.shape-2 { width: 45vw; height: 45vw; background: var(--liquid-2); bottom: -10%; right: -10%; border-radius: 60% 40% 30% 70% / 50% 60% 40% 50%; animation-delay: -5s; }@keyframes liquidMorph {0% { border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%; transform: rotate(0deg) scale(1); }100% { border-radius: 60% 40% 30% 70% / 50% 60% 40% 50%; transform: rotate(45deg) scale(1.1); }}/* --- SİRR Lİ VƏ DUMANLI (BLUR) SPLASH EKRANI --- */#splash {position: fixed; inset: 0; background: #020204;z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center;transition: opacity 1.5s ease-in-out;}.splash-text {font-size: 65px; font-weight: 200; color: transparent;margin-left: 30px;animation: breatheMelt 4s cubic-bezier(0.25, 1, 0.5, 1) forwards;}.splash-sub {font-size: 13px; color: var(--accent); letter-spacing: 20px; margin-top: 25px;text-transform: uppercase; margin-left: 20px; opacity: 0;animation: subFade 4s ease-in-out forwards;}@keyframes breatheMelt {0% { opacity: 0; filter: blur(30px); text-shadow: 0 0 0px rgba(0, 242, 254, 0); transform: scale(1.1); letter-spacing: 45px; }40% { opacity: 1; filter: blur(0px); text-shadow: 0 0 60px rgba(0, 242, 254, 0.8); transform: scale(1); letter-spacing: 30px; color: #fff; }70% { opacity: 1; filter: blur(0px); text-shadow: 0 0 40px rgba(0, 242, 254, 0.5); transform: scale(1); letter-spacing: 30px; color: #fff; }100% { opacity: 0; filter: blur(30px); text-shadow: 0 0 0px rgba(0, 242, 254, 0); transform: scale(0.9); letter-spacing: 15px; color: transparent; }}@keyframes subFade {0% { opacity: 0; filter: blur(10px); }40% { opacity: 0.9; filter: blur(0px); }70% { opacity: 0.9; filter: blur(0px); }100% { opacity: 0; filter: blur(15px); }}/* Panellər (Glass) */.panel-glass { background: var(--bg-panel); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border-color); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,0.2); transition: 0.3s; }/* Üst Panel */.top-bar { height: 60px; margin: 10px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; z-index: 100; opacity: 0; transform: translateY(-50px); animation: slideInTop 1s cubic-bezier(0.16, 1, 0.3, 1) forwards 3.5s; }.brand { font-size: 16px; font-weight: 500; letter-spacing: 2px; display: flex; align-items: center; gap: 15px; }.brand i { color: var(--accent); }.controls { display: flex; align-items: center; gap: 15px; }.btn { background: rgba(0,0,0,0.2); color: var(--text-main); border: 1px solid var(--border-color); padding: 8px 15px; border-radius: 6px; cursor: pointer; transition: 0.2s; font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px;}.light-mode .btn { background: rgba(255,255,255,0.5); }.btn:hover { border-color: var(--accent); color: var(--accent); }.btn-run { background: rgba(0, 242, 254, 0.1); border-color: var(--accent); color: var(--accent); }.btn-run:hover { background: var(--accent); color: #fff; transform: translateY(-2px); }@keyframes slideInTop { to { transform: translateY(0); opacity: 1; } }/* Ayarlar Modalı */#settings-modal { display: none; position: fixed; top: 75px; right: 20px; width: 250px; z-index: 200; padding: 20px; flex-direction: column; gap: 15px; }.setting-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }select, input { background: transparent; color: var(--text-main); border: 1px solid var(--border-color); padding: 5px; border-radius: 4px; outline: none; }.light-mode select option { background: #fff; color: #000; }.light-mode select { background: #fff; }/* Əsas Layout */.main-layout { display: flex; flex: 1; overflow: hidden; padding: 0 10px 10px 10px; gap: 10px; opacity: 0; animation: fadeIn 1s forwards 3.8s; }@keyframes fadeIn { to { opacity: 1; } }/* Sol Panel (Advanced VFS) */.sidebar-left { width: 260px; display: flex; flex-direction: column; transition: 0.3s; }.sidebar-left.collapsed { width: 0; opacity: 0; margin: 0; border: none; }.panel-header { padding: 15px; font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--text-muted); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }.file-actions i { cursor: pointer; transition: 0.2s; margin-left: 8px; font-size: 14px; }.file-actions i:hover { color: var(--accent); }.file-tree { flex: 1; overflow-y: auto; padding: 10px; font-size: 13.5px; }.folder-item { margin-bottom: 5px; cursor: pointer; user-select: none; }.folder-title { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 4px; color: var(--text-main); font-weight: 500;}.folder-title:hover { background: rgba(128,128,128,0.1); }.folder-content { margin-left: 15px; padding-left: 10px; border-left: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 2px; margin-top: 5px;}.file-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-radius: 4px; cursor: pointer; color: var(--text-muted); transition: 0.2s; }.file-item:hover { color: var(--text-main); background: rgba(128,128,128,0.1); }.file-item.active { background: rgba(0, 242, 254, 0.1); color: var(--text-main); border-left: 2px solid var(--accent); }.del-btn { opacity: 0; color: #f87171; transition: 0.2s; }.file-item:hover .del-btn { opacity: 1; }/* Orta Panel */.center-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }#editor-container { flex: 1; min-height: 100px; background: var(--editor-bg); border-radius: var(--radius) var(--radius) 0 0; }.resizer { height: 6px; cursor: ns-resize; background: transparent; transition: 0.2s; z-index: 50; border-top: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color); }.resizer:hover { background: var(--accent); }/* Alt Panel */.bottom-panel { height: 280px; min-height: 100px; display: flex; flex-direction: column; background: var(--bg-panel); border-radius: 0 0 var(--radius) var(--radius); }.bottom-tabs { display: flex; border-bottom: 1px solid var(--border-color); background: rgba(0,0,0,0.2); }.tab { padding: 10px 20px; font-size: 12px; cursor: pointer; color: var(--text-muted); transition: 0.2s; border-right: 1px solid var(--border-color); }.tab.active { color: var(--accent); background: transparent; border-bottom: 2px solid var(--accent); }.tab-content { flex: 1; overflow: hidden; display: none; }.tab-content.active { display: flex; flex-direction: column; }#terminal-output { flex: 1; padding: 15px; font-family: 'Consolas', monospace; font-size: 14px; color: #d1d1d1; overflow-y: auto; white-space: pre-wrap; line-height: 1.6; }.light-mode #terminal-output { color: #333; }.ps-cmd { color: var(--accent); font-weight: bold; }.ps-err { color: #f87171; }.ps-ok { color: #4ade80; }#browser-frame { flex: 1; border: none; width: 100%; height: 100%; background: #fff; }/* Sağ Panel (Exypos AI) */.sidebar-right { width: 320px; display: flex; flex-direction: column; transition: 0.3s; }.sidebar-right.collapsed { width: 0; opacity: 0; margin: 0; border: none; }#ai-chat { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; font-size: 13.5px; }.msg { padding: 10px 15px; border-radius: 8px; max-width: 90%; line-height: 1.5; }.msg.user { background: rgba(0, 242, 254, 0.1); border: 1px solid var(--accent); align-self: flex-end; }.msg.ai { background: rgba(128, 128, 128, 0.1); border: 1px solid var(--border-color); align-self: flex-start; }.ai-input-zone { padding: 15px; border-top: 1px solid var(--border-color); display: flex; gap: 10px; }.ai-input-zone input { flex: 1; background: transparent; border: 1px solid var(--border-color); color: var(--text-main); padding: 8px; border-radius: 4px; outline: none; }</style><script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script></head><body><div class="liquid-bg"><div class="shape shape-1"></div><div class="shape shape-2"></div></div><div id="splash"><div class="splash-text">TWENTY</div><div class="splash-sub">Premium Environment</div></div><div class="panel-glass top-bar" id="top-bar"><div class="brand"><button class="icon-btn" onclick="togglePanel('left')" style="background:transparent; border:none; color:var(--text-muted); cursor:pointer;"><i class="fa-solid fa-folder-tree"></i></button><i class="fa-solid fa-code"></i> TWENTY IDE <span style="color:var(--text-muted); font-size:12px;">| <span id="current-file-label">main.py</span></span></div><div class="controls"><button class="btn" onclick="toggleSettings()"><i class="fa-solid fa-gear"></i> Ayarlar</button><button class="btn" onclick="togglePanel('right')"><i class="fa-solid fa-robot"></i> Exypos AI</button><button class="btn btn-run" onclick="runCode()"><i class="fa-solid fa-play"></i> İcra Et</button></div></div><div class="panel-glass" id="settings-modal"><div class="panel-header" style="padding:0 0 10px 0;">Sistem Ayarları</div><div class="setting-row">Mövzu:<select id="theme-select" onchange="changeTheme()"><option value="dark">Tünd (Gece)</option><option value="light">Açıq (Gündüz)</option></select></div></div><div class="main-layout"><div class="panel-glass sidebar-left" id="sidebar-left"><div class="panel-header">Fayl Sistemi<div class="file-actions"><i class="fa-solid fa-folder-plus" onclick="createFolder()" title="Qovluq Yarat"></i><i class="fa-solid fa-file-circle-plus" onclick="createFile()" title="Fayl Yarat"></i></div></div><div class="file-tree" id="file-tree"></div></div><div class="panel-glass center-panel"><div id="editor-container"></div><div class="resizer" id="resizer"></div><div class="bottom-panel" id="bottom-panel"><div class="bottom-tabs"><div class="tab active" onclick="switchTab('terminal')"><i class="fa-solid fa-terminal"></i> Terminal / Console</div><div class="tab" onclick="switchTab('browser')"><i class="fa-brands fa-chrome"></i> Browser Preview</div><i class="fa-solid fa-broom" style="margin-left:auto; margin-right:15px; margin-top:8px; cursor:pointer; color:var(--text-muted);" onclick="clearTerminal()" title="Təmizlə"></i></div><div class="tab-content active" id="tab-terminal"><div id="terminal-output"><span style="color:#888;">// Twenty Engine Başladı...</span><span style="color:#888;">// Məsləhət: Konsol komandası (pip install, ls) üçün kodun əvvəlinə ! qoyub İcra Et basın.</span><br></div></div><div class="tab-content" id="tab-browser"><iframe id="browser-frame"></iframe></div></div></div><div class="panel-glass sidebar-right collapsed" id="sidebar-right"><div class="panel-header">EXYPOS AI Köməkçi</div><div id="ai-chat"><div class="msg ai">Salam! Mən Exypos. Sənə kod yazmaqda necə kömək edə bilərəm?</div></div><div class="ai-input-zone"><input type="text" id="ai-input" placeholder="Sualını yaz..." onkeypress="if(event.key === 'Enter') askAI()"><button onclick="askAI()" style="background:transparent; border:none; cursor:pointer;"><i class="fa-solid fa-paper-plane" style="color:var(--accent); font-size:16px;"></i></button></div></div></div><script>// --- GİRİŞ ANİMASİYASI ZAMANLAMASI ---window.onload = () => {setTimeout(() => {const splash = document.getElementById('splash');splash.style.opacity = '0';setTimeout(() => {splash.remove();}, 1000);}, 3800);};// --- AYARLAR & MÖVZU ---function toggleSettings() {const modal = document.getElementById('settings-modal');modal.style.display = modal.style.display === 'flex' ? 'none' : 'flex';}function changeTheme() {const isLight = document.getElementById('theme-select').value === 'light';if(isLight) {document.body.classList.add('light-mode');if(editor) monaco.editor.setTheme('vs-light');} else {document.body.classList.remove('light-mode');if(editor) monaco.editor.setTheme('vs-dark');}}function togglePanel(side) {document.getElementById(`sidebar-${side}`).classList.toggle('collapsed');if(editor) setTimeout(() => editor.layout(), 300);}// --- BOTTOM TABS (Terminal vs Browser) ---function switchTab(tabId) {document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));document.querySelectorAll('.tab-content').forEach(tc => tc.classList.remove('active'));event.currentTarget.classList.add('active');document.getElementById(`tab-${tabId}`).classList.add('active');}// --- VİRTUAL FAYL SİSTEMİ ---let vfs = {"root": {"main.py": "# Python kodunuz\\n\\nprint('Salam Twenty IDE!')\\n\\n# Qeyd: Terminal komandası üçün ! istifadə edin.\\n# Məsələn: !pip install requests","Web": {"index.html": "<!DOCTYPE html>\\n<html>\\n<head><style>body{background:#222;color:#fff;font-family:sans-serif;text-align:center;padding:50px;}</style></head>\\n<body>\\n <h1>Twenty Veb Server</h1>\\n <p>Browser tabında dərhal işləyir!</p>\\n</body>\\n</html>"}}};let currentFilePath = ["root", "main.py"];let editor;function getFileIcon(name) {if(name.endsWith('.py')) return '<i class="fa-brands fa-python" style="color:#ffeb3b;"></i>';if(name.endsWith('.html')) return '<i class="fa-brands fa-html5" style="color:#e34f26;"></i>';if(name.endsWith('.js')) return '<i class="fa-brands fa-js" style="color:#f7df1e;"></i>';return '<i class="fa-solid fa-file-code" style="color:#aaa;"></i>';}function renderVFS() {const tree = document.getElementById('file-tree');tree.innerHTML = "";for(let folderName in vfs) {const folderDiv = document.createElement('div');folderDiv.className = 'folder-item';folderDiv.innerHTML = `<div class="folder-title"><i class="fa-solid fa-folder-open" style="color:#eac54f;"></i> ${folderName}</div>`;const contentDiv = document.createElement('div');contentDiv.className = 'folder-content';for(let fileName in vfs[folderName]) {const isActive = (currentFilePath[0] === folderName && currentFilePath[1] === fileName) ? 'active' : '';const fileDiv = document.createElement('div');fileDiv.className = `file-item ${isActive}`;fileDiv.innerHTML = `<div style="display:flex; align-items:center; gap:8px;" onclick="openFile('${folderName}', '${fileName}')">${getFileIcon(fileName)} <span>${fileName}</span></div><i class="fa-solid fa-trash del-btn" onclick="deleteFile('${folderName}', '${fileName}', event)"></i>`;contentDiv.appendChild(fileDiv);}folderDiv.appendChild(contentDiv);tree.appendChild(folderDiv);}document.getElementById('current-file-label').innerText = currentFilePath[1];}function openFile(folder, file) {if(editor) vfs[currentFilePath[0]][currentFilePath[1]] = editor.getValue();currentFilePath = [folder, file];editor.setValue(vfs[folder][file]);let lang = "plaintext";if(file.endsWith('.py')) lang = "python";else if(file.endsWith('.html')) lang = "html";else if(file.endsWith('.js')) lang = "javascript";monaco.editor.setModelLanguage(editor.getModel(), lang);renderVFS();}function createFolder() {const name = prompt("Yeni qovluq adı:");if(name && !vfs[name]) {vfs[name] = {};renderVFS();}}function createFile() {const folder = prompt("Hansı qovluğa? Mövcud: " + Object.keys(vfs).join(', '), "root");if(folder && vfs[folder]) {const name = prompt("Faylın adı (məs: test.py):");if(name && !vfs[folder][name]) {vfs[folder][name] = "# " + name;openFile(folder, name);}}}function deleteFile(folder, file, event) {event.stopPropagation();if(confirm(`${file} silinsin?`)) {delete vfs[folder][file];if(currentFilePath[0] === folder && currentFilePath[1] === file) {const fallbackFolder = Object.keys(vfs)[0];const fallbackFile = Object.keys(vfs[fallbackFolder])[0];if(fallbackFile) openFile(fallbackFolder, fallbackFile);else editor.setValue("");}renderVFS();}}// --- İCRA SİSTEMİ ---async function runCode() {if(!editor) return;vfs[currentFilePath[0]][currentFilePath[1]] = editor.getValue();const code = editor.getValue();const filename = currentFilePath[1];if(filename.endsWith('.html')) {document.querySelectorAll('.tab')[1].click(); // Browser tabını açconst frame = document.getElementById('browser-frame');frame.srcdoc = code;return;}document.querySelectorAll('.tab')[0].click(); // Terminal tabını açconst term = document.getElementById('terminal-output');const isShell = code.trim().startsWith('!');if(isShell) {term.innerHTML += `<br><span class="ps-cmd">Twenty Shell></span> ${code.trim()}<br><span style="color:#888">Terminal komandası icra olunur (Zaman ala bilər)...</span>`;} else {term.innerHTML += `<br><span class="ps-cmd">PS C:\\Twenty></span> python ${filename}<br><span style="color:#888">İcra olunur...</span>`;}term.scrollTop = term.scrollHeight;try {const response = await fetch('/run', {method: 'POST',1 unmodified linebody: JSON.stringify({ code: code, is_shell: isShell })});const data = await response.json();if (data.status === 'success') {term.innerHTML += `<br><span class="ps-ok">${data.output}</span>`;} else {term.innerHTML += `<br><span class="ps-err">${data.output}</span>`;}} catch (error) {term.innerHTML += `<br><span class="ps-err">Bağlantı xətası!</span>`;}term.scrollTop = term.scrollHeight;}function clearTerminal() {document.getElementById('terminal-output').innerHTML = `<span class="ps-cmd">Twenty></span> Konsol təmizləndi...`;}// --- EXYPOS AI ---async function askAI() {const inputEl = document.getElementById('ai-input');const prompt = inputEl.value.trim();if(!prompt) return;const chat = document.getElementById('ai-chat');chat.innerHTML += `<div class="msg user">${prompt}</div>`;inputEl.value = '';chat.scrollTop = chat.scrollHeight;const typingId = "type-" + Date.now();chat.innerHTML += `<div class="msg ai" id="${typingId}">...</div>`;try {const contextCode = editor ? editor.getValue() : "";const response = await fetch('/ask_ai', {2 unmodified linesbody: JSON.stringify({ prompt: prompt, code: contextCode })});const data = await response.json();document.getElementById(typingId).innerHTML = data.reply.replace(/\\n/g, '<br>');} catch (e) {document.getElementById(typingId).innerHTML = "<span style='color:red'>AI Bağlantı xətası.</span>";}chat.scrollTop = chat.scrollHeight;}// --- SÜRÜŞDÜRÜCÜ ---const resizer = document.getElementById('resizer');const bottomPanel = document.getElementById('bottom-panel');let isResizing = false;1 unmodified linedocument.addEventListener('mousemove', (e) => {if (!isResizing) return;const containerHeight = document.querySelector('.center-panel').clientHeight;const newHeight = containerHeight - e.clientY + 50;if (newHeight > 100 && newHeight < containerHeight - 100) {bottomPanel.style.height = `${newHeight}px`;bottomPanel.style.flex = 'none';if(editor) editor.layout();}});document.addEventListener('mouseup', () => { isResizing = false; document.body.style.cursor = 'default'; });// --- 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[currentFilePath[0]][currentFilePath[1]],language: 'python',theme: 'vs-dark',automaticLayout: true,fontSize: 15,minimap: { enabled: false },padding: { top: 15 }});editor.onDidChangeModelContent(() => {vfs[currentFilePath[0]][currentFilePath[1]] = editor.getValue();});renderVFS();});</script></body></html>12 unmodified linesif not code.strip():return jsonify({"status": "error", "output": "Boş kod göndərildi."})if is_shell:shell_cmd = code.strip()[1:]try:result = subprocess.run(shell_cmd, shell=True, capture_output=True, text=True, timeout=30)output = result.stdout if result.returncode == 0 else result.stderrstatus = "success" if result.returncode == 0 else "error"return jsonify({"status": status, "output": output})except subprocess.TimeoutExpired:return jsonify({"status": "error", "output": "Vaxt bitdi (30 saniyə limit)."})except Exception as e:return jsonify({"status": "error", "output": str(e)})with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False, encoding='utf-8') as temp_file:temp_file.write(code)temp_filepath = temp_file.nametry:result = subprocess.run(['python', temp_filepath], capture_output=True, text=True, timeout=10)if result.returncode == 0:return jsonify({"status": "success", "output": result.stdout})else:return jsonify({"status": "error", "output": result.stderr if result.stderr else result.stdout})except subprocess.TimeoutExpired:return jsonify({"status": "error", "output": "Vaxt bitdi (10 saniyə limit)."})except Exception as e:return jsonify({"status": "error", "output": str(e)})finally:4 unmodified linesdef ask_ai():if not client_groq:return jsonify({"reply": "Xəta: Groq API Key (GROQ_API_KEY) tapılmadı."})data = request.jsonprompt = data.get('prompt', '')context_code = data.get('code', '')system_msg = "Sən Exypos AI-san. Twenty IDE-nin köməkçisisən. Qısa, dəqiq və azərbaycanca cavab ver."user_msg = f"Sual: {prompt}\\n\\nHazırki kodum:\\n```\\n{context_code}\\n```"try:# XƏTA BURADA İDİ: Model yeniləndi!chat_completion = client_groq.chat.completions.create(messages=[{"role": "system", "content": system_msg},{"role": "user", "content": user_msg}],model="llama-3.1-8b-instant",temperature=0.5,max_tokens=1000)return jsonify({"reply": chat_completion.choices[0].message.content})except Exception as e:return jsonify({"reply": f"AI Xətası: {str(e)}"})if __name__ == "__main__":app.run(host="0.0.0.0", port=7860, debug=False)12345679 unmodified lines17181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472481 unmodified line2502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922 unmodified lines2952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423431 unmodified line34534634734834935035135235335435535635735812 unmodified lines3713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004 unmodified lines405406407408409410411412413414415416417418419420421422423424425426427428429430431432iimport osimport subprocessimport tempfileimport jsonfrom flask import Flask, render_template_string, request, jsonifyfrom groq import Groq9 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Twenty IDE | Liquid Antigravity</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"><style>/* --- LIQUID GLASS DƏYİŞƏNLƏRİ --- */:root {--bg-base: #020205;--glass-bg: rgba(20, 20, 30, 0.4);--glass-border: rgba(255, 255, 255, 0.08);--glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);--text-main: #f4f4f5;--text-muted: #888899;--accent: #00f2fe;--liquid-1: #00f2fe;--liquid-2: #4facfe;--liquid-3: #7f00ff;--radius: 16px;}* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }body { background-color: var(--bg-base); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }/* --- ARXA PLAN MAYE (LIQUID) ANİMASİYASI --- */.liquid-bg { position: fixed; inset: 0; z-index: -2; overflow: hidden; background: var(--bg-base); }.blob { position: absolute; filter: blur(90px); opacity: 0.5; animation: blobMove 20s infinite alternate cubic-bezier(0.4, 0, 0.2, 1); }.blob-1 { width: 60vw; height: 60vw; background: var(--liquid-1); top: -20%; left: -10%; border-radius: 40% 60% 70% 30%; }.blob-2 { width: 50vw; height: 50vw; background: var(--liquid-3); bottom: -20%; right: -10%; border-radius: 60% 40% 30% 70%; animation-delay: -5s; }@keyframes blobMove {0% { transform: translate(0, 0) scale(1) rotate(0deg); border-radius: 40% 60% 70% 30%; }50% { transform: translate(10vw, 10vh) scale(1.1) rotate(45deg); border-radius: 60% 40% 30% 70%; }100% { transform: translate(-10vw, -10vh) scale(0.9) rotate(90deg); border-radius: 30% 70% 50% 50%; }}/* --- RAKET LIFTOFF (SPLASH) --- */#rocket-splash {position: fixed; inset: 0; background: #020205; z-index: 9999;display: flex; flex-direction: column; justify-content: center; align-items: center;}.rocket-icon { font-size: 100px; animation: liftoff 3.5s cubic-bezier(0.5, 0, 0.2, 1) forwards; }.splash-text { font-size: 40px; font-weight: 300; letter-spacing: 15px; margin-top: 20px; color: transparent; text-shadow: 0 0 20px var(--accent); animation: fadeOutText 3s forwards; }@keyframes liftoff {0% { transform: translateY(200px) scale(1); opacity: 1; filter: drop-shadow(0 20px 20px #ff9800); }40% { transform: translateY(0px) scale(1.1); opacity: 1; filter: drop-shadow(0 50px 30px #ff5722); }100% { transform: translateY(-1000px) scale(0.5); opacity: 0; filter: drop-shadow(0 100px 50px transparent); }}@keyframes fadeOutText { 0%, 50% { opacity: 1; } 100% { opacity: 0; letter-spacing: 30px; } }/* --- LIQUID GLASS PANELLƏR --- */.glass-panel {background: var(--glass-bg);backdrop-filter: blur(16px);-webkit-backdrop-filter: blur(16px);border: 1px solid var(--glass-border);border-radius: var(--radius);box-shadow: var(--glass-shadow);}/* --- SLIDE-IN ANİMASİYALARI --- */.top-bar { height: 65px; margin: 15px; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; z-index: 100; transform: translateY(-100px); opacity: 0; animation: slideDown 1s cubic-bezier(0.16, 1, 0.3, 1) forwards 3s; }.sidebar-left { width: 280px; display: flex; flex-direction: column; transform: translateX(-350px); opacity: 0; animation: slideRight 1s cubic-bezier(0.16, 1, 0.3, 1) forwards 3.2s; transition: width 0.3s; }.sidebar-right { width: 350px; display: flex; flex-direction: column; transform: translateX(400px); opacity: 0; animation: slideLeft 1s cubic-bezier(0.16, 1, 0.3, 1) forwards 3.4s; transition: width 0.3s; }.center-panel { flex: 1; display: flex; flex-direction: column; transform: scale(0.9); opacity: 0; animation: popIn 1s cubic-bezier(0.16, 1, 0.3, 1) forwards 3.6s; }.bottom-panel { height: 300px; display: flex; flex-direction: column; border-radius: 0 0 var(--radius) var(--radius); }@keyframes slideDown { to { transform: translateY(0); opacity: 1; } }@keyframes slideRight { to { transform: translateX(0); opacity: 1; } }@keyframes slideLeft { to { transform: translateX(0); opacity: 1; } }@keyframes popIn { to { transform: scale(1); opacity: 1; } }/* --- UI ELEMENTLƏRİ --- */.brand { font-size: 18px; font-weight: 600; letter-spacing: 2px; display: flex; align-items: center; gap: 15px; }.controls { display: flex; align-items: center; gap: 15px; }.btn { background: rgba(255,255,255,0.05); color: var(--text-main); border: 1px solid var(--glass-border); padding: 10px 18px; border-radius: 8px; cursor: pointer; transition: 0.3s; font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; backdrop-filter: blur(5px);}.btn:hover { background: rgba(255,255,255,0.1); border-color: var(--accent); box-shadow: 0 0 15px rgba(0,242,254,0.3); }.btn-run { background: rgba(0, 242, 254, 0.15); border-color: var(--accent); color: var(--accent); }.btn-run:hover { background: var(--accent); color: #fff; box-shadow: 0 0 20px var(--accent); transform: translateY(-2px); }.main-layout { display: flex; flex: 1; overflow: hidden; padding: 0 15px 15px 15px; gap: 15px; }.panel-header { padding: 18px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; color: var(--accent); border-bottom: 1px solid var(--glass-border); display: flex; justify-content: space-between; align-items: center; }/* Editor Area */#editor-container { flex: 1; background: transparent; border-radius: var(--radius) var(--radius) 0 0; overflow: hidden;}.resizer { height: 8px; cursor: ns-resize; background: transparent; transition: 0.3s; z-index: 50; }.resizer:hover { background: var(--accent); opacity: 0.5; }/* Terminal & Tabs */.bottom-tabs { display: flex; border-bottom: 1px solid var(--glass-border); background: rgba(0,0,0,0.2); }.tab { padding: 12px 25px; font-size: 13px; cursor: pointer; color: var(--text-muted); transition: 0.3s; border-right: 1px solid var(--glass-border); }.tab.active { color: var(--accent); background: rgba(0,242,254,0.05); border-bottom: 2px solid var(--accent); }.tab-content { flex: 1; overflow: hidden; display: none; background: rgba(0,0,0,0.4); }.tab-content.active { display: flex; flex-direction: column; }#terminal-output { flex: 1; padding: 20px; font-family: 'Consolas', monospace; font-size: 14px; color: #e2e8f0; overflow-y: auto; white-space: pre-wrap; line-height: 1.6; }.ps-cmd { color: var(--accent); font-weight: bold; }.ps-err { color: #ff4757; }.ps-ok { color: #2ed573; }/* Exypos AI Chat */#ai-chat { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; font-size: 14px; }.msg { padding: 12px 18px; border-radius: 12px; max-width: 90%; line-height: 1.6; box-shadow: 0 4px 15px rgba(0,0,0,0.2); }.msg.user { background: rgba(0, 242, 254, 0.15); border: 1px solid var(--accent); align-self: flex-end; border-bottom-right-radius: 2px; }.msg.ai { background: rgba(255, 255, 255, 0.05); border: 1px solid var(--glass-border); align-self: flex-start; border-bottom-left-radius: 2px; }.ai-input-zone { padding: 15px; border-top: 1px solid var(--glass-border); display: flex; gap: 10px; background: rgba(0,0,0,0.2); border-radius: 0 0 var(--radius) var(--radius); }.ai-input-zone input { flex: 1; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); color: var(--text-main); padding: 12px; border-radius: 8px; outline: none; transition: 0.3s; }.ai-input-zone input:focus { border-color: var(--accent); background: rgba(0,0,0,0.5); }/* AI Editor Actions */.ai-action-btn { background: var(--accent); color: #000; border: none; padding: 6px 12px; border-radius: 4px; font-size: 12px; font-weight: bold; cursor: pointer; margin-top: 8px; transition: 0.2s; }.ai-action-btn:hover { box-shadow: 0 0 10px var(--accent); }.terminal-ai-btn { background: transparent; border: 1px solid #ff4757; color: #ff4757; padding: 4px 10px; border-radius: 4px; cursor: pointer; margin-top: 5px; font-size: 12px; transition: 0.2s; }.terminal-ai-btn:hover { background: #ff4757; color: #fff; }pre { background: #000; padding: 10px; border-radius: 6px; overflow-x: auto; border: 1px solid var(--glass-border); margin-top: 5px; }code { font-family: 'Consolas', monospace; color: #a8b2d1; }</style><script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script></head><body><div class="liquid-bg"><div class="blob blob-1"></div><div class="blob blob-2"></div></div><div id="rocket-splash"><div class="rocket-icon">🚀</div><div class="splash-text">LIFTOFF</div></div><div class="glass-panel top-bar" id="top-bar"><div class="brand"><i class="fa-solid fa-meteor" style="color:var(--accent); font-size:24px;"></i>TWENTY OS <span style="color:var(--text-muted); font-weight:400; font-size:14px;">| Exypos Engine</span></div><div class="controls"><button class="btn btn-run" onclick="runCode()"><i class="fa-solid fa-play"></i> Kodu İcra Et</button></div></div><div class="main-layout"><div class="glass-panel sidebar-left" id="sidebar-left"><div class="panel-header">Fayl Sistemi</div><div id="file-tree" style="padding: 15px; font-size: 14px; color: var(--text-main);"><i class="fa-brands fa-python" style="color:#ffeb3b;"></i> main.py</div></div><div class="center-panel"><div class="glass-panel" id="editor-container" style="flex: 1; border-radius: var(--radius); border-bottom-left-radius: 0; border-bottom-right-radius: 0;"></div><div class="resizer" id="resizer"></div><div class="glass-panel bottom-panel" id="bottom-panel" style="border-top-left-radius: 0; border-top-right-radius: 0; border-top: none;"><div class="bottom-tabs"><div class="tab active" onclick="switchTab('terminal')"><i class="fa-solid fa-terminal"></i> Terminal</div><i class="fa-solid fa-broom" style="margin-left:auto; margin-right:20px; margin-top:12px; cursor:pointer; color:var(--text-muted);" onclick="clearTerminal()"></i></div><div class="tab-content active" id="tab-terminal"><div id="terminal-output"><span style="color:#888;">// Twenty OS Terminalı Hazırdır...</span><br><span style="color:#888;">// 'pip install' üçün komandanın əvvəlinə ! qoyun.</span><br></div></div></div></div><div class="glass-panel sidebar-right" id="sidebar-right"><div class="panel-header"><i class="fa-solid fa-robot"></i> EXYPOS AI</div><div id="ai-chat"><div class="msg ai">Sistemlər aktivdir, komandir. Kodunu oxuyuram. Xəta olarsa, mənə göndər.</div></div><div class="ai-input-zone"><input type="text" id="ai-input" placeholder="Sualını yaz..." onkeypress="if(event.key === 'Enter') askAI()"><button onclick="askAI()" style="background:transparent; border:none; cursor:pointer;"><i class="fa-solid fa-paper-plane" style="color:var(--accent); font-size:20px;"></i></button></div></div></div><script>// Splash Animasiyasıwindow.onload = () => {setTimeout(() => {const splash = document.getElementById('rocket-splash');splash.style.display = 'none';}, 3500);};// Editor & Variableslet editor;let lastAiCode = ""; // AI tərəfindən göndərilən son kodrequire.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: "# Twenty OS: Anti-Gravity Mode Active\\nprint('Hello Universe!')\\n",language: 'python',theme: 'vs-dark',automaticLayout: true,fontSize: 15,minimap: { enabled: false },padding: { top: 20 },scrollBeyondLastLine: false});// Glassmorphism üçün editor arxasını şəffaf etməkdocument.querySelector('.monaco-editor').style.background = 'transparent';document.querySelector('.monaco-editor .margin').style.background = 'transparent';});// Tabsfunction switchTab(tabId) {document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));document.querySelectorAll('.tab-content').forEach(tc => tc.classList.remove('active'));event.currentTarget.classList.add('active');document.getElementById(`tab-${tabId}`).classList.add('active');}// İcra Et & Shell (PIP)async function runCode() {if(!editor) return;const code = editor.getValue();const term = document.getElementById('terminal-output');const isShell = code.trim().startsWith('!');if(isShell) {term.innerHTML += `<br><span class="ps-cmd">Twenty></span> ${code.trim()}<br><span style="color:#888">Shell komandası icra olunur...</span>`;} else {term.innerHTML += `<br><span class="ps-cmd">Twenty></span> python main.py<br><span style="color:#888">İcra olunur...</span>`;}term.scrollTop = term.scrollHeight;try {const response = await fetch('/run', {method: 'POST',1 unmodified linebody: JSON.stringify({ code: code, is_shell: isShell })});const data = await response.json();if (data.status === 'success') {term.innerHTML += `<br><span class="ps-ok">${escapeHtml(data.output)}</span>`;} else {// Xəta olduqda AI-dan soruşmaq üçün düymə əlavə ediriklet safeError = encodeURIComponent(data.output.substring(0, 500));term.innerHTML += `<br><span class="ps-err">${escapeHtml(data.output)}</span><br><button class="terminal-ai-btn" onclick="askAiAboutError('${safeError}')"><i class="fa-solid fa-wand-magic-sparkles"></i> Exypos-a Soruş</button>`;}} catch (error) {term.innerHTML += `<br><span class="ps-err">Sistem Xətası!</span>`;}term.scrollTop = term.scrollHeight;}function clearTerminal() {document.getElementById('terminal-output').innerHTML = `<span class="ps-cmd">Twenty></span> Terminal təmizləndi...`;}function escapeHtml(text) {return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");}// Exypos AI - Smart Chatasync function askAI() {const inputEl = document.getElementById('ai-input');const prompt = inputEl.value.trim();if(!prompt) return;const chat = document.getElementById('ai-chat');chat.innerHTML += `<div class="msg user">${escapeHtml(prompt)}</div>`;inputEl.value = '';chat.scrollTop = chat.scrollHeight;const typingId = "type-" + Date.now();chat.innerHTML += `<div class="msg ai" id="${typingId}">Düşünürəm... 🚀</div>`;chat.scrollTop = chat.scrollHeight;try {const contextCode = editor ? editor.getValue() : "";const response = await fetch('/ask_ai', {2 unmodified linesbody: JSON.stringify({ prompt: prompt, code: contextCode })});const data = await response.json();// Kodu tapmaq və düymə əlavə etməklet rawReply = escapeHtml(data.reply);// Əgər cavabda python kodu varsa, tuturuqconst codeMatch = data.reply.match(/```(?:python)?\\n([\\s\\S]*?)```/);if(codeMatch) {lastAiCode = codeMatch[1].trim();// Markdown kod blokunu HTML-ə çeviririk və "Kodu Editora Yaz" düyməsi əlavə edirikrawReply = rawReply.replace(/```(?:python)?\\n([\\s\\S]*?)```/g,`</p><pre><code>$1</code></pre><button class="ai-action-btn" onclick="insertAiCode()"><i class="fa-solid fa-code-merge"></i> Kodu Editora Yaz</button><p>`);}document.getElementById(typingId).innerHTML = rawReply.replace(/\\n/g, '<br>');} catch (e) {document.getElementById(typingId).innerHTML = "<span style='color:#ff4757'>Bağlantı xətası.</span>";}chat.scrollTop = chat.scrollHeight;}// Exypos kodunu birbaşa editora yazan funksiyafunction insertAiCode() {if(editor && lastAiCode) {// Kodu editorun mövcud koduna əlavə edir və ya əvəz edir (istəsən setValue ilə tam silib yaza bilərsən)const selection = editor.getSelection();editor.executeEdits("ai-insert", [{range: selection,text: lastAiCode,forceMoveMarkers: true}]);document.getElementById('terminal-output').innerHTML += `<br><span style="color:var(--accent)">[Exypos AI]</span> Kod editora uğurla əlavə edildi.<br>`;}}// Terminaldakı xətanı birbaşa Exypos-a göndərirfunction askAiAboutError(encodedError) {const decodedError = decodeURIComponent(encodedError);const inputEl = document.getElementById('ai-input');inputEl.value = "Bu xətanı necə həll edim? Xəta: " + decodedError;askAI();}// Resizer (Sürüşdürücü)const resizer = document.getElementById('resizer');const bottomPanel = document.getElementById('bottom-panel');let isResizing = false;1 unmodified linedocument.addEventListener('mousemove', (e) => {if (!isResizing) return;const containerHeight = document.querySelector('.center-panel').clientHeight;const newHeight = containerHeight - e.clientY + 65;if (newHeight > 100 && newHeight < containerHeight - 100) {bottomPanel.style.height = `${newHeight}px`;bottomPanel.style.flex = 'none';if(editor) editor.layout();}});document.addEventListener('mouseup', () => { isResizing = false; document.body.style.cursor = 'default'; });</script></body></html>12 unmodified linesif not code.strip():return jsonify({"status": "error", "output": "Boş kod göndərildi."})# Terminal (Shell) komandası (Məs: !pip install requests)if is_shell:shell_cmd = code.strip()[1:]try:result = subprocess.run(shell_cmd, shell=True, capture_output=True, text=True, timeout=60)output = result.stdout if result.returncode == 0 else result.stderrstatus = "success" if result.returncode == 0 else "error"return jsonify({"status": status, "output": output})except Exception as e:return jsonify({"status": "error", "output": str(e)})# Python Kodu İcra Etməkwith tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False, encoding='utf-8') as temp_file:temp_file.write(code)temp_filepath = temp_file.nametry:result = subprocess.run(['python', temp_filepath], capture_output=True, text=True, timeout=15)if result.returncode == 0:return jsonify({"status": "success", "output": result.stdout})else:return jsonify({"status": "error", "output": result.stderr if result.stderr else result.stdout})except subprocess.TimeoutExpired:return jsonify({"status": "error", "output": "Vaxt bitdi (15 saniyə limit). Sonsuz dövrə (while True) düşmüş ola bilərsiniz."})except Exception as e:return jsonify({"status": "error", "output": str(e)})finally:4 unmodified linesdef ask_ai():if not client_groq:return jsonify({"reply": "Xəta: Groq API Key (GROQ_API_KEY) tapılmadı."})data = request.jsonprompt = data.get('prompt', '')context_code = data.get('code', '')# Exypos-a kod haqqında məlumat veririksystem_msg = "Sən Exypos AI-san, Twenty OS daxilində çalışan güclü kod köməkçisisən. Qısa, dəqiq və azərbaycanca cavab ver. Əgər kod düzəldirsənsə, mütləq mətndə yalnız python kodunu ```python ... ``` blokunun içinə yaz."user_msg = f"Sual: {prompt}\n\nHazırki kodum:\n```python\n{context_code}\n```"try:chat_completion = client_groq.chat.completions.create(messages=[{"role": "system", "content": system_msg},{"role": "user", "content": user_msg}],model="llama-3.1-8b-instant",temperature=0.5,max_tokens=1500)return jsonify({"reply": chat_completion.choices[0].message.content})except Exception as e:return jsonify({"reply": f"AI Bağlantı Xətası: {str(e)}"})if __name__ == "__main__":app.run(host="0.0.0.0", port=7860, debug=False)
app.py+214-369