Update app.py
Browse files15 unmodified lines1617181920212223242526273 unmodified lines3132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421432 unmodified lines1461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463475 unmodified lines3533543553563573585 unmodified lines36436536636736836937037137237337437537637737815 unmodified lines<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Twenty IDE | Final Workspace</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.7);--border-color: rgba(255, 255, 255, 0.1);--text-main: #f4f4f5;--text-muted: #888899;3 unmodified lines--radius: 12px;}.light-mode {--bg-base: #f0f2f5;--bg-panel: rgba(255, 255, 255, 0.8);--border-color: rgba(0, 0, 0, 0.1);--text-main: #111827;--text-muted: #6b7280;--accent: #0284c7;--liquid-1: #bae6fd;--liquid-2: #e0f2fe;}* { 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 ARXA PLAN */.liquid-bg { position: fixed; inset: 0; z-index: -1; background: var(--bg-base); }.shape { position: absolute; filter: blur(70px); opacity: 0.35; 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%; }.shape-2 { width: 45vw; height: 45vw; background: var(--liquid-2); bottom: -10%; right: -10%; border-radius: 60% 40%; animation-delay: -5s; }@keyframes liquidMorph { 0% { transform: translate(0,0) rotate(0deg); } 100% { transform: translate(10vw, 10vh) rotate(90deg); } }/* SPLASH SCREEN */#splash { position: fixed; inset: 0; background: #020204; z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: opacity 1.2s ease-in-out; }.splash-text { font-size: 65px; font-weight: 200; color: transparent; letter-spacing: 30px; animation: breatheMelt 3.5s forwards; }@keyframes breatheMelt {0% { opacity: 0; filter: blur(20px); text-shadow: 0 0 0px #00f2fe; transform: scale(1.1); }50% { opacity: 1; filter: blur(0px); text-shadow: 0 0 40px #00f2fe; transform: scale(1); color: #fff; }100% { opacity: 0; filter: blur(20px); transform: scale(0.9); }}/* ANİMASİYA BAŞLANĞICI (GİZLİ) */.panel-glass { background: var(--bg-panel); backdrop-filter: blur(25px); -webkit-backdrop-filter: blur(25px); border: 1px solid var(--border-color); border-radius: var(--radius); transition: 0.5s cubic-bezier(0.16, 1, 0.3, 1); }#top-bar { transform: translateY(-100px); opacity: 0; }#sidebar-left { transform: translateX(-300px); opacity: 0; }#center-panel { transform: translateY(300px); opacity: 0; }#sidebar-right { transform: translateX(400px); opacity: 0; }/* ANİMASİYA AKTİV (SÜRÜŞMƏ) */.show-ui #top-bar { transform: translateY(0); opacity: 1; }.show-ui #sidebar-left { transform: translateX(0); opacity: 1; transition-delay: 0.2s; }.show-ui #center-panel { transform: translateY(0); opacity: 1; transition-delay: 0.4s; }.show-ui #sidebar-right { transform: translateX(0); opacity: 1; transition-delay: 0.6s; }/* ÜST PANEL */.top-bar { height: 60px; margin: 10px; display: flex; justify-content: space-between; align-items: center; padding: 0 25px; z-index: 100; }.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(255,255,255,0.05); color: var(--text-main); border: 1px solid var(--border-color); padding: 8px 16px; border-radius: 8px; cursor: pointer; transition: 0.2s; font-size: 13px; display: flex; align-items: center; gap: 8px; }.btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(0, 242, 254, 0.1); }.btn-run { background: var(--accent); color: #000; border: none; font-weight: 700; }.btn-run:hover { background: #fff; color: #000; transform: translateY(-2px); box-shadow: 0 0 20px var(--accent); }/* LAYOUT */.main-layout { display: flex; flex: 1; overflow: hidden; padding: 0 10px 10px 10px; gap: 10px; }/* SIDEBARS */.sidebar-left { width: 260px; display: flex; flex-direction: column; overflow: hidden; }.sidebar-left.collapsed { width: 0; border: none; padding: 0; margin: 0; }.sidebar-right { width: 340px; display: flex; flex-direction: column; overflow: hidden; }.sidebar-right.collapsed { width: 0; border: none; padding: 0; margin: 0; }.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; background: rgba(0,0,0,0.1); }/* VFS TREE */.file-tree { flex: 1; overflow-y: auto; padding: 10px; font-size: 13.5px; }.file-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-radius: 6px; cursor: pointer; margin-bottom: 2px; transition: 0.2s; color: var(--text-muted); }.file-item:hover { background: rgba(255,255,255,0.05); color: #fff; }.file-item.active { background: rgba(0, 242, 254, 0.1); color: var(--accent); border-left: 3px solid var(--accent); }/* EDITOR */.center-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }#editor-container { flex: 1; background: rgba(0,0,0,0.3); }/* TERMINAL */.bottom-panel { height: 260px; display: flex; flex-direction: column; background: var(--bg-panel); }.tabs { display: flex; background: rgba(0,0,0,0.3); border-bottom: 1px solid var(--border-color); }.tab { padding: 10px 20px; font-size: 12px; cursor: pointer; color: var(--text-muted); border-right: 1px solid var(--border-color); }.tab.active { color: var(--accent); background: rgba(0, 242, 254, 0.05); border-bottom: 2px solid var(--accent); }#terminal-output { flex: 1; padding: 15px; font-family: 'Consolas', monospace; font-size: 14px; overflow-y: auto; color: #ccc; }/* AI CHAT & CODE BLOCKS */#ai-chat { flex: 1; padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }.msg { padding: 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.5; position: relative; }.msg.user { background: rgba(0, 242, 254, 0.1); align-self: flex-end; border: 1px solid var(--accent); }.msg.ai { background: rgba(255,255,255,0.05); align-self: flex-start; border: 1px solid var(--border-color); }/* AI KOD BLOKU */.ai-code-block {background: #0d0d0d; border-radius: 8px; margin-top: 10px; border: 1px solid #333; overflow: hidden;}.ai-code-header {padding: 5px 10px; background: #1a1a1a; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #333;}.ai-code-header span { font-size: 10px; color: #888; text-transform: uppercase; }.copy-to-editor {background: var(--accent); color: #000; border: none; padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; cursor: pointer;}.ai-code-block pre { padding: 12px; font-family: 'Consolas', monospace; font-size: 12px; color: #dcdcaa; overflow-x: auto; margin: 0; }.ai-input-zone { padding: 15px; border-top: 1px solid var(--border-color); display: flex; gap: 10px; }.ai-input-zone input { flex: 1; background: rgba(0,0,0,0.3); border: 1px solid var(--border-color); color: #fff; padding: 10px; border-radius: 8px; outline: none; }.resizer { height: 6px; cursor: ns-resize; border-top: 1px solid var(--border-color); }.resizer:hover { background: var(--accent); }</style><script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.36.1/min/vs/loader.min.js"></script></head>2 unmodified lines<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-glass top-bar" id="top-bar"><div class="brand"><button class="btn" onclick="togglePanel('left')"><i class="fa-solid fa-folder-tree"></i></button><i class="fa-solid fa-code"></i> TWENTY IDE <span id="file-label" style="color:var(--text-muted); font-size:12px; margin-left:10px;">/ main.py</span></div><div class="controls"><button class="btn" onclick="toggleTheme()"><i class="fa-solid fa-circle-half-stroke"></i></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="main-layout"><div class="panel-glass sidebar-left" id="sidebar-left"><div class="panel-header">FAYL SİSTEMİ <i class="fa-solid fa-file-circle-plus" onclick="createFile()" style="cursor:pointer"></i></div><div class="file-tree" id="file-tree"></div></div><div class="center-panel" id="center-panel"><div id="editor-container"></div><div class="resizer" id="resizer"></div><div class="panel-glass bottom-panel"><div class="tabs"><div class="tab active">TERMINAL</div><div class="tab" onclick="clearTerminal()">TƏMİZLƏ</div></div><div id="terminal-output">// Twenty Engine Hazırdır...<br>PS C:\\Twenty> </div></div></div><div class="panel-glass sidebar-right" id="sidebar-right"><div class="panel-header">EXYPOS AI</div><div id="ai-chat"><div class="msg ai">Salam! Mən Exypos. Sənə 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 class="btn" onclick="askAI()"><i class="fa-solid fa-paper-plane"></i></button></div></div></div><script>// --- ANİMASİYA GİRİŞİ ---window.onload = () => {setTimeout(() => {const splash = document.getElementById('splash');splash.style.opacity = '0';setTimeout(() => {splash.remove();document.body.classList.add('show-ui');}, 1200);}, 3500);};// --- VFS & EDITOR ---let vfs = { "main.py": "print('Salam Twenty IDE!')\\n# Exypos AI-dan kod isteyin!" };let currentFile = "main.py";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: vfs[currentFile],language: 'python',theme: 'vs-dark',automaticLayout: true,fontSize: 15,padding: { top: 20 }});renderFiles();});function renderFiles() {const tree = document.getElementById('file-tree');tree.innerHTML = "";for(let f in vfs) {const div = document.createElement('div');div.className = `file-item ${f === currentFile ? 'active' : ''}`;div.innerHTML = `<span><i class="fa-brands fa-python"></i> ${f}</span><i class="fa-solid fa-trash" onclick="deleteFile('${f}')" style="font-size:10px"></i>`;div.onclick = () => switchFile(f);tree.appendChild(div);}}function switchFile(f) {vfs[currentFile] = editor.getValue();currentFile = f;editor.setValue(vfs[f]);document.getElementById('file-label').innerText = "/ " + f;renderFiles();}function createFile() {const name = prompt("Fayl adı:");if(name && !vfs[name]) { vfs[name] = "# " + name; switchFile(name); }}// --- EXYPOS AI & KOD ENJEKSİYASI ---async function askAI() {const input = document.getElementById('ai-input');const prompt = input.value.trim();if(!prompt) return;const chat = document.getElementById('ai-chat');chat.innerHTML += `<div class="msg user">${prompt}</div>`;input.value = "";chat.scrollTop = chat.scrollHeight;const typingId = "ai-" + Date.now();chat.innerHTML += `<div class="msg ai" id="${typingId}">Düşünürəm...</div>`;try {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();// Kodu və mətni ayırırıqconst processedReply = formatAIReply(data.reply);document.getElementById(typingId).innerHTML = processedReply;} catch (e) {document.getElementById(typingId).innerText = "Xəta baş verdi.";}chat.scrollTop = chat.scrollHeight;}function formatAIReply(text) {// Markdown kod bloklarını tapırıq (```python ... ```)const codeRegex = /```(?:python|py)?\\n([\\s\\S]*?)```/g;let lastIndex = 0;let html = "";let match;while ((match = codeRegex.exec(text)) !== null) {// Koddan əvvəlki mətni əlavə ethtml += text.substring(lastIndex, match.index).replace(/\\n/g, "<br>");const code = match[1].trim();const escapedCode = code.replace(/"/g, '"').replace(/'/g, "\\'");// Kod blokunu düymə ilə birgə əlavə ethtml += `<div class="ai-code-block"><div class="ai-code-header"><span>Python Code</span><button class="copy-to-editor" onclick="injectToEditor(\`${escapedCode}\`)">Editora At</button></div><pre><code>${code}</code></pre></div>`;lastIndex = match.index + match[0].length;}html += text.substring(lastIndex).replace(/\\n/g, "<br>");return html;}function injectToEditor(code) {const selection = editor.getSelection();const range = new monaco.Range(selection.startLineNumber, selection.startColumn, selection.endLineNumber, selection.endColumn);// Kodu seçili yerə və ya kursor olan yerə qüsursuz yapışdırıreditor.executeEdits("beautifier", [{range: range,text: code,forceMoveMarkers: true}]);// AI panelini bağlaya bilərik (istəyə bağlı)// togglePanel('right');}// --- DİGƏR FUNKSİYALAR ---function togglePanel(id) {document.getElementById(`sidebar-${id}`).classList.toggle('collapsed');setTimeout(() => editor.layout(), 300);}function toggleTheme() { document.body.classList.toggle('light-mode'); }async function runCode() {const term = document.getElementById('terminal-output');term.innerHTML += `<br><span style="color:var(--accent)">> python ${currentFile}</span><br>`;const res = await fetch('/run', {method: 'POST',headers: {'Content-Type': 'application/json'},body: JSON.stringify({ code: editor.getValue() })});const data = await res.json();term.innerHTML += data.output.replace(/\\n/g, "<br>");term.scrollTop = term.scrollHeight;}function clearTerminal() { document.getElementById('terminal-output').innerHTML = "PS C:\\\\Twenty> "; }</script></body></html>5 unmodified lines@app.route('/run', methods=['POST'])def run_code():code = request.json.get('code', '')with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:f.write(code)path = f.name5 unmodified lines@app.route('/ask_ai', methods=['POST'])def ask_ai():if not client_groq: return jsonify({"reply": "API Key yoxdur."})prompt = request.json.get('prompt')code = request.json.get('code')try:completion = client_groq.chat.completions.create(model="llama-3.1-8b-instant",messages=[{"role": "system", "content": "Sən Exypos AI-san. Kodları MÜTLƏQ ```python ... ``` blokunda ver. Python boşluqlarına (4 boşluq) ciddi əməl et."},{"role": "user", "content": f"Hazırkı kod:\\n{code}\\n\\nSual: {prompt}"}])return jsonify({"reply": completion.choices[0].message.content})15 unmodified lines1617181920212223242526273 unmodified lines313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384852 unmodified lines8889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372385 unmodified lines2442452462472482492502512522532542555 unmodified lines26126226326426526626726826927027127227327427515 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;3 unmodified lines--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>2 unmodified lines<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>5 unmodified lines@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.name5 unmodified lines@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})
app.py+149-252