Download app.py from ExyposAI/ExyposAi: direct link, hf CLI and curl.
- Browser
- Download file 24.2 kB
-
https://huggingface.co/spaces/ExyposAI/ExyposAi/resolve/main/app.py
- Command line
-
hf download hf://spaces/ExyposAI/ExyposAi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ExyposAI/ExyposAi/resolve/main/app.py
24.2 kB
| import os | |
| import re | |
| import base64 | |
| import io | |
| from flask import Flask, render_template_string, request, jsonify, send_from_directory | |
| from huggingface_hub import InferenceClient | |
| from groq import Groq | |
| app = Flask(__name__) | |
| # API Key-ləri Secrets-dən götürürük | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| client_hf = InferenceClient(api_key=HF_TOKEN) if HF_TOKEN else None | |
| client_groq = Groq(api_key=GROQ_API_KEY) if GROQ_API_KEY else None | |
| # ========================================== | |
| # FRONTEND - DİZAYN QORUNDU, FUNKSİONALLIQ ARTIRILDI | |
| # ========================================== | |
| HTML_TEMPLATE = r"""<!DOCTYPE html> | |
| <html lang="az"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
| <title>Exypos AI | Global Pro</title> | |
| <link rel="manifest" href="/manifest.json"> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&display=swap'); | |
| :root { | |
| --bg-dark: #050505; | |
| --color-white: #fff; | |
| --text-main: #f4f4f5; | |
| --text-muted: #888; | |
| --brand-gradient: linear-gradient(135deg, #4A47F6, #A634FF, #FF3B7A); | |
| --bot-msg-grad: linear-gradient(135deg, #16161a, #1f1f24); | |
| --glass-bg: rgba(255, 255, 255, 0.03); | |
| } | |
| * { box-sizing:border-box; margin:0; padding:0; font-family:'Segoe UI', system-ui, sans-serif; -webkit-tap-highlight-color: transparent; } | |
| body { background-color:var(--bg-dark); color:var(--text-main); height:100dvh; overflow:hidden; display:flex; flex-direction:column; } | |
| .ambient-bg { position:fixed; inset:0; z-index:-2; overflow:hidden; background:var(--bg-dark); } | |
| .orb { position:absolute; border-radius:50%; opacity:0.4; will-change: transform; transform: translateZ(0); } | |
| .orb-1 { width:600px; height:600px; background: radial-gradient(circle, rgba(166,52,255,0.3) 0%, transparent 70%); animation: f1 20s infinite alternate linear; } | |
| .orb-2 { width:500px; height:500px; bottom:0; right:0; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%); animation: f2 25s infinite alternate-reverse linear; } | |
| @keyframes f1 { 100% { transform:translate3d(25vw,35vh,0) scale(1.1); } } | |
| @keyframes f2 { 100% { transform:translate3d(-35vw,-25vh,0) scale(1.2); } } | |
| #splash { position:fixed; inset:0; background:#050505; z-index:9999; display:flex; justify-content:center; align-items:center; transition:0.8s; } | |
| .splash-text { font-family: 'Montserrat', sans-serif; font-size:40px; font-weight:300; letter-spacing:20px; color:#fff; opacity:0; transform:scale(0.9); animation:fadeSplash 2s forwards; } | |
| @keyframes fadeSplash { | |
| 0% { opacity:0; transform:scale(0.95); filter:blur(10px);} | |
| 40% { opacity:1; transform:scale(1); filter:blur(0);} | |
| 80% { opacity:1; transform:scale(1); filter:blur(0);} | |
| 100% { opacity:0; transform:scale(1.05); filter:blur(5px);} | |
| } | |
| .top-bar { position:fixed; top:0; left:0; width:100%; height:85px; display:flex; justify-content:space-between; align-items:center; padding:0 20px; z-index:1000; pointer-events:none; } | |
| .menu-btn { pointer-events:auto; background:var(--glass-bg); backdrop-filter:blur(10px); color:var(--color-white); cursor:pointer; font-size:20px; width:42px; height:42px; border-radius:12px; transition:0.2s; border:1px solid rgba(255,255,255,0.1); display:flex; justify-content:center; align-items:center;} | |
| .menu-btn:hover { color:#A634FF; transform:scale(1.05); } | |
| /* Giriş və Download Düymələri */ | |
| .top-right-actions { pointer-events:auto; display:flex; flex-direction:column; align-items:center; gap:4px; } | |
| .login-btn { display:flex; align-items:center; gap:8px; padding:8px 16px; border-radius:30px; font-weight:600; background:var(--glass-bg); backdrop-filter:blur(10px); border:1px solid rgba(255,255,255,0.1); color:var(--color-white); cursor:pointer; } | |
| .login-btn img { height:22px; width:22px; object-fit:cover; border-radius:50%; filter:grayscale(100%) brightness(150%); } | |
| /* Download Yazısı (Nöqtəli) */ | |
| #install-btn { display:none; font-size:10px; color:var(--text-muted); cursor:pointer; letter-spacing:1px; text-transform:uppercase; font-weight:700; align-items:center; gap:4px; margin-top: 2px; } | |
| #install-btn:hover { color:#fff; } | |
| #install-btn::before { content: "●"; color: #A634FF; font-size: 8px; } | |
| .sidebar { position:fixed; top:0; left:-320px; width:280px; height:100%; background: linear-gradient(135deg, rgba(20,20,22,0.9), rgba(0,0,0,0.95)); backdrop-filter: blur(15px); display:flex; flex-direction:column; padding:80px 15px 15px; z-index:2000; transition:left 0.3s ease; box-shadow: 5px 0 20px rgba(0,0,0,0.8); border-right:1px solid rgba(255,255,255,0.05);} | |
| .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; } | |
| .lang-select { background:var(--glass-bg); color:#fff; border:1px solid rgba(255,255,255,0.1); padding:12px; border-radius:8px; margin-bottom:15px; width:100%; outline:none; font-size:15px; cursor:pointer; } | |
| .lang-select option { background: #1a1a1a; color: #fff; } | |
| .side-btn { background:var(--glass-bg); 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:15px; transition:0.2s; } | |
| .side-btn:hover { background: rgba(166,52,255,0.1); } | |
| .history-container { flex:1; overflow-y:auto; scrollbar-width:none; } | |
| .history-item { display: flex; justify-content: space-between; align-items: center; gap:10px; padding:12px; border-radius:10px; margin-bottom:8px; cursor:pointer; background:var(--glass-bg); border:1px solid transparent; transition:0.2s; } | |
| .history-item.active { background:rgba(255,255,255,0.05); border-left:3px solid #A634FF; } | |
| .history-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size:14px; color:var(--text-muted); } | |
| .history-actions { background:transparent; border:none; color:#ff4d4d; cursor:pointer; padding:5px; transition:0.2s; opacity:0.6; } | |
| .history-actions:hover { opacity:1; } | |
| .chat-area { flex:1; display:flex; flex-direction:column; padding-top:70px; align-items:center; width:100%; position:relative;} | |
| .glass-container { width:94%; max-width:900px; height:calc(100vh - 160px); background: linear-gradient(135deg, rgba(255,255,255,0.02), rgba(0,0,0,0.5)); backdrop-filter: blur(15px); border-radius:20px; display:flex; flex-direction:column; overflow:hidden; border:1px solid rgba(255,255,255,0.05); } | |
| .messages-wrapper { flex:1; overflow-y:auto; padding:20px; scrollbar-width:none; scroll-behavior:smooth; } | |
| .message { margin-bottom:20px; display:flex; flex-direction:column; max-width:90%; animation:slideUp 0.3s forwards; opacity:0; transform:translateY(10px); } | |
| .msg-user { align-self: flex-end; margin-left:auto; } | |
| .msg-bot { align-self: flex-start; margin-right:auto; } | |
| .bubble { padding:14px 18px; line-height:1.6; font-size:15px; border-radius:18px; word-wrap: break-word;} | |
| .msg-user .bubble { background:rgba(255,255,255,0.08); color:var(--color-white); border:1px solid rgba(255,255,255,0.1); border-bottom-right-radius:4px; } | |
| .msg-bot .bubble { background:var(--bot-msg-grad); color:var(--color-white); border-bottom-left-radius:4px; border:1px solid rgba(255,255,255,0.05); box-shadow:0 4px 10px rgba(0,0,0,0.3); } | |
| @keyframes slideUp { to { opacity:1; transform:translateY(0); } } | |
| .input-zone { position:fixed; bottom:20px; left:50%; transform:translateX(-50%); width:94%; max-width:900px; background:rgba(15,15,18,0.95); border-radius:30px; display:flex; align-items:center; padding:8px 12px; gap:8px; border:1px solid rgba(255,255,255,0.1); box-shadow:0 10px 30px rgba(0,0,0,0.6); z-index:100; } | |
| .expanding-input { flex:1; background:transparent; border:none; color:var(--color-white); font-size:16px; padding:10px 5px; outline:none; min-width: 0; } | |
| .icon-btn { background:transparent; border:none; color:var(--text-muted); font-size:20px; cursor:pointer; padding:5px; flex-shrink: 0; transition:0.2s; } | |
| .send-btn { background:var(--color-white); color:#000; border:none; width:42px; height:42px; min-width:42px; min-height:42px; flex-shrink: 0; border-radius:50%; cursor:pointer; display:flex; justify-content:center; align-items:center; transition:0.2s; } | |
| .send-btn:hover { transform:scale(1.05); background:#A634FF; color:#fff; } | |
| .fancy-loader { --color-two: #A634FF; position: relative; border-radius: 50%; width: 30px; height: 30px; border: 3px solid rgba(166,52,255,0.2); border-top-color: var(--color-two); animation: spin 1s infinite linear; } | |
| @keyframes spin { 100% { transform: rotate(360deg); } } | |
| /* RADIO DALĞALARI */ | |
| #exyecho-overlay { position:fixed; inset:0; background:rgba(5,5,5,0.98); z-index:5000; display:none; flex-direction:column; align-items:center; justify-content:center; opacity:0; transition:0.4s; } | |
| .echo-title { position:absolute; top:40px; font-size:2rem; font-family: 'Montserrat', sans-serif; font-weight:700; letter-spacing:5px; background: var(--brand-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } | |
| .close-echo { position:absolute; top:40px; right:30px; background:transparent; border:none; color:#fff; font-size:30px; cursor:pointer; } | |
| .radio-waves { display: flex; align-items: center; justify-content: center; gap: 8px; height: 120px; cursor:pointer; padding: 20px;} | |
| .wave-bar { width: 10px; height: 15px; background: #A634FF; border-radius: 10px; transition: 0.2s ease; box-shadow: 0 0 15px rgba(166,52,255,0.5); } | |
| @keyframes waveAnim { 0% { height: 15px; } 50% { height: 90px; } 100% { height: 15px; } } | |
| .status-idle .wave-bar { animation: waveAnim 2s infinite ease-in-out; opacity:0.5; } | |
| .status-listening .wave-bar { animation: waveAnim 0.6s infinite ease-in-out; background: #FF3B7A; box-shadow: 0 0 20px rgba(255,59,122,0.8); } | |
| .status-speaking .wave-bar { animation: waveAnim 0.4s infinite ease-in-out; background: #fff; box-shadow: 0 0 20px #fff; } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="splash"><div class="splash-text">EXYPOS</div></div> | |
| <div class="ambient-bg"><div class="orb orb-1"></div><div class="orb orb-2"></div></div> | |
| <div class="top-bar"> | |
| <button class="menu-btn" onclick="toggleSidebar()"><i class="fa-solid fa-bars"></i></button> | |
| <div class="top-right-actions"> | |
| <button class="login-btn"><img src="https://cdn-icons-png.flaticon.com/512/300/300221.png" alt="User"> <span id="ui-login">Giriş</span></button> | |
| <div id="install-btn">Download</div> | |
| </div> | |
| </div> | |
| <div class="sidebar-overlay" id="sb-overlay" onclick="toggleSidebar()"></div> | |
| <aside class="sidebar" id="sidebar"> | |
| <select class="lang-select" id="lang-select" onchange="changeLanguage(this.value)"> | |
| <option value="az">🇦🇿 Azərbaycan</option> | |
| <option value="en">🇬🇧 English</option> | |
| <option value="ru">🇷🇺 Русский</option> | |
| <option value="zh">🇨🇳 中文</option> | |
| </select> | |
| <button class="side-btn" onclick="createNewChat()" style="background:rgba(255,255,255,0.1); border-color:#fff;"><i class="fa-solid fa-plus"></i> <span id="ui-newchat">Yeni Söhbət</span></button> | |
| <div class="history-container" id="history-list"></div> | |
| </aside> | |
| <main class="chat-area"> | |
| <div class="glass-container"> | |
| <div class="messages-wrapper" id="chat-box"></div> | |
| </div> | |
| </main> | |
| <div class="input-zone"> | |
| <button class="icon-btn" onclick="createNewChat()"><i class="fa-solid fa-plus"></i></button> | |
| <input type="text" id="user-input" class="expanding-input" placeholder="Exypos-a mesaj yaz..." autocomplete="off"> | |
| <button class="icon-btn mic-btn" onclick="startExyEcho()"><i class="fa-solid fa-microphone"></i></button> | |
| <button class="send-btn" onclick="sendMessage()"><i class="fa-solid fa-paper-plane"></i></button> | |
| </div> | |
| <div id="exyecho-overlay"> | |
| <div class="echo-title">ExyEcho</div> | |
| <button class="close-echo" onclick="stopExyEcho()"><i class="fa-solid fa-xmark"></i></button> | |
| <div class="radio-waves status-idle" id="radio-waves" onclick="startRecognition()"> | |
| <div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div> | |
| <div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div> | |
| </div> | |
| <div style="color:var(--text-muted); font-size:16px; margin-top:40px; text-align:center;" id="echo-status">Toxun və danış...</div> | |
| </div> | |
| <script> | |
| const i18n = { | |
| az: { newChat: "Yeni Söhbət", input: "Exypos-a mesaj yaz...", login: "Giriş", voiceIdle: "Toxun və danış...", voiceListen: "Səni dinləyirəm...", voiceThink: "Düşünürəm...", voiceSpeak: "Exypos danışır...", errVoice: "Səsi anlaya bilmədim. Toxun." }, | |
| en: { newChat: "New Chat", input: "Message Exypos...", login: "Login", voiceIdle: "Touch and speak...", voiceListen: "Listening...", voiceThink: "Thinking...", voiceSpeak: "Exypos is speaking...", errVoice: "Couldn't hear. Touch again." }, | |
| ru: { newChat: "Новый чат", input: "Напишите Exypos...", login: "Войти", voiceIdle: "Нажмите и говорите...", voiceListen: "Слушаю...", voiceThink: "Думаю...", voiceSpeak: "Exypos говорит...", errVoice: "Не расслышал. Нажмите еще раз." }, | |
| zh: { newChat: "新聊天", input: "给 Exypos 发消息...", login: "登录", voiceIdle: "触摸并说话...", voiceListen: "听着...", voiceThink: "思考中...", voiceSpeak: "Exypos 正在说话...", errVoice: "没听清。请再按一次。" } | |
| }; | |
| let currentLang = 'az'; | |
| let synth = window.speechSynthesis; | |
| let chats = {}, actId = null; | |
| function unlockAudio() { | |
| const silent = new SpeechSynthesisUtterance(" "); | |
| synth.speak(silent); | |
| } | |
| function changeLanguage(lang) { | |
| currentLang = lang; | |
| document.getElementById('ui-newchat').innerText = i18n[lang].newChat; | |
| document.getElementById('ui-login').innerText = i18n[lang].login; | |
| document.getElementById('user-input').placeholder = i18n[lang].input; | |
| document.getElementById('echo-status').innerText = i18n[lang].voiceIdle; | |
| if(chats[actId] && chats[actId].m.length === 0) loadChat(actId); | |
| } | |
| try { chats = JSON.parse(localStorage.getItem('EX_DB')||'{}'); actId = localStorage.getItem('EX_ACT'); } catch(e){chats={};} | |
| window.onload = () => { | |
| setTimeout(() => { const s = document.getElementById('splash'); s.style.opacity = '0'; setTimeout(() => s.style.display = 'none', 500); }, 1800); | |
| if(!actId || !chats[actId]) createNewChat(); else loadChat(actId); | |
| // Register Service Worker | |
| if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js'); } | |
| }; | |
| // INSTALL (DOWNLOAD) LOGIC | |
| let deferredPrompt; | |
| const installBtn = document.getElementById('install-btn'); | |
| window.addEventListener('beforeinstallprompt', (e) => { | |
| e.preventDefault(); | |
| deferredPrompt = e; | |
| installBtn.style.display = 'flex'; | |
| }); | |
| installBtn.addEventListener('click', async () => { | |
| if (deferredPrompt) { | |
| deferredPrompt.prompt(); | |
| const { outcome } = await deferredPrompt.userChoice; | |
| if (outcome === 'accepted') { installBtn.style.display = 'none'; } | |
| deferredPrompt = null; | |
| } | |
| }); | |
| function toggleSidebar(){ document.getElementById('sidebar').classList.toggle('open'); document.getElementById('sb-overlay').classList.toggle('open'); } | |
| function saveDB(){ localStorage.setItem('EX_DB',JSON.stringify(chats)); localStorage.setItem('EX_ACT',actId); renderHist(); } | |
| function createNewChat(){ | |
| actId = 'c_'+Date.now(); | |
| chats[actId] = {t: i18n[currentLang].newChat, m: []}; | |
| saveDB(); loadChat(actId); | |
| if(window.innerWidth<=768) toggleSidebar(); | |
| } | |
| function loadChat(id){ | |
| actId = id; saveDB(); | |
| const b = document.getElementById('chat-box'); b.innerHTML = ''; | |
| if(chats[id].m.length === 0) { | |
| b.innerHTML = `<div style="height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;opacity:0.6;"> | |
| <div style="font-family:'Montserrat', sans-serif; font-size:2.5rem; font-weight:700; color:#fff; letter-spacing:10px;">EXYPOS</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("Silək?")) { delete chats[id]; if(actId === id) createNewChat(); else saveDB(); } } | |
| function appMsg(snd, txt, save=false, isH=false){ | |
| const b = document.getElementById('chat-box'), d = document.createElement('div'); d.className = `message msg-${snd}`; | |
| const bub = document.createElement('div'); bub.className = 'bubble'; isH ? bub.innerHTML = txt : bub.innerText = txt; | |
| d.appendChild(bub); b.appendChild(d); b.scrollTop = b.scrollHeight; | |
| if(save){ chats[actId].m.push({s:snd, c:txt, h:isH}); saveDB(); } | |
| } | |
| async function sendMessage(textOverride = null, isVoice = false){ | |
| const inp = document.getElementById('user-input'); | |
| const txt = textOverride || inp.value.trim(); | |
| if(!txt) return; | |
| if(!isVoice) { | |
| if(chats[actId].m.length === 0){ chats[actId].t = txt.substring(0,20) + "..."; document.getElementById('chat-box').innerHTML = ''; } | |
| appMsg('user', txt, true); inp.value = ''; | |
| } | |
| const loadId = 'l_'+Date.now(); | |
| if(!isVoice) { | |
| const lDiv = document.createElement('div'); lDiv.className='message msg-bot'; lDiv.id=loadId; | |
| lDiv.innerHTML=`<div class="bubble" style="background:transparent; border:none; box-shadow:none;"><div class="fancy-loader"></div></div>`; | |
| document.getElementById('chat-box').appendChild(lDiv); | |
| document.getElementById('chat-box').scrollTop = document.getElementById('chat-box').scrollHeight; | |
| } | |
| try { | |
| const res = await fetch('/chat',{method:'POST',headers:{'Content-Type':'application/json'}, body:JSON.stringify({msg:txt, hst:chats[actId].m, lng:currentLang, is_voice: isVoice})}); | |
| const data = await res.json(); | |
| if(!isVoice) document.getElementById(loadId).remove(); | |
| if(isVoice) playNativeVoice(data.content); else appMsg('bot', data.content, true); | |
| } catch(e){ if(!isVoice) document.getElementById(loadId).remove(); } | |
| } | |
| document.getElementById("user-input").addEventListener("keypress", (e) => { if (e.key === "Enter") sendMessage(); }); | |
| // VOICE LOGIC | |
| let recognition; | |
| let isEchoActive = false; | |
| let langMap = { az: 'az-AZ', en: 'en-US', ru: 'ru-RU', zh: 'zh-CN' }; | |
| function startExyEcho() { | |
| unlockAudio(); | |
| isEchoActive = true; | |
| document.getElementById('exyecho-overlay').style.display = 'flex'; | |
| setTimeout(() => document.getElementById('exyecho-overlay').style.opacity = '1', 10); | |
| initRecognition(); | |
| } | |
| function stopExyEcho() { | |
| isEchoActive = false; | |
| if(recognition) recognition.stop(); | |
| synth.cancel(); | |
| document.getElementById('exyecho-overlay').style.opacity = '0'; | |
| setTimeout(() => document.getElementById('exyecho-overlay').style.display = 'none', 400); | |
| document.getElementById('radio-waves').className = 'radio-waves status-idle'; | |
| } | |
| function initRecognition() { | |
| const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; | |
| recognition = new SpeechRecognition(); | |
| recognition.lang = langMap[currentLang]; | |
| recognition.onstart = () => updateEchoStatus(i18n[currentLang].voiceListen, "status-listening"); | |
| recognition.onresult = (e) => { | |
| const t = e.results[0][0].transcript; | |
| updateEchoStatus(i18n[currentLang].voiceThink, "status-idle"); | |
| sendMessage(t, true); | |
| }; | |
| recognition.onerror = () => updateEchoStatus(i18n[currentLang].errVoice, "status-idle"); | |
| try { recognition.start(); } catch(e) {} | |
| } | |
| function startRecognition() { synth.cancel(); try { recognition.start(); } catch(e) {} } | |
| function updateEchoStatus(status, animClass) { | |
| document.getElementById('echo-status').innerText = status; | |
| document.getElementById('radio-waves').className = `radio-waves ${animClass}`; | |
| } | |
| function playNativeVoice(text) { | |
| if (!isEchoActive) return; | |
| updateEchoStatus(i18n[currentLang].voiceSpeak, "status-speaking"); | |
| let utterance = new SpeechSynthesisUtterance(text.replace(/[*_#`~]/g, '')); | |
| utterance.lang = langMap[currentLang]; | |
| utterance.onend = () => { if (isEchoActive) updateEchoStatus(i18n[currentLang].voiceIdle, "status-idle"); }; | |
| synth.speak(utterance); | |
| } | |
| </script> | |
| </body> | |
| </html>""" | |
| def index(): | |
| return render_template_string(HTML_TEMPLATE) | |
| def serve_manifest(): | |
| return send_from_directory('.', 'manifest.json') | |
| def serve_sw(): | |
| return send_from_directory('.', 'sw.js') | |
| def serve_logo(): | |
| return send_from_directory('.', 'logo.png') | |
| def chat(): | |
| data = request.json | |
| u_msg, hist, lang_code, is_voice = data.get("msg",""), data.get("hst",[]), data.get("lng","az"), data.get("is_voice", False) | |
| lang_names = {"az": "Azərbaycan", "en": "English", "ru": "Русский", "zh": "中文"} | |
| active_lang = lang_names.get(lang_code, "Azərbaycan") | |
| sys_p = f"Sən Tunarın dostusan. {active_lang} dilində qısa cavab ver. Simvollar yazma." if is_voice else f"Sən Exypos AI modelisən. {active_lang} dilində cavab ver." | |
| msgs = [{"role":"system", "content":sys_p}] | |
| for m in hist[-8:]: msgs.append({"role": "user" if m['s']=='user' else "assistant", "content": m['c']}) | |
| msgs.append({"role": "user", "content": u_msg}) | |
| if client_groq: | |
| try: | |
| c = client_groq.chat.completions.create(model="llama-3.3-70b-versatile", messages=msgs, temperature=0.7, max_tokens=1024) | |
| return jsonify({"type": "text", "content": c.choices[0].message.content}) | |
| except: return jsonify({"type": "text", "content": "Xəta."}) | |
| return jsonify({"type": "text", "content": "Groq API Key yoxdur."}) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) |