Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152import osimport subprocessfrom flask import Flask, render_template_string, request, jsonify
app = Flask(__name__)
# --- TWENTY IDE: XÜSUSİ DİZAYN (LIQUID FOCUS) ---HTML_TEMPLATE = """<!DOCTYPE html><html lang="az"><head> <meta charset="UTF-8"> <title>TWENTY IDE | IAHAI</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.23.0/ace.js"></script> <style> :root { --bg: #030305; --panel-bg: rgba(15, 15, 20, 0.6); --accent: #00f2fe; --border: rgba(255, 255, 255, 0.1); } body, html { margin: 0; padding: 0; height: 100%; background: var(--bg); color: #fff; font-family: 'Fira Code', monospace; overflow: hidden; } /* Arxa plan obyektləri */ .orb { position: absolute; border-radius: 50%; filter: blur(100px); z-index: -1; opacity: 0.3; } .orb-1 { width: 400px; height: 400px; background: #6b21a8; top: -100px; right: -100px; } .orb-2 { width: 300px; height: 300px; background: #00f2fe; bottom: -50px; left: -50px; }
.wrapper { display: grid; grid-template-columns: 60px 250px 1fr 300px; height: 100vh; }
/* Sol İkon Paneli */ .icon-bar { background: rgba(0,0,0,0.5); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 20px 0; gap: 25px; } .icon-bar i { font-size: 20px; color: #555; cursor: pointer; transition: 0.3s; } .icon-bar i:hover, .icon-bar i.active { color: var(--accent); text-shadow: 0 0 10px var(--accent); }
/* Fayl Paneli */ .file-explorer { background: var(--panel-bg); backdrop-filter: blur(20px); border-right: 1px solid var(--border); padding: 20px; } .file-explorer h4 { margin-top: 0; font-size: 12px; color: #888; letter-spacing: 2px; }
/* Editor Sahəsi */ .editor-container { display: flex; flex-direction: column; position: relative; } #editor { flex: 1; background: transparent !important; font-size: 16px; }
/* Terminal */ .terminal { height: 200px; background: rgba(0,0,0,0.8); border-top: 1px solid var(--border); padding: 15px; overflow-y: auto; font-family: 'Consolas', monospace; font-size: 14px; } .term-header { display: flex; justify-content: space-between; margin-bottom: 10px; color: #888; font-size: 12px; }
/* AI Panel */ .ai-panel { background: var(--panel-bg); backdrop-filter: blur(20px); border-left: 1px solid var(--border); padding: 20px; display: flex; flex-direction: column; } /* Düymələr */ .run-btn { background: var(--accent); color: #000; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; font-weight: bold; transition: 0.3s; } .run-btn:hover { box-shadow: 0 0 15px var(--accent); transform: scale(1.05); } </style></head><body> <div class="orb orb-1"></div><div class="orb orb-2"></div> <div class="wrapper"> <div class="icon-bar"> <i class="fa-solid fa-file-code active"></i> <i class="fa-solid fa-magnifying-glass"></i> <i class="fa-solid fa-gear"></i> </div>
<div class="file-explorer"> <h4>EXPLORER</h4> <div style="font-size: 14px; color: var(--accent);"><i class="fa-solid fa-python"></i> main.py</div> </div>
<div class="editor-container"> <div style="padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border);"> <span style="font-size: 12px; color: #888;">main.py</span> <button class="run-btn" onclick="runCode()"><i class="fa-solid fa-play"></i> RUN</button> </div> <div id="editor"># TWENTY IDE-yə xoş gəlmisən, Tunar!def salam_iahai(): print("TWENTY IDE ishalidir!")
salam_iahai()</div> <div class="terminal" id="terminal"> <div class="term-header"><span>TERMINAL</span><span id="status">Ready</span></div> <div id="output" style="color: #0f0;"></div> </div> </div>
<div class="ai-panel"> <h4 style="color: var(--accent); font-size: 12px;">EXYPOS AI</h4> <div id="ai-chat" style="flex: 1; font-size: 13px; color: #ccc;"> Kodunuzu yazın, xəta olsa mən bura yazacam. </div> </div> </div>
<script> var editor = ace.edit("editor"); editor.setTheme("ace/theme/one_dark"); editor.session.setMode("ace/mode/python"); editor.setOptions({ enableBasicAutocompletion: true, enableLiveAutocompletion: true, showPrintMargin: false, transparentBackground: true });
async function runCode() { const code = editor.getValue(); const outDiv = document.getElementById('output'); const status = document.getElementById('status'); status.innerText = "Running..."; outDiv.innerText = "Processing...";
try { const res = await fetch('/run', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ code: code }) }); const data = await res.json(); outDiv.innerText = data.output; status.innerText = "Done"; } catch (e) { outDiv.innerText = "Error: System fail"; status.innerText = "Failed"; } } </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') try: with open('temp_script.py', 'w') as f: f.write(code) result = subprocess.run(['python3', 'temp_script.py'], capture_output=True, text=True, timeout=5) output = result.stdout if result.stdout else result.stderr return jsonify({'output': output}) except Exception as e: return jsonify({'output': str(e)})
if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)app.pyAdded+152