Update app.py
Browse files123456789107 unmodified lines181920212223249 unmodified lines3435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231246 unmodified lines1311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681692 unmodified lines1721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402 unmodified lines2432442452462472482492502512522532542552562572582592602612622632642652664 unmodified lines2712722732742752762772782792802 unmodified lines2832842852862872882895 unmodified lines29529629729829930030130230330430530630730830931031131231331431510 unmodified lines3263273283293303313323333345 unmodified lines3403413423433443453463473483493503513523533548 unmodified lines363364365366367368369370371372373374375376import osimport reimport urllib.requestimport base64import ioimport cv2import numpy as npfrom flask import Flask, render_template_string, request, jsonifyfrom huggingface_hub import InferenceClientfrom groq import Groq7 unmodified linesclient_groq = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None# ==========================================# FRONTEND - YENİLƏNMİŞ GEMİNİ STİLİ (MİNİMALİST)# ==========================================HTML_TEMPLATE = r"""<!DOCTYPE html><html lang="az">9 unmodified lines--color-white: #e3e3e3;--text-main: #e3e3e3;--text-muted: #8e8ea0;--accent: #007bff;}* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }body { background-color: var(--bg-dark); color: var(--text-main); height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }/* Üst Panel */.top-bar { position: fixed; top: 0; left: 0; width: 100%; height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 15px; z-index: 1000; background: var(--bg-dark); border-bottom: 1px solid rgba(255,255,255,0.05); }.menu-btn { background: transparent; border: none; color: var(--color-white); cursor: pointer; font-size: 20px; padding: 10px; border-radius: 50%; transition: 0.2s; }.menu-btn:hover { background: rgba(255,255,255,0.1); }.top-right-actions { display: flex; align-items: center; gap: 15px; font-weight: 500; font-size: 18px; letter-spacing: 1px; }/* Yan Menyu */.sidebar { position: fixed; top: 0; left: -300px; width: 280px; height: 100%; background: var(--bg-panel); border-right: 1px solid rgba(255,255,255,0.05); display: flex; flex-direction: column; padding: 70px 15px 15px; z-index: 2000; transition: left 0.3s ease; }.sidebar.open { left: 0; }.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1900; opacity: 0; visibility: hidden; transition: 0.3s; }.sidebar-overlay.open { opacity: 1; visibility: visible; }.side-btn { background: transparent; color: var(--color-white); border: 1px solid rgba(255,255,255,0.1); padding: 12px; border-radius: 8px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; transition: 0.2s; }.side-btn:hover { background: rgba(255,255,255,0.05); }/* Söhbət Tarixçəsi (Yenilənmiş 3 Nöqtə Sistemi) */.history-container { flex: 1; overflow-y: auto; scrollbar-width: none; margin-top: 15px; }.history-item { padding: 10px 12px; border-radius: 8px; margin-bottom: 5px; cursor: pointer; color: var(--color-white); font-size: 14px; background: transparent; transition: 0.2s; display: flex; justify-content: space-between; align-items: center; position: relative; }.history-item:hover, .history-item.active { background: rgba(255,255,255,0.1); }.history-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.history-actions { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 5px; border-radius: 4px; }.history-actions:hover { color: var(--color-white); background: rgba(255,255,255,0.1); }/* Açılan 3 Nöqtə Menyu */.chat-dropdown { position: absolute; right: 10px; top: 35px; background: #2a2b2f; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; flex-direction: column; overflow: hidden; z-index: 3000; box-shadow: 0 4px 12px rgba(0,0,0,0.5); display: none; }.chat-dropdown.show { display: flex; }.chat-dropdown button { background: transparent; border: none; color: var(--color-white); padding: 10px 15px; text-align: left; cursor: pointer; font-size: 13px; display: flex; gap: 8px; align-items: center; }.chat-dropdown button:hover { background: rgba(255,255,255,0.1); }/* Mərkəzi Söhbət Sahəsi */.chat-area { flex: 1; display: flex; flex-direction: column; align-items: center; padding-top: 60px; width: 100%; position: relative; }.glass-container { width: 100%; max-width: 800px; height: calc(100vh - 140px); display: flex; flex-direction: column; overflow: hidden; background: transparent; }.messages-wrapper { flex: 1; overflow-y: auto; padding: 20px; scrollbar-width: none; scroll-behavior: smooth; }/* Mesaj Dizaynları (Gemini Tərzi) */.message { margin-bottom: 25px; display: flex; flex-direction: column; max-width: 85%; animation: fadeIn 0.3s forwards; }.msg-user { align-self: flex-end; }.msg-bot { align-self: flex-start; }.bubble { padding: 12px 18px; line-height: 1.6; font-size: 16px; border-radius: 20px; word-wrap: break-word; }.msg-user .bubble { background: var(--bg-panel); color: var(--color-white); border-bottom-right-radius: 4px; }.msg-bot .bubble { background: transparent; color: var(--color-white); padding: 5px 0; }.msg-bot .bubble img { max-width: 100%; border-radius: 12px; margin-top: 10px; border: 1px solid rgba(255,255,255,0.1); }/* Gözləmə İkonu */.bot-icon { margin-bottom: 8px; color: #a8c7fa; font-size: 20px; }@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }/* Yazı Yeri (Input Box) */.input-zone { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); width: 92%; max-width: 800px; background: var(--bg-panel); border-radius: 30px; display: flex; align-items: center; padding: 8px 15px; gap: 10px; border: 1px solid rgba(255,255,255,0.05); }.plus-btn { background: transparent; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 5px; transition: 0.2s; }.plus-btn:hover { color: var(--color-white); }.expanding-input { flex: 1; background: transparent; border: none; color: var(--color-white); font-size: 16px; padding: 10px 5px; outline: none; }.send-btn { background: var(--color-white); color: var(--bg-dark); border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; }.send-btn:hover { transform: scale(1.05); }/* Rejim Menyusu */.mode-menu { position: absolute; bottom: 70px; left: 10px; background: #2a2b2f; border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 5px; opacity: 0; visibility: hidden; transition: 0.2s; width: 200px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }.mode-menu.active { opacity: 1; visibility: visible; }.mode-btn { background: transparent; color: var(--text-muted); border: none; padding: 10px; border-radius: 8px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 10px; }.mode-btn:hover, .mode-btn.active { background: rgba(255,255,255,0.1); color: var(--color-white); }/* Başlanğıc Ekranı (Welcome Screen) */.welcome-screen { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-bottom: 50px; }.welcome-title { font-size: 2.5rem; font-weight: 600; background: -webkit-linear-gradient(#fff, #888); -webkit-background-clip: text; -webkit-text-fill-color: transparent; margin-bottom: 10px; }.welcome-sub { color: var(--text-muted); font-size: 1.1rem; }@media(max-width:768px){ .glass-container{ height: calc(100vh - 120px); } .input-zone{ bottom: 15px; } .welcome-title{ font-size: 2rem; } }</style></head><body><div class="top-bar"><button class="menu-btn" onclick="toggleSidebar()"><i class="fa-solid fa-bars"></i></button><div class="top-right-actions">Exypos AI</div></div><div class="sidebar-overlay" id="sb-overlay" onclick="toggleSidebar()"></div><aside class="sidebar" id="sidebar"><button class="side-btn" onclick="createNewChat()"><i class="fa-solid fa-plus"></i> Yeni Söhbət</button><div class="history-container" id="history-list"></div></aside>6 unmodified lines<div class="input-zone"><div class="mode-menu" id="mode-menu"><button class="mode-btn active" onclick="setMode('ExyposAi')"><i class="fa-solid fa-robot"></i> ExyposAi</button><button class="mode-btn" onclick="setMode('Normal')"><i class="fa-solid fa-bolt"></i> Normal</button><button class="mode-btn" onclick="setMode('Plus')"><i class="fa-solid fa-sparkles"></i> Plus</button></div><button class="plus-btn" onclick="document.getElementById('mode-menu').classList.toggle('active')"><i class="fa-solid fa-sliders"></i></button><input type="text" id="user-input" class="expanding-input" placeholder="Exypos-a mesaj yaz..." autocomplete="off"><button class="send-btn" onclick="sendMessage()"><i class="fa-solid fa-arrow-up"></i></button></div><script>let chats = {}, actId = null, mode = 'ExyposAi';try { chats = JSON.parse(localStorage.getItem('EX_DB')||'{}'); actId = localStorage.getItem('EX_ACT'); } catch(e){chats={};}function toggleSidebar(){document.getElementById('sidebar').classList.toggle('open');document.getElementById('sb-overlay').classList.toggle('open');}// Menyu Bağlanma İdarəsi (Boşluğa basanda bağlansın)document.addEventListener('click', function(e) {if(!e.target.closest('.history-item') && !e.target.closest('.chat-dropdown')) {document.querySelectorAll('.chat-dropdown').forEach(m => m.classList.remove('show'));}});function saveDB(){ localStorage.setItem('EX_DB',JSON.stringify(chats)); localStorage.setItem('EX_ACT',actId); renderHist(); }function createNewChat(){actId = 'c_'+Date.now();chats[actId] = {t: "Yeni Söhbət", m: []};saveDB();loadChat(actId);if(window.innerWidth<=768 && document.getElementById('sidebar').classList.contains('open')) toggleSidebar();}function loadChat(id){actId = id; saveDB();2 unmodified linesif(chats[id].m.length === 0) {b.innerHTML = `<div class="welcome-screen"><i class="fa-brands fa-connectdevelop bot-icon" style="font-size: 50px;"></i><div class="welcome-title">Salam, Tunar</div><div class="welcome-sub">Bu gün sizə necə kömək edə bilərəm?</div></div>`;}else {chats[id].m.forEach(msg => appMsg(msg.s, msg.c, false, msg.h));}}// --- YENİLƏNMİŞ: Söhbət Tarixçəsi və 3 Nöqtə ---function renderHist(){const l = document.getElementById('history-list'); l.innerHTML = '';Object.keys(chats).sort().reverse().forEach(id => {const d = document.createElement('div');d.className = `history-item ${id===actId ? 'active' : ''}`;d.innerHTML = `<div class="history-title" onclick="openHistoryChat('${id}')">${chats[id].t}</div><button class="history-actions" onclick="toggleChatMenu(event, '${id}')"><i class="fa-solid fa-ellipsis-vertical"></i></button><div class="chat-dropdown" id="menu-${id}"><button onclick="renameChat(event, '${id}')"><i class="fa-solid fa-pen"></i> Adını dəyiş</button><button onclick="deleteChat(event, '${id}')" style="color:#ff6b6b;"><i class="fa-solid fa-trash"></i> Sil</button></div>`;l.appendChild(d);});}function openHistoryChat(id) {loadChat(id);if(window.innerWidth<=768) toggleSidebar();}function toggleChatMenu(e, id) {e.stopPropagation();document.querySelectorAll('.chat-dropdown').forEach(m => m.classList.remove('show')); // Digərlərini bağladocument.getElementById(`menu-${id}`).classList.toggle('show');}function renameChat(e, id) {e.stopPropagation();const newName = prompt("Söhbətin yeni adını daxil edin:", chats[id].t);if(newName && newName.trim() !== "") {chats[id].t = newName.trim();saveDB();}}function deleteChat(e, id) {e.stopPropagation();if(confirm("Bu söhbəti silmək istədiyinizə əminsiniz?")) {delete chats[id];if(actId === id) {const remaining = Object.keys(chats);if(remaining.length > 0) actId = remaining[0];else return createNewChat();}saveDB();loadChat(actId);}}// ------------------------------------------------function setMode(m){mode = m;2 unmodified linesevent.currentTarget.classList.add('active');}function appMsg(snd, txt, save=false, isH=false){const b = document.getElementById('chat-box');// Əgər ekranda "Welcome" yazısı varsa, onu siləkconst welcome = b.querySelector('.welcome-screen');if(welcome) welcome.remove();const d = document.createElement('div'); d.className = `message msg-${snd}`;let innerHTML = '';if(snd === 'bot') innerHTML += `<i class="fa-brands fa-connectdevelop bot-icon"></i>`;const bub = document.createElement('div'); bub.className = 'bubble';isH ? bub.innerHTML = txt : bub.innerText = txt;innerHTML += bub.outerHTML;d.innerHTML = innerHTML;b.appendChild(d);setTimeout(() => b.scrollTop = b.scrollHeight, 10);4 unmodified linesconst inp = document.getElementById('user-input'), txt = inp.value.trim();if(!txt) return;if(chats[actId].m.length === 0){chats[actId].t = txt.substring(0,20) + "...";document.getElementById('chat-box').innerHTML = '';}appMsg('user', txt, true);inp.value = '';2 unmodified linesconst loadId = 'l_'+Date.now();const lDiv = document.createElement('div'); lDiv.className = 'message msg-bot'; lDiv.id = loadId;lDiv.innerHTML = `<i class="fa-brands fa-connectdevelop bot-icon"></i><div class="bubble"><i class="fa-solid fa-circle-notch fa-spin"></i> Düşünür...</div>`;document.getElementById('chat-box').appendChild(lDiv);try {5 unmodified lineselse { appMsg('bot', data.content, true, data.type === 'html'); }} catch(e){document.getElementById(loadId).remove();appMsg('bot', "Server xətası baş verdi.", false);}}// Enter vuranda mesaj göndərsindocument.getElementById("user-input").addEventListener("keypress", function(event) {if (event.key === "Enter") {event.preventDefault();sendMessage();}});window.onload = () => {if(!actId || !chats[actId]) createNewChat(); else loadChat(actId);};</script></body></html>"""10 unmodified linesmode = data.get("mod","ExyposAi")lang = data.get("lng","az")# ----------------------------------------------------# YENİLƏNMİŞ VƏ STABİL ŞƏKİL YARATMA HİSSƏSİ (FLUX.1)# ----------------------------------------------------if u_msg.lower().startswith(("/sekil", "/image")):p = re.sub(r"^/(sekil|image)\s*", "", u_msg, flags=re.IGNORECASE).strip()if client_hf:5 unmodified linesimg_base64 = base64.b64encode(buf.getvalue()).decode()return jsonify({"type": "image_url", "content": f"data:image/png;base64,{img_base64}"})except Exception as e:print(f"Exypos Şəkil Xətası: {e}")return jsonify({"type": "text", "content": "Sistemdə yüklənmə var. Zəhmət olmasa bir az sonra təkrar yoxla."})return jsonify({"type": "text", "content": "HuggingFace API Key (HF_TOKEN) sistemə əlavə edilməyib."})# Mətn söhbəti üçün sistem promptusys_p = f"Sən {mode} modelisən. IAHAI tərəfindən yaradılmısan. Fikir sahibi Tunardır. Cavabı {lang} dilində ver."msgs = [{"role":"system", "content":sys_p}]# Yaddaş limiti (Şəkilləri yoxsayan filtr)for m in hist[-8:]:content = m['c']if "data:image" in content or "<img" in content:8 unmodified linesmodel="llama-3.3-70b-versatile",messages=msgs,temperature=0.6,max_tokens=1024)return jsonify({"type": "text", "content": c.choices[0].message.content})except Exception as e:print(f"Groq xətası: {e}")return jsonify({"type": "text", "content": "Mətn yaradılarkən xəta baş verdi."})return jsonify({"type": "text", "content": "Groq API Key (GROQ_API_KEY) əskikdir."})if __name__ == "__main__":app.run(host="0.0.0.0", port=7860)12345677 unmodified lines151617181920219 unmodified lines3132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461476 unmodified lines1541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132 unmodified lines2162172182192202212222232242252262272282292302312322332342352362372382392402412422432442 unmodified lines2472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013024 unmodified lines3073083093103113123132 unmodified lines3163173183193203213225 unmodified lines32832933033133233333433533633733833934010 unmodified lines3513523533543553563575 unmodified lines3633643653663673683693703713723733743753763773783798 unmodified lines388389390391392393394395396397398399400import osimport reimport ioimport base64from flask import Flask, render_template_string, request, jsonifyfrom huggingface_hub import InferenceClientfrom groq import Groq7 unmodified linesclient_groq = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None# ==========================================# FRONTEND - LOGO, ANİMASİYA VƏ CODEEXY MODU# ==========================================HTML_TEMPLATE = r"""<!DOCTYPE html><html lang="az">9 unmodified lines--color-white: #e3e3e3;--text-main: #e3e3e3;--text-muted: #8e8ea0;/* Loqodakı Mükəmməl Rənglər */--brand-gradient: linear-gradient(135deg, #4A47F6, #A634FF, #FF3B7A);--bot-bg: #1e1f20;--code-bg: #0d1117;--code-header: #161b22;}/* Fərqli Mövzular (Ayarlar üçün) */body[data-theme="purple"] { --bg-dark: #160f24; --bg-panel: #211636; --bot-bg: #2a1d45; }body[data-theme="blue"] { --bg-dark: #0a1128; --bg-panel: #111d40; --bot-bg: #172755; }body[data-theme="dark"] { --bg-dark: #000000; --bg-panel: #111111; --bot-bg: #1a1a1a; }* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }body { background-color: var(--bg-dark); color: var(--text-main); height: 100dvh; overflow: hidden; display: flex; flex-direction: column; transition: 0.3s; }/* Giriş Animasiyası (Splash Screen) */#splash { position: fixed; inset: 0; background: var(--bg-dark); z-index: 9999; display: flex; justify-content: center; align-items: center; transition: opacity 0.8s ease; }.splash-logo { width: 120px; height: 120px; border-radius: 25%; animation: spinIntro 2s cubic-bezier(0.25, 1, 0.5, 1) forwards; box-shadow: 0 0 50px rgba(166, 52, 255, 0.4); }@keyframes spinIntro {0% { transform: scale(0.2) rotate(-180deg); opacity: 0; }50% { transform: scale(1.2) rotate(0deg); opacity: 1; }100% { transform: scale(1) rotate(0deg); opacity: 1; }}/* Üst Panel */.top-bar { position: fixed; top: 0; left: 0; width: 100%; height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 15px; z-index: 1000; background: transparent; }.menu-btn { background: transparent; border: none; color: var(--color-white); cursor: pointer; font-size: 20px; padding: 10px; transition: 0.2s; }.menu-btn:hover { color: #A634FF; }.top-logo-text { font-size: 20px; font-weight: 700; background: var(--brand-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }/* Yan Menyu */.sidebar { position: fixed; top: 0; left: -300px; width: 280px; height: 100%; background: var(--bg-panel); border-right: 1px solid rgba(255,255,255,0.05); display: flex; flex-direction: column; padding: 70px 15px 15px; z-index: 2000; transition: left 0.3s ease; box-shadow: 5px 0 20px rgba(0,0,0,0.5); }.sidebar.open { left: 0; }.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(3px); z-index: 1900; opacity: 0; visibility: hidden; transition: 0.3s; }.sidebar-overlay.open { opacity: 1; visibility: visible; }.side-btn { background: rgba(255,255,255,0.05); color: var(--color-white); border: 1px solid rgba(255,255,255,0.1); padding: 12px; border-radius: 12px; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 10px; margin-bottom: 10px; transition: 0.2s; }.side-btn:hover { background: var(--brand-gradient); border-color: transparent; }/* Söhbət Tarixçəsi */.history-container { flex: 1; overflow-y: auto; margin-top: 15px; }.history-item { padding: 12px; border-radius: 10px; margin-bottom: 5px; cursor: pointer; color: var(--color-white); font-size: 14px; transition: 0.2s; display: flex; justify-content: space-between; align-items: center; }.history-item:hover, .history-item.active { background: rgba(255,255,255,0.1); border-left: 3px solid #A634FF; }.history-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }.history-actions { background: transparent; border: none; color: var(--text-muted); cursor: pointer; padding: 5px; }/* Mərkəzi Söhbət Sahəsi */.chat-area { flex: 1; display: flex; flex-direction: column; align-items: center; padding-top: 60px; width: 100%; }.glass-container { width: 100%; max-width: 850px; height: calc(100vh - 140px); display: flex; flex-direction: column; overflow: hidden; }.messages-wrapper { flex: 1; overflow-y: auto; padding: 20px; scrollbar-width: none; scroll-behavior: smooth; }/* SOL VƏ SAĞ MESAJ DİZAYNI */.message { margin-bottom: 25px; display: flex; flex-direction: column; max-width: 85%; animation: fadeIn 0.3s forwards; }.msg-user { align-self: flex-end; }.msg-bot { align-self: flex-start; }.bubble { padding: 12px 18px; line-height: 1.6; font-size: 16px; border-radius: 20px; word-wrap: break-word; }.msg-user .bubble { background: var(--brand-gradient); color: white; border-bottom-right-radius: 4px; box-shadow: 0 4px 15px rgba(166, 52, 255, 0.3); }.msg-bot .bubble { background: var(--bot-bg); color: var(--color-white); border-bottom-left-radius: 4px; border: 1px solid rgba(255,255,255,0.05); }.msg-bot .bubble img { max-width: 100%; border-radius: 12px; margin-top: 10px; }/* KOD BLOKLARI VƏ KOPYALAMA (Premium Özəllik) */.code-container { background: var(--code-bg); border-radius: 10px; margin: 15px 0; overflow: hidden; border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 5px 15px rgba(0,0,0,0.5); }.code-header { display: flex; justify-content: space-between; padding: 8px 15px; background: var(--code-header); color: #8b949e; font-size: 13px; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.05); }.code-header .lang { text-transform: uppercase; font-weight: bold; color: #A634FF; }.code-header button { background: none; border: none; color: #8b949e; cursor: pointer; transition: 0.2s; display: flex; gap: 5px; align-items: center; font-size: 13px; }.code-header button:hover { color: var(--color-white); }.code-container pre { padding: 15px; overflow-x: auto; color: #e6edf3; font-family: Consolas, monospace; font-size: 14px; margin: 0; line-height: 1.5; }@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }/* Yazı Yeri (Input Box) */.input-zone { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); width: 92%; max-width: 850px; background: var(--bg-panel); border-radius: 25px; display: flex; align-items: center; padding: 10px 15px; gap: 10px; border: 1px solid rgba(255,255,255,0.08); box-shadow: 0 10px 30px rgba(0,0,0,0.5); }.plus-btn { background: transparent; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; transition: 0.2s; }.plus-btn:hover { color: #A634FF; }.expanding-input { flex: 1; background: transparent; border: none; color: var(--color-white); font-size: 16px; padding: 10px 5px; outline: none; }.send-btn { background: var(--brand-gradient); color: white; border: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: 0.2s; box-shadow: 0 4px 10px rgba(166, 52, 255, 0.4); }.send-btn:hover { transform: scale(1.1); }/* Rejim Menyusu */.mode-menu { position: absolute; bottom: 80px; left: 10px; background: var(--bg-panel); border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 5px; opacity: 0; visibility: hidden; transition: 0.2s; box-shadow: 0 10px 30px rgba(0,0,0,0.6); z-index: 100; }.mode-menu.active { opacity: 1; visibility: visible; }.mode-btn { background: transparent; color: var(--text-muted); border: none; padding: 10px 15px; border-radius: 8px; text-align: left; cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 500; }.mode-btn:hover, .mode-btn.active { background: rgba(255,255,255,0.05); color: #A634FF; }/* Ayarlar Modal */#settings-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); z-index: 4000; display: none; align-items: center; justify-content: center; opacity: 0; transition: 0.3s; }.modal-content { background: var(--bg-panel); border: 1px solid rgba(255,255,255,0.1); padding: 30px; border-radius: 20px; width: 90%; max-width: 400px; box-shadow: 0 15px 50px rgba(0,0,0,0.8); }.set-group { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 10px; }.set-select { background: var(--bg-dark); color: var(--color-white); padding: 10px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2); outline: none; }/* Welcome Screen */.welcome-screen { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }.welcome-logo { width: 80px; border-radius: 20px; margin-bottom: 20px; box-shadow: 0 0 20px rgba(166, 52, 255, 0.5); }.welcome-title { font-size: 2rem; font-weight: 700; background: var(--brand-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }</style></head><body><div id="splash"><img src="logo.png" class="splash-logo" alt="Exypos Logo" onerror="this.src='https://cdn-icons-png.flaticon.com/512/6106/6106288.png'"></div><div class="top-bar"><button class="menu-btn" onclick="toggleSidebar()"><i class="fa-solid fa-bars-staggered"></i></button><div class="top-logo-text">Exypos AI</div></div><div class="sidebar-overlay" id="sb-overlay" onclick="toggleSidebar()"></div><aside class="sidebar" id="sidebar"><button class="side-btn" onclick="createNewChat()"><i class="fa-solid fa-plus"></i> Yeni Söhbət</button><button class="side-btn" onclick="openSettings()" style="background:transparent; border-color:transparent;"><i class="fa-solid fa-gear"></i> Ayarlar</button><div class="history-container" id="history-list"></div></aside>6 unmodified lines<div class="input-zone"><div class="mode-menu" id="mode-menu"><button class="mode-btn active" onclick="setMode('ExyposAi')"><i class="fa-solid fa-robot"></i> ExyposAi</button><button class="mode-btn" onclick="setMode('CodeExy')"><i class="fa-solid fa-code"></i> CodeExy</button><button class="mode-btn" onclick="setMode('Plus')"><i class="fa-solid fa-sparkles"></i> Plus</button></div><button class="plus-btn" onclick="document.getElementById('mode-menu').classList.toggle('active')"><i class="fa-solid fa-layer-group"></i></button><input type="text" id="user-input" class="expanding-input" placeholder="Exypos-a mesaj yaz..." autocomplete="off"><button class="send-btn" onclick="sendMessage()"><i class="fa-solid fa-paper-plane"></i></button></div><div id="settings-modal"><div class="modal-content"><h2 style="margin-bottom:20px; color:white;"><i class="fa-solid fa-palette"></i> Mövzu Ayarları</h2><div class="set-group"><span>İnterfeys Rəngi:</span><select class="set-select" onchange="changeTheme(this.value)"><option value="default">Klassik Exypos</option><option value="purple">Bənövşəyi Kosmos</option><option value="blue">Tünd Göy</option><option value="dark">Tam Qara (AMOLED)</option></select></div><button class="side-btn" style="width:100%; justify-content:center; margin-top:10px;" onclick="closeSettings()">Bağla</button></div></div><script>let chats = {}, actId = null, mode = 'ExyposAi';try { chats = JSON.parse(localStorage.getItem('EX_DB')||'{}'); actId = localStorage.getItem('EX_ACT'); } catch(e){chats={};}// Giriş animasiyasını silməkwindow.onload = () => {setTimeout(() => {const splash = document.getElementById('splash');splash.style.opacity = '0';setTimeout(() => splash.style.display = 'none', 800);}, 2000); // 2 saniyə fırlanırif(!actId || !chats[actId]) createNewChat(); else loadChat(actId);// Yadda qalan mövzunu yükləconst savedTheme = localStorage.getItem('EX_THEME');if(savedTheme) document.body.setAttribute('data-theme', savedTheme);};function toggleSidebar(){ document.getElementById('sidebar').classList.toggle('open'); document.getElementById('sb-overlay').classList.toggle('open'); }function openSettings(){ document.getElementById('settings-modal').style.display='flex'; setTimeout(()=>document.getElementById('settings-modal').style.opacity='1',10); if(window.innerWidth<=768)toggleSidebar(); }function closeSettings(){ document.getElementById('settings-modal').style.opacity='0'; setTimeout(()=>document.getElementById('settings-modal').style.display='none',300); }function changeTheme(theme) {document.body.setAttribute('data-theme', theme);localStorage.setItem('EX_THEME', theme);}function saveDB(){ localStorage.setItem('EX_DB',JSON.stringify(chats)); localStorage.setItem('EX_ACT',actId); renderHist(); }function createNewChat(){ actId = 'c_'+Date.now(); chats[actId] = {t: "Yeni Söhbət", m: []}; saveDB(); loadChat(actId); if(window.innerWidth<=768 && document.getElementById('sidebar').classList.contains('open')) toggleSidebar(); }function loadChat(id){actId = id; saveDB();2 unmodified linesif(chats[id].m.length === 0) {b.innerHTML = `<div class="welcome-screen"><img src="logo.png" class="welcome-logo" alt="Logo" onerror="this.src='https://cdn-icons-png.flaticon.com/512/6106/6106288.png'"><div class="welcome-title">Salam, Tunar</div><div style="color: var(--text-muted); margin-top:10px;">Exypos AI səni dinləyir...</div></div>`;}else { chats[id].m.forEach(msg => appMsg(msg.s, msg.c, false, msg.h)); }}function renderHist(){const l = document.getElementById('history-list'); l.innerHTML = '';Object.keys(chats).sort().reverse().forEach(id => {const d = document.createElement('div');d.className = `history-item ${id===actId ? 'active' : ''}`;d.innerHTML = `<div class="history-title" onclick="loadChat('${id}'); if(window.innerWidth<=768)toggleSidebar();">${chats[id].t}</div><button class="history-actions" onclick="deleteChat(event, '${id}')"><i class="fa-solid fa-trash"></i></button>`;l.appendChild(d);});}function deleteChat(e, id) {e.stopPropagation();if(confirm("Silinsin?")) { delete chats[id]; if(actId === id) { actId = Object.keys(chats)[0] || null; if(!actId) createNewChat(); else loadChat(actId); } else saveDB(); }}function setMode(m){mode = m;2 unmodified linesevent.currentTarget.classList.add('active');}// *** KOD BLOKLARINI FORMATLAMA FUNKSİYASI ***function formatMessage(text) {// Şəkillərə dəymirikif(text.includes("<img")) return text;// Markdown kod bloklarını (```) HTML-ə çevirirreturn text.replace(/```(\w*)\n([\s\S]*?)```/g, function(match, lang, code) {const safeCode = code.replace(/</g, '<').replace(/>/g, '>');const language = lang ? lang : 'code';return `<div class="code-container"><div class="code-header"><span class="lang">${language}</span><button onclick="copyCode(this)"><i class="fa-regular fa-copy"></i> Kopyala</button></div><pre><code>${safeCode}</code></pre></div>`;});}// *** KOD KOPYALAMA FUNKSİYASI ***window.copyCode = function(btn) {const pre = btn.parentElement.nextElementSibling;const code = pre.innerText;navigator.clipboard.writeText(code);const originalText = btn.innerHTML;btn.innerHTML = '<i class="fa-solid fa-check" style="color:#00ff88;"></i> Kopyalandı';btn.style.color = '#00ff88';setTimeout(() => {btn.innerHTML = originalText;btn.style.color = '';}, 2000);}function appMsg(snd, txt, save=false, isH=false){const b = document.getElementById('chat-box');const welcome = b.querySelector('.welcome-screen');if(welcome) welcome.remove();const d = document.createElement('div'); d.className = `message msg-${snd}`;const bub = document.createElement('div'); bub.className = 'bubble';// Əgər bot yazırsa və şəkil deyilsə, kodu formatlaif(snd === 'bot' && !isH) {bub.innerHTML = formatMessage(txt);} else {isH ? bub.innerHTML = txt : bub.innerText = txt;}d.appendChild(bub);b.appendChild(d);setTimeout(() => b.scrollTop = b.scrollHeight, 10);4 unmodified linesconst inp = document.getElementById('user-input'), txt = inp.value.trim();if(!txt) return;if(chats[actId].m.length === 0){ chats[actId].t = txt.substring(0,20) + "..."; document.getElementById('chat-box').innerHTML = ''; }appMsg('user', txt, true);inp.value = '';2 unmodified linesconst loadId = 'l_'+Date.now();const lDiv = document.createElement('div'); lDiv.className = 'message msg-bot'; lDiv.id = loadId;lDiv.innerHTML = `<div class="bubble"><i class="fa-solid fa-circle-notch fa-spin"></i> Exypos düşünür...</div>`;document.getElementById('chat-box').appendChild(lDiv);try {5 unmodified lineselse { appMsg('bot', data.content, true, data.type === 'html'); }} catch(e){document.getElementById(loadId).remove();appMsg('bot', "Xəta baş verdi.", false);}}document.getElementById("user-input").addEventListener("keypress", function(event) {if (event.key === "Enter") { event.preventDefault(); sendMessage(); }});</script></body></html>"""10 unmodified linesmode = data.get("mod","ExyposAi")lang = data.get("lng","az")# Şəkil Yaratma (FLUX)if u_msg.lower().startswith(("/sekil", "/image")):p = re.sub(r"^/(sekil|image)\s*", "", u_msg, flags=re.IGNORECASE).strip()if client_hf:5 unmodified linesimg_base64 = base64.b64encode(buf.getvalue()).decode()return jsonify({"type": "image_url", "content": f"data:image/png;base64,{img_base64}"})except Exception as e:return jsonify({"type": "text", "content": "Sistem yüklüdür. Zəhmət olmasa bir az sonra təkrar yoxla."})return jsonify({"type": "text", "content": "HF_TOKEN yoxdur."})# MODELLƏRƏ GÖRƏ XÜSUSİ TƏLİMATLARif mode == "CodeExy":sys_p = "Sən yalnız proqramlaşdırma kodları yazan 'CodeExy' adlı süni intellektsən. Fikir sahibi Tunardır. Cavablarını ancaq Markdown formatında kod blokları (```) içində ver. İzahı qısa saxla və ya kodun içində şərh (comment) kimi yaz."else:sys_p = f"Sən {mode} modelisən. IAHAI tərəfindən yaradılmısan. Fikir sahibi Tunardır. Cavabı {lang} dilində ver."msgs = [{"role":"system", "content":sys_p}]for m in hist[-8:]:content = m['c']if "data:image" in content or "<img" in content:8 unmodified linesmodel="llama-3.3-70b-versatile",messages=msgs,temperature=0.6,max_tokens=2048)return jsonify({"type": "text", "content": c.choices[0].message.content})except Exception as e:return jsonify({"type": "text", "content": "Mətn yaradılarkən xəta baş verdi."})return jsonify({"type": "text", "content": "GROQ_API_KEY əskikdir."})if __name__ == "__main__":app.run(host="0.0.0.0", port=7860)
app.py+178-154