feat: Node.js — чистый http, /api/profiles, 0 зависимостей
This commit is contained in:
-13
@@ -1,13 +0,0 @@
|
|||||||
FROM python:3.9-slim
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY requirements.txt .
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
COPY site /app/site
|
|
||||||
|
|
||||||
EXPOSE 5000
|
|
||||||
|
|
||||||
CMD ["python", "site/app.py"]
|
|
||||||
Generated
+12
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "say",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"name": "say",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "say",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "server.js",
|
||||||
|
"scripts": { "start": "node server.js" },
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Flask==2.0.1
|
|
||||||
Werkzeug==2.3.7
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
const http = require('http');
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
|
http.createServer((req, res) => {
|
||||||
|
if (req.url === '/healthz') {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end('{"status":"ok"}');
|
||||||
|
} else if (req.url === '/api/profiles') {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
|
res.end(JSON.stringify([
|
||||||
|
{"id": "ddm", "name": "DDM-120", "desc": "Быстрая модель"},
|
||||||
|
{"id": "qwen", "name": "Qwen", "desc": "Мощная модель"},
|
||||||
|
{"id": "deepseek", "name": "DeepSeek", "desc": "Глубокая аналитика"},
|
||||||
|
]));
|
||||||
|
} else {
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
|
res.end('Say OK');
|
||||||
|
}
|
||||||
|
}).listen(PORT, () => console.log(':' + PORT));
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
from flask import Flask, render_template, jsonify
|
|
||||||
|
|
||||||
|
|
||||||
class SayApp:
|
|
||||||
def __init__(self):
|
|
||||||
self.app = Flask(__name__, template_folder="templates", static_folder="static")
|
|
||||||
self.add_routes()
|
|
||||||
|
|
||||||
def add_routes(self):
|
|
||||||
self.app.add_url_rule("/", "index", self.index)
|
|
||||||
self.app.add_url_rule("/healthz", "healthz", self.health)
|
|
||||||
self.app.add_url_rule("/api/profiles", "profiles", self.profiles)
|
|
||||||
|
|
||||||
def index(self):
|
|
||||||
return render_template("index.html")
|
|
||||||
|
|
||||||
def healthz(self):
|
|
||||||
return jsonify({"status": "ok"})
|
|
||||||
|
|
||||||
def profiles(self):
|
|
||||||
return jsonify([
|
|
||||||
{"id": "ddm", "name": "DDM-120", "desc": "Быстрая модель"},
|
|
||||||
{"id": "qwen", "name": "Qwen", "desc": "Мощная модель"},
|
|
||||||
{"id": "deepseek", "name": "DeepSeek", "desc": "Глубокая аналитика"},
|
|
||||||
])
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
self.app.run(host="0.0.0.0", port=5000, debug=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
SayApp().run()
|
|
||||||
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1017 B |
@@ -1,2 +0,0 @@
|
|||||||
Forbidden
|
|
||||||
Transaction ID: bdd7fbca-219a-4dbf-95ca-a27cc8bdecd9
|
|
||||||
@@ -1,241 +0,0 @@
|
|||||||
/*
|
|
||||||
* Say — Голосовой ассистент
|
|
||||||
* Дизайн-система Nubes (как в ipwhitelist-app)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
CSS Variables — точь-в-точь ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
:root {
|
|
||||||
--bg: #f5f5f5;
|
|
||||||
--card: #ffffff;
|
|
||||||
--text: #1a1a1a;
|
|
||||||
--muted: #6b7280;
|
|
||||||
--border: #d1d5db;
|
|
||||||
--grey-light: #f3f4f6;
|
|
||||||
--blue: #2563eb;
|
|
||||||
--blue-h: #1d4ed8;
|
|
||||||
--red: #dc2626;
|
|
||||||
--red-h: #b91c1c;
|
|
||||||
--green: #16a34a;
|
|
||||||
--amber: #d97706;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Reset & Base
|
|
||||||
========================================================================== */
|
|
||||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
||||||
background: var(--bg);
|
|
||||||
color: var(--text);
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Topbar (header) — 48px, белый, как в ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
.topbar {
|
|
||||||
background: #fff;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
height: 48px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 0 1.5rem;
|
|
||||||
}
|
|
||||||
.topbar-inner {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.75rem;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.topbar-logo {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
.topbar-logo img {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.topbar-sep {
|
|
||||||
color: var(--muted);
|
|
||||||
font-size: 1rem;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
.topbar-title {
|
|
||||||
font-size: 0.9rem;
|
|
||||||
color: var(--muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Page Container
|
|
||||||
========================================================================== */
|
|
||||||
.page {
|
|
||||||
max-width: 900px;
|
|
||||||
margin: 1.5rem auto;
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Cards — точь-в-точь ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
.card {
|
|
||||||
background: var(--card);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: 12px;
|
|
||||||
box-shadow: 0 1px 2px rgba(0,0,0,.04);
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
.card-header {
|
|
||||||
background: var(--grey-light);
|
|
||||||
padding: .75rem 1rem;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 1rem;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
.card-body {
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Alerts — точь-в-точь ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
.alert {
|
|
||||||
padding: .75rem 1rem;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
border: 1px solid;
|
|
||||||
}
|
|
||||||
.alert-error {
|
|
||||||
background: #fecaca;
|
|
||||||
color: #991b1b;
|
|
||||||
border-color: #fca5a5;
|
|
||||||
}
|
|
||||||
.alert-success {
|
|
||||||
background: #dcfce7;
|
|
||||||
color: #166534;
|
|
||||||
border-color: #bbf7d0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Buttons — точь-в-точь ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
.btn {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: .35rem;
|
|
||||||
padding: .5rem 1rem;
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: 6px;
|
|
||||||
font-size: .85rem;
|
|
||||||
font-weight: 500;
|
|
||||||
background: #fff;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background .15s;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
.btn:hover { background: var(--grey-light); }
|
|
||||||
|
|
||||||
.btn-primary {
|
|
||||||
background: var(--blue);
|
|
||||||
color: #fff;
|
|
||||||
border-color: var(--blue);
|
|
||||||
}
|
|
||||||
.btn-primary:hover { background: var(--blue-h); }
|
|
||||||
.btn-primary:disabled {
|
|
||||||
background: #93c5fd;
|
|
||||||
border-color: #93c5fd;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
LLM Cards — список моделей
|
|
||||||
========================================================================== */
|
|
||||||
.llm-card {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 1rem;
|
|
||||||
padding: .75rem 0;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
.llm-card:last-child { border-bottom: none; }
|
|
||||||
|
|
||||||
.llm-info {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
.llm-name {
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: .95rem;
|
|
||||||
}
|
|
||||||
.llm-desc {
|
|
||||||
font-size: .8rem;
|
|
||||||
color: var(--muted);
|
|
||||||
margin-top: .15rem;
|
|
||||||
}
|
|
||||||
.rec-status {
|
|
||||||
font-size: .8rem;
|
|
||||||
color: var(--muted);
|
|
||||||
min-width: 80px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Кнопка в режиме записи */
|
|
||||||
.record-btn.recording {
|
|
||||||
background: var(--red);
|
|
||||||
border-color: var(--red);
|
|
||||||
animation: pulse-rec 1.2s infinite;
|
|
||||||
}
|
|
||||||
.record-btn.recording:hover {
|
|
||||||
background: var(--red-h);
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse-rec {
|
|
||||||
0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.4); }
|
|
||||||
50% { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Result Section
|
|
||||||
========================================================================== */
|
|
||||||
.result-section {
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
}
|
|
||||||
.result-section:last-child { margin-bottom: 0; }
|
|
||||||
|
|
||||||
.result-label {
|
|
||||||
font-size: .8rem;
|
|
||||||
font-weight: 500;
|
|
||||||
color: var(--muted);
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: .5px;
|
|
||||||
margin-bottom: .35rem;
|
|
||||||
}
|
|
||||||
.result-text {
|
|
||||||
font-size: 1rem;
|
|
||||||
line-height: 1.6;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
word-break: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Loading
|
|
||||||
========================================================================== */
|
|
||||||
.loading {
|
|
||||||
color: var(--muted);
|
|
||||||
font-size: .9rem;
|
|
||||||
padding: 1rem 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
Footer — точь-в-точь ipwhitelist-app
|
|
||||||
========================================================================== */
|
|
||||||
.footer {
|
|
||||||
text-align: center;
|
|
||||||
font-size: .72rem;
|
|
||||||
color: var(--muted);
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
@@ -1,283 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Say — Голосовой ассистент | Nubes</title>
|
|
||||||
<link rel="icon" href="/static/favicon.png" type="image/png">
|
|
||||||
<link rel="stylesheet" href="/static/style.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- Header — точь-в-точь как в ipwhitelist-app -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<header class="topbar">
|
|
||||||
<div class="topbar-inner">
|
|
||||||
<a href="/" class="topbar-logo" title="Say — Главная">
|
|
||||||
<img src="/static/nubes-logo.svg" alt="Nubes" width="130" height="28">
|
|
||||||
</a>
|
|
||||||
<span class="topbar-sep">|</span>
|
|
||||||
<span class="topbar-title">Say — Голосовой ассистент</span>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- Контент -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<div class="page">
|
|
||||||
|
|
||||||
<!-- Карточка: три LLM на выбор -->
|
|
||||||
<div class="card">
|
|
||||||
<div class="card-header">🤖 Выберите модель — нажмите и говорите</div>
|
|
||||||
<div class="card-body" id="llmCards">
|
|
||||||
<!-- Заполняется JS после загрузки профилей с /api/profiles -->
|
|
||||||
<div class="loading">Загрузка моделей...</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Карточка: результат -->
|
|
||||||
<div class="card" id="resultCard" style="display:none">
|
|
||||||
<div class="card-header">📋 Результат</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="result-section">
|
|
||||||
<div class="result-label">📝 Распознано (Whisper)</div>
|
|
||||||
<div class="result-text" id="transcriptionText"></div>
|
|
||||||
</div>
|
|
||||||
<div class="result-section">
|
|
||||||
<div class="result-label" id="responseLabel">🤖 Ответ LLM</div>
|
|
||||||
<div class="result-text" id="responseText"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Ошибка -->
|
|
||||||
<div class="alert alert-error" id="errorBox" style="display:none"></div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- Footer -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<div class="footer">Say v1.0.0 · Whisper + LLM · Nubes</div>
|
|
||||||
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<!-- JavaScript -->
|
|
||||||
<!-- ================================================================== -->
|
|
||||||
<script>
|
|
||||||
// ===========================================================================
|
|
||||||
// DOM-элементы
|
|
||||||
// ===========================================================================
|
|
||||||
const llmCards = document.getElementById('llmCards');
|
|
||||||
const resultCard = document.getElementById('resultCard');
|
|
||||||
const transEl = document.getElementById('transcriptionText');
|
|
||||||
const respEl = document.getElementById('responseText');
|
|
||||||
const respLabel = document.getElementById('responseLabel');
|
|
||||||
const errorBox = document.getElementById('errorBox');
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Состояние записи (одна активная кнопка в моменте)
|
|
||||||
// ===========================================================================
|
|
||||||
let activeStream = null; // MediaStream
|
|
||||||
let activeRecorder = null; // MediaRecorder
|
|
||||||
let activeBtn = null; // DOM-кнопка
|
|
||||||
let audioChunks = [];
|
|
||||||
let activeLlmId = null;
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Шаблон карточки LLM
|
|
||||||
// ===========================================================================
|
|
||||||
function buildLlmCard(profile) {
|
|
||||||
return `
|
|
||||||
<div class="llm-card" data-llm="${profile.id}">
|
|
||||||
<div class="llm-info">
|
|
||||||
<div class="llm-name">${escapeHtml(profile.name)}</div>
|
|
||||||
<div class="llm-desc">${escapeHtml(profile.description)}</div>
|
|
||||||
</div>
|
|
||||||
<button class="btn btn-primary record-btn" data-llm="${profile.id}">
|
|
||||||
<span class="btn-icon">🎤</span>
|
|
||||||
<span class="btn-label">Записать</span>
|
|
||||||
</button>
|
|
||||||
<span class="rec-status" data-llm="${profile.id}"></span>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHtml(str) {
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.textContent = str;
|
|
||||||
return div.innerHTML;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Загрузка профилей с сервера
|
|
||||||
// ===========================================================================
|
|
||||||
async function loadProfiles() {
|
|
||||||
try {
|
|
||||||
const resp = await fetch('/api/profiles');
|
|
||||||
if (!resp.ok) throw new Error('Ошибка загрузки профилей: ' + resp.status);
|
|
||||||
const profiles = await resp.json();
|
|
||||||
|
|
||||||
llmCards.innerHTML = profiles.map(buildLlmCard).join('');
|
|
||||||
|
|
||||||
// Вешаем обработчики на все кнопки записи
|
|
||||||
document.querySelectorAll('.record-btn').forEach(function(btn) {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
var llmId = btn.dataset.llm;
|
|
||||||
if (activeRecorder && activeRecorder.state === 'recording') {
|
|
||||||
stopRecording(); // повторное нажатие = стоп
|
|
||||||
} else {
|
|
||||||
startRecording(llmId, btn);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
llmCards.innerHTML = '<div class="alert alert-error">' + escapeHtml(err.message) + '</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Старт записи
|
|
||||||
// ===========================================================================
|
|
||||||
async function startRecording(llmId, btn) {
|
|
||||||
// Сбрасываем предыдущий результат/ошибку
|
|
||||||
resultCard.style.display = 'none';
|
|
||||||
errorBox.style.display = 'none';
|
|
||||||
|
|
||||||
// Если уже идёт запись на другой кнопке — стоп
|
|
||||||
if (activeRecorder && activeRecorder.state === 'recording') {
|
|
||||||
stopRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
activeStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
||||||
} catch (err) {
|
|
||||||
showError('Нет доступа к микрофону. Разрешите запись в браузере.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var mimeType = MediaRecorder.isTypeSupported('audio/webm;codecs=opus')
|
|
||||||
? 'audio/webm;codecs=opus'
|
|
||||||
: 'audio/webm';
|
|
||||||
|
|
||||||
activeRecorder = new MediaRecorder(activeStream, { mimeType: mimeType });
|
|
||||||
audioChunks = [];
|
|
||||||
activeLlmId = llmId;
|
|
||||||
activeBtn = btn;
|
|
||||||
|
|
||||||
activeRecorder.ondataavailable = function(e) {
|
|
||||||
if (e.data.size > 0) audioChunks.push(e.data);
|
|
||||||
};
|
|
||||||
|
|
||||||
activeRecorder.onstop = function() { sendToServer(); };
|
|
||||||
|
|
||||||
activeRecorder.start();
|
|
||||||
|
|
||||||
// UI: кнопка → состояние «запись»
|
|
||||||
setButtonRecording(btn, true);
|
|
||||||
setAllButtonsDisabled(true, btn);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Стоп записи
|
|
||||||
// ===========================================================================
|
|
||||||
function stopRecording() {
|
|
||||||
if (activeRecorder && activeRecorder.state === 'recording') {
|
|
||||||
activeRecorder.stop();
|
|
||||||
}
|
|
||||||
if (activeStream) {
|
|
||||||
activeStream.getTracks().forEach(function(t) { t.stop(); });
|
|
||||||
activeStream = null;
|
|
||||||
}
|
|
||||||
// UI: кнопка → «обработка...»
|
|
||||||
if (activeBtn) {
|
|
||||||
setButtonProcessing(activeBtn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Отправка аудио на сервер
|
|
||||||
// ===========================================================================
|
|
||||||
async function sendToServer() {
|
|
||||||
var blob = new Blob(audioChunks, { type: 'audio/webm' });
|
|
||||||
var formData = new FormData();
|
|
||||||
formData.append('audio', blob, 'recording.webm');
|
|
||||||
|
|
||||||
try {
|
|
||||||
var resp = await fetch('/api/speech/' + activeLlmId, {
|
|
||||||
method: 'POST',
|
|
||||||
body: formData,
|
|
||||||
});
|
|
||||||
|
|
||||||
var data = await resp.json();
|
|
||||||
|
|
||||||
if (!resp.ok) {
|
|
||||||
throw new Error(data.error || 'Ошибка сервера (' + resp.status + ')');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Успех — показываем результат
|
|
||||||
transEl.textContent = data.transcription;
|
|
||||||
respEl.textContent = data.response;
|
|
||||||
respLabel.textContent = '🤖 Ответ (' + data.llm.name + ')';
|
|
||||||
resultCard.style.display = '';
|
|
||||||
errorBox.style.display = 'none';
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
showError(err.message);
|
|
||||||
} finally {
|
|
||||||
resetButtons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// UI-хелперы
|
|
||||||
// ===========================================================================
|
|
||||||
function setButtonRecording(btn, rec) {
|
|
||||||
var icon = btn.querySelector('.btn-icon');
|
|
||||||
var label = btn.querySelector('.btn-label');
|
|
||||||
if (rec) {
|
|
||||||
icon.textContent = '⏺️';
|
|
||||||
label.textContent = 'Стоп';
|
|
||||||
btn.classList.add('recording');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function setButtonProcessing(btn) {
|
|
||||||
var icon = btn.querySelector('.btn-icon');
|
|
||||||
var label = btn.querySelector('.btn-label');
|
|
||||||
icon.textContent = '⏳';
|
|
||||||
label.textContent = 'Обработка...';
|
|
||||||
btn.disabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setAllButtonsDisabled(dis, exceptBtn) {
|
|
||||||
document.querySelectorAll('.record-btn').forEach(function(b) {
|
|
||||||
if (b !== exceptBtn) b.disabled = dis;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetButtons() {
|
|
||||||
document.querySelectorAll('.record-btn').forEach(function(b) {
|
|
||||||
b.disabled = false;
|
|
||||||
b.classList.remove('recording');
|
|
||||||
b.querySelector('.btn-icon').textContent = '🎤';
|
|
||||||
b.querySelector('.btn-label').textContent = 'Записать';
|
|
||||||
});
|
|
||||||
activeBtn = null;
|
|
||||||
activeRecorder = null;
|
|
||||||
activeLlmId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showError(msg) {
|
|
||||||
errorBox.textContent = '❌ ' + msg;
|
|
||||||
errorBox.style.display = '';
|
|
||||||
resultCard.style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
// Инициализация
|
|
||||||
// ===========================================================================
|
|
||||||
loadProfiles();
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user