Update app.py
Browse files15 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827915 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Twenty IDE | Learning & Pro Edition</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"><style>:root {--bg-base: #050505;--bg-panel: rgba(15, 15, 20, 0.8);--border-color: rgba(255, 255, 255, 0.1);--text-main: #f4f4f5;--text-muted: #888899;--accent: #00f2fe;--liquid-1: #00f2fe;--liquid-2: #4facfe;--radius: 12px;}* { 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; }/* Liquid BG */.liquid-bg { position: fixed; inset: 0; z-index: -1; background: var(--bg-base); }.shape { position: absolute; filter: blur(70px); opacity: 0.25; animation: liquid 20s infinite alternate; }.shape-1 { width: 50vw; height: 50vw; background: var(--liquid-1); top: -10%; left: -10%; }.shape-2 { width: 45vw; height: 45vw; background: var(--liquid-2); bottom: -10%; right: -10%; }@keyframes liquid { 0% { transform: rotate(0deg) scale(1); } 100% { transform: rotate(90deg) scale(1.2); } }/* Splash */#splash { position: fixed; inset: 0; background: #000; z-index: 9999; display: flex; justify-content: center; align-items: center; transition: 1s; }.splash-text { font-size: 50px; font-weight: 200; letter-spacing: 20px; animation: glow 3s infinite; }@keyframes glow { 0%, 100% { color: #fff; text-shadow: 0 0 10px var(--accent); } 50% { color: var(--accent); text-shadow: 0 0 30px #fff; } }/* Panellər */.panel { background: var(--bg-panel); backdrop-filter: blur(20px); border: 1px solid var(--border-color); border-radius: var(--radius); transition: 0.5s; opacity: 0; transform: scale(0.95); }.show-ui .panel { opacity: 1; transform: scale(1); }.top-bar { height: 60px; margin: 10px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; }.main-layout { display: flex; flex: 1; overflow: hidden; padding: 0 10px 10px 10px; gap: 10px; }/* Kitabxana Paneli */.sidebar-left { width: 280px; display: flex; flex-direction: column; }.lib-header { padding: 15px; font-size: 12px; font-weight: bold; border-bottom: 1px solid var(--border-color); color: var(--accent); }.lib-content { flex: 1; overflow-y: auto; padding: 10px; }.lib-item { padding: 12px; border-radius: 8px; background: rgba(255,255,255,0.03); margin-bottom: 10px; cursor: pointer; transition: 0.2s; border: 1px solid transparent; }.lib-item:hover { border-color: var(--accent); background: rgba(0, 242, 254, 0.05); }.lib-item h4 { font-size: 13px; margin-bottom: 5px; color: #fff; }.lib-item p { font-size: 11px; color: var(--text-muted); line-height: 1.4; }/* Editor */.center-panel { flex: 1; display: flex; flex-direction: column; }#editor-container { flex: 1; border-bottom: 1px solid var(--border-color); }.terminal { height: 200px; padding: 15px; font-family: monospace; font-size: 13px; overflow-y: auto; background: rgba(0,0,0,0.3); }/* AI */.sidebar-right { width: 300px; display: flex; flex-direction: column; }#ai-chat { flex: 1; padding: 15px; overflow-y: auto; font-size: 13px; }.ai-input-zone { padding: 10px; border-top: 1px solid var(--border-color); display: flex; gap: 5px; }.ai-input-zone input { flex: 1; background: #111; border: 1px solid #333; color: #fff; padding: 8px; border-radius: 5px; }.btn { padding: 8px 15px; border-radius: 6px; border: 1px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: bold; transition: 0.3s; }.btn:hover { background: var(--accent); color: #000; }/* Code Block in AI */.code-box { background: #000; padding: 10px; border-radius: 5px; border: 1px solid #333; margin: 10px 0; }.code-box pre { font-size: 11px; color: #00f2fe; overflow-x: auto; }.code-box button { background: var(--accent); border: none; padding: 3px 8px; font-size: 10px; border-radius: 3px; cursor: pointer; margin-top: 5px; font-weight: bold; }</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><div class="panel top-bar" id="top-bar"><div style="display:flex; align-items:center; gap:15px;"><i class="fa-solid fa-brain" style="color:var(--accent); font-size:20px;"></i><span style="font-weight:bold; letter-spacing:2px;">TWENTY PRO IDE</span></div><div style="display:flex; gap:15px;"><button class="btn" onclick="runCode()"><i class="fa-solid fa-play"></i> İCRA ET</button><button class="btn" onclick="clearTerminal()"><i class="fa-solid fa-broom"></i></button></div></div><div class="main-layout"><div class="panel sidebar-left"><div class="lib-header"><i class="fa-solid fa-book"></i> KOD KİTABXANASI</div><div class="lib-content" id="library"></div></div><div class="panel center-panel"><div id="editor-container"></div><div class="terminal" id="terminal-output">// Twenty Pro Engine Hazırdır...<br>>_ </div></div><div class="panel sidebar-right"><div class="lib-header"><i class="fa-solid fa-robot"></i> EXYPOS AI KÖMƏKÇİ</div><div id="ai-chat"></div><div class="ai-input-zone"><input type="text" id="ai-input" placeholder="Sual soruş..." onkeypress="if(event.key==='Enter') askAI()"><button class="btn" onclick="askAI()"><i class="fa-solid fa-paper-plane"></i></button></div></div></div><script>// --- DATA: HAZIR KODLAR ---const codeLibrary = [{title: "Döviz Məzənnəsi (API)",desc: "Real vaxtda valyuta kurslarını çəkir. 'requests' kitabxanası lazımdır.",code: "# !pip install requests\\nimport requests\\n\\ndef get_rate():\\n url = 'https://api.exchangerate-api.com/v4/latest/USD'\\n res = requests.get(url).json()\\n print(f'USD to AZN: {res[\\"rates\\"][\\"AZN\\"]}')\\n\\nget_rate()"},{title: "Veb Skraping (Sayt Çəkmək)",desc: "Hər hansı bir saytın başlığını çəkir. 'beautifulsoup4' lazımdır.",code: "# !pip install requests beautifulsoup4\\nimport requests\\nfrom bs4 import BeautifulSoup\\n\\nurl = 'https://google.com'\\nhtml = requests.get(url).text\\nsoup = BeautifulSoup(html, 'html.parser')\\nprint('Saytın Başlığı:', soup.title.string)"},{title: "Süni İntellekt (Sadə Regressiya)",desc: "Məlumatlar əsasında təxmin edir. 'numpy' və 'scikit-learn' lazımdır.",code: "# !pip install numpy scikit-learn\\nimport numpy as np\\nfrom sklearn.linear_model import LinearRegression\\n\\n# X = Saatlar, y = Qiymətlər\\nX = np.array([[1], [2], [3], [4]])\\ny = np.array([2, 4, 6, 8])\\n\\nmodel = LinearRegression().fit(X, y)\\nprint('5 saat üçün təxmin:', model.predict([[5]]))"}];// --- UI LOGIC ---window.onload = () => {setTimeout(() => {document.getElementById('splash').style.opacity = '0';setTimeout(() => {document.getElementById('splash').remove();document.body.classList.add('show-ui');}, 1000);}, 2500);renderLibrary();};function renderLibrary() {const lib = document.getElementById('library');codeLibrary.forEach(item => {const div = document.createElement('div');div.className = 'lib-item';div.innerHTML = `<h4>${item.title}</h4><p>${item.desc}</p>`;div.onclick = () => {editor.setValue(item.code);printTerminal(`// ${item.title} şablonu yükləndi.`);};lib.appendChild(div);});}// --- EDITOR & AI ---let editor;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: "# Salam Twenty Pro!\\n# Sol tərəfdən bir şablon seç və ya kod yaz.\\n# Kitabxana üçün !pip install komandasını işlət.",language: 'python',theme: 'vs-dark',automaticLayout: true,fontSize: 14,});});async function runCode() {const code = editor.getValue();printTerminal(`> İcra olunur...`);const res = await fetch('/run', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({ code: code })});const data = await res.json();printTerminal(data.output);}async function askAI() {const input = document.getElementById('ai-input');const chat = document.getElementById('ai-chat');const prompt = input.value;if(!prompt) return;chat.innerHTML += `<div style="color:var(--accent); margin-bottom:10px;"><b>Sən:</b> ${prompt}</div>`;input.value = "";const res = await fetch('/ask_ai', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({ prompt: prompt, code: editor.getValue() })});const data = await res.json();// Kod bloklarını təmizləmək və "At" düyməsi qoymaqlet reply = data.reply.replace(/```python([\\s\\S]*?)```/g, (match, code) => {const escaped = code.trim().replace(/"/g, '"').replace(/'/g, "\\'");return `<div class="code-box"><pre><code>${code.trim()}</code></pre><button onclick="injectCode('${escaped}')">Editora At</button></div>`;});chat.innerHTML += `<div style="margin-bottom:20px;"><b>Exypos:</b><br>${reply}</div>`;chat.scrollTop = chat.scrollHeight;}function injectCode(code) {const line = editor.getPosition();const range = new monaco.Range(line.lineNumber, 1, line.lineNumber, 1);editor.executeEdits("", [{ range: range, text: code + "\\n" }]);}function printTerminal(msg) {const term = document.getElementById('terminal-output');term.innerHTML += `<br>${msg.replace(/\\n/g, '<br>')}`;term.scrollTop = term.scrollHeight;}function clearTerminal() {document.getElementById('terminal-output').innerHTML = ">_ Terminal təmizləndi.";}</script></body></html>"""@app.route('/')def index(): return render_template_string(HTML_TEMPLATE)@app.route('/run', methods=['POST'])def run_code():code = request.json.get('code', '')# !pip install yoxlanışıif code.strip().startswith('!pip'):cmd = code.strip()[1:]res = subprocess.run(cmd, shell=True, capture_output=True, text=True)return jsonify({"output": res.stdout + res.stderr})with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:f.write(code)path = f.nametry:res = subprocess.run(['python', path], capture_output=True, text=True, timeout=10)return jsonify({"output": res.stdout if res.returncode == 0 else res.stderr})except: return jsonify({"output": "Vaxt bitdi."})finally: os.remove(path)@app.route('/ask_ai', methods=['POST'])def ask_ai():if not client_groq: return jsonify({"reply": "API Key Yoxdur."})p = request.json.get('prompt')c = request.json.get('code')try:completion = client_groq.chat.completions.create(model="llama-3.1-8b-instant",messages=[{"role": "system", "content": "Sən proqramlaşdırma müəllimisən. Kodları izah et və mütləq ```python ... ``` blokunda ver."},{"role": "user", "content": f"Kodum: {c}\\n\\nSual: {p}"}])return jsonify({"reply": completion.choices[0].message.content})except Exception as e: return jsonify({"reply": str(e)})if __name__ == "__main__":app.run(host="0.0.0.0", port=7860)15 unmodified lines16171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658715 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',headers: { 'Content-Type': 'application/json' },body: 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', {method: 'POST',headers: {'Content-Type': 'application/json'},body: 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;resizer.addEventListener('mousedown', () => { isResizing = true; document.body.style.cursor = 'ns-resize'; });document.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>"""@app.route('/')def index():return render_template_string(HTML_TEMPLATE)@app.route('/run', methods=['POST'])def run_code():data = request.jsoncode = data.get('code', '')is_shell = data.get('is_shell', False)if 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:if os.path.exists(temp_filepath):os.remove(temp_filepath)@app.route('/ask_ai', methods=['POST'])def 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)
app.py+489-181