Upload 9 files
Browse files- .gitattributes +2 -35
- .gitignore +3 -0
- Dockerfile +5 -0
- Procfile +1 -0
- app.py +140 -0
- requirements.txt +7 -0
- static/script.js +133 -0
- static/styles.css +148 -0
- templates/index.html +48 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,2 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model_cache/
|
| 2 |
+
models_cache/
|
| 3 |
+
instance/
|
Dockerfile
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY . .
|
| 4 |
+
RUN pip install -r requirements.txt
|
| 5 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]
|
Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
web: gunicorn app:app
|
app.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify, render_template
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
import torchaudio
|
| 5 |
+
from pydub import AudioSegment
|
| 6 |
+
import os
|
| 7 |
+
import io
|
| 8 |
+
os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
|
| 9 |
+
from transformers import AutoModelForAudioClassification, AutoFeatureExtractor
|
| 10 |
+
|
| 11 |
+
app = Flask(__name__)
|
| 12 |
+
|
| 13 |
+
# Обновлённый словарь эмоций с surprise
|
| 14 |
+
emotion_map = {
|
| 15 |
+
'joy': '😊 Радость',
|
| 16 |
+
'neutral': '😐 Нейтрально',
|
| 17 |
+
'anger': '😠 Злость',
|
| 18 |
+
'sadness': '😢 Грусть',
|
| 19 |
+
'surprise': '😲 Удивление'
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Добавим ffmpeg и ffprobe в PATH
|
| 23 |
+
os.environ["PATH"] = r"C:\ffmpeg\bin;" + os.environ["PATH"]
|
| 24 |
+
|
| 25 |
+
# Модель для текста
|
| 26 |
+
text_classifier = pipeline("text-classification", model="cointegrated/rubert-tiny2-cedr-emotion-detection", top_k=None)
|
| 27 |
+
|
| 28 |
+
# Модель для аудио
|
| 29 |
+
# Аудио модель: универсальная, с поддержкой русского
|
| 30 |
+
audio_classifier = pipeline(
|
| 31 |
+
"audio-classification",
|
| 32 |
+
model="superb/hubert-large-superb-er",
|
| 33 |
+
device=0 if torch.cuda.is_available() else -1
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@app.route("/")
|
| 38 |
+
def index():
|
| 39 |
+
return render_template("index.html")
|
| 40 |
+
|
| 41 |
+
@app.route("/analyze", methods=["POST"])
|
| 42 |
+
def analyze_text():
|
| 43 |
+
data = request.get_json()
|
| 44 |
+
text = data.get("text", "")
|
| 45 |
+
if not text.strip():
|
| 46 |
+
return jsonify({"error": "Пустой текст."}), 400
|
| 47 |
+
|
| 48 |
+
predictions = text_classifier(text)[0]
|
| 49 |
+
if not predictions:
|
| 50 |
+
return jsonify({"emotion": "❓ Не определено", "confidence": 0.0})
|
| 51 |
+
|
| 52 |
+
top_prediction = max(predictions, key=lambda x: x["score"])
|
| 53 |
+
label = top_prediction["label"]
|
| 54 |
+
confidence = round(top_prediction["score"], 2)
|
| 55 |
+
|
| 56 |
+
if confidence < 0.5:
|
| 57 |
+
return jsonify({"emotion": "🤔 Неуверенно", "confidence": confidence})
|
| 58 |
+
|
| 59 |
+
emotion = emotion_map.get(label, "❓ Неизвестно")
|
| 60 |
+
return jsonify({"emotion": emotion, "confidence": confidence})
|
| 61 |
+
|
| 62 |
+
from pydub.utils import which
|
| 63 |
+
|
| 64 |
+
# Проверка на наличие ffmpeg
|
| 65 |
+
if not which("ffmpeg"):
|
| 66 |
+
print("FFmpeg не найден в системе!")
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@app.route('/analyze_audio', methods=['POST'])
|
| 70 |
+
def analyze_audio():
|
| 71 |
+
try:
|
| 72 |
+
if 'audio' not in request.files:
|
| 73 |
+
return jsonify({'error': 'Аудио файл обязателен'}), 400
|
| 74 |
+
|
| 75 |
+
audio_file = request.files['audio']
|
| 76 |
+
temp_path = "temp_audio.wav"
|
| 77 |
+
|
| 78 |
+
# Конвертация в формат для модели
|
| 79 |
+
audio = AudioSegment.from_file(io.BytesIO(audio_file.read()))
|
| 80 |
+
audio = audio.set_frame_rate(16000).set_channels(1)
|
| 81 |
+
audio.export(temp_path, format="wav", codec="pcm_s16le") # Явно указываем кодек
|
| 82 |
+
|
| 83 |
+
# Анализ
|
| 84 |
+
result = audio_classifier(temp_path)
|
| 85 |
+
os.remove(temp_path)
|
| 86 |
+
|
| 87 |
+
# Отладочный вывод
|
| 88 |
+
print("Raw model output:", result)
|
| 89 |
+
|
| 90 |
+
# Сопоставление с эмоциями
|
| 91 |
+
# Новый маппинг
|
| 92 |
+
emotion_mapping = {
|
| 93 |
+
'hap': 'happy',
|
| 94 |
+
'sad': 'sad',
|
| 95 |
+
'neu': 'neutral',
|
| 96 |
+
'ang': 'angry'
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Сбор эмоций
|
| 100 |
+
emotions = {v: 0.0 for v in emotion_mapping.values()}
|
| 101 |
+
|
| 102 |
+
for item in result:
|
| 103 |
+
label = item['label'].lower()
|
| 104 |
+
score = item['score']
|
| 105 |
+
if label in emotion_mapping:
|
| 106 |
+
key = emotion_mapping[label]
|
| 107 |
+
emotions[key] += score
|
| 108 |
+
|
| 109 |
+
# Нормализация
|
| 110 |
+
total = sum(emotions.values())
|
| 111 |
+
if total == 0:
|
| 112 |
+
return jsonify({'error': 'Не удалось распознать эмоции'}), 500
|
| 113 |
+
|
| 114 |
+
emotions = {k: round(v / total, 4) for k, v in emotions.items()}
|
| 115 |
+
dominant_emotion = max(emotions.items(), key=lambda x: x[1])
|
| 116 |
+
|
| 117 |
+
# Маппинг для ответа
|
| 118 |
+
response_map = {
|
| 119 |
+
'happy': '😊 Радость',
|
| 120 |
+
'sad': '😢 Грусть',
|
| 121 |
+
'angry': '😠 Злость',
|
| 122 |
+
'neutral': '😐 Нейтрально'
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return jsonify({
|
| 126 |
+
'emotion': response_map.get(dominant_emotion[0], 'неизвестно'),
|
| 127 |
+
'confidence': dominant_emotion[1],
|
| 128 |
+
'details': emotions
|
| 129 |
+
})
|
| 130 |
+
|
| 131 |
+
except Exception as e:
|
| 132 |
+
print(f"Ошибка анализа аудио: {str(e)}")
|
| 133 |
+
return jsonify({'error': 'Ошибка обработки аудио'}), 500
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
if __name__ == "__main__":
|
| 137 |
+
app.run(debug=True)
|
| 138 |
+
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
app.run(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask>=2.0.0
|
| 2 |
+
transformers>=4.15.0
|
| 3 |
+
torch>=1.9.0
|
| 4 |
+
torchaudio>=0.9.0
|
| 5 |
+
pydub>=0.25.1
|
| 6 |
+
librosa>=0.8.0
|
| 7 |
+
numpy>=1.21.0
|
static/script.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 2 |
+
// Объявляем переменные для записи аудио
|
| 3 |
+
let mediaRecorder;
|
| 4 |
+
let audioChunks = [];
|
| 5 |
+
let audioStream;
|
| 6 |
+
|
| 7 |
+
// Элементы интерфейса
|
| 8 |
+
const recordBtn = document.getElementById("record-btn");
|
| 9 |
+
const stopBtn = document.getElementById("stop-btn");
|
| 10 |
+
const sendBtn = document.getElementById("send-btn");
|
| 11 |
+
const uploadBtn = document.getElementById("upload-btn");
|
| 12 |
+
const userInput = document.getElementById("user-input");
|
| 13 |
+
const chatBox = document.getElementById("chat-box");
|
| 14 |
+
const audioFileInput = document.getElementById("audio-file");
|
| 15 |
+
|
| 16 |
+
// ===== 1. Отправка текста =====
|
| 17 |
+
sendBtn.addEventListener("click", async () => {
|
| 18 |
+
const text = userInput.value.trim();
|
| 19 |
+
if (!text) return;
|
| 20 |
+
|
| 21 |
+
appendMessage("user", text);
|
| 22 |
+
userInput.value = "";
|
| 23 |
+
|
| 24 |
+
try {
|
| 25 |
+
const response = await fetch("/analyze", {
|
| 26 |
+
method: "POST",
|
| 27 |
+
headers: { "Content-Type": "application/json" },
|
| 28 |
+
body: JSON.stringify({ text })
|
| 29 |
+
});
|
| 30 |
+
|
| 31 |
+
if (!response.ok) throw new Error("Ошибка сервера");
|
| 32 |
+
|
| 33 |
+
const data = await response.json();
|
| 34 |
+
appendMessage("bot", `Эмоция: ${data.emotion} (${(data.confidence * 100).toFixed(1)}%)`);
|
| 35 |
+
} catch (error) {
|
| 36 |
+
console.error("Ошибка:", error);
|
| 37 |
+
appendMessage("bot", `❌ Ошибка: ${error.message}`);
|
| 38 |
+
}
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
// ===== 2. Загрузка аудиофайла =====
|
| 42 |
+
uploadBtn.addEventListener("click", async () => {
|
| 43 |
+
const file = audioFileInput.files[0];
|
| 44 |
+
if (!file) return;
|
| 45 |
+
|
| 46 |
+
appendMessage("user", "Загружен аудиофайл...");
|
| 47 |
+
|
| 48 |
+
try {
|
| 49 |
+
const formData = new FormData();
|
| 50 |
+
formData.append("audio", file);
|
| 51 |
+
|
| 52 |
+
const response = await fetch("/analyze_audio", {
|
| 53 |
+
method: "POST",
|
| 54 |
+
body: formData
|
| 55 |
+
});
|
| 56 |
+
|
| 57 |
+
if (!response.ok) throw new Error("Ошибка сервера");
|
| 58 |
+
|
| 59 |
+
const data = await response.json();
|
| 60 |
+
appendMessage("bot", `Эмоция: ${data.emotion} (${(data.confidence * 100).toFixed(1)}%)`);
|
| 61 |
+
} catch (error) {
|
| 62 |
+
console.error("Ошибка:", error);
|
| 63 |
+
appendMessage("bot", `❌ Ошибка: ${error.message}`);
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
// ===== 3. Запись аудио =====
|
| 68 |
+
recordBtn.addEventListener("click", async () => {
|
| 69 |
+
try {
|
| 70 |
+
// Запрашиваем доступ к микрофону
|
| 71 |
+
audioStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 72 |
+
|
| 73 |
+
// Настраиваем запись
|
| 74 |
+
mediaRecorder = new MediaRecorder(audioStream);
|
| 75 |
+
audioChunks = [];
|
| 76 |
+
|
| 77 |
+
// Обработчики событий
|
| 78 |
+
mediaRecorder.ondataavailable = (e) => audioChunks.push(e.data);
|
| 79 |
+
|
| 80 |
+
mediaRecorder.onstop = async () => {
|
| 81 |
+
try {
|
| 82 |
+
const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
|
| 83 |
+
appendMessage("user", "Отправлено голосовое сообщение...");
|
| 84 |
+
|
| 85 |
+
const formData = new FormData();
|
| 86 |
+
formData.append("audio", audioBlob, "recording.wav");
|
| 87 |
+
|
| 88 |
+
const response = await fetch("/analyze_audio", {
|
| 89 |
+
method: "POST",
|
| 90 |
+
body: formData
|
| 91 |
+
});
|
| 92 |
+
|
| 93 |
+
if (!response.ok) throw new Error("Ошибка сервера");
|
| 94 |
+
|
| 95 |
+
const data = await response.json();
|
| 96 |
+
appendMessage("bot", `Эмоция: ${data.emotion} (${(data.confidence * 100).toFixed(1)}%)`);
|
| 97 |
+
} catch (error) {
|
| 98 |
+
console.error("Ошибка:", error);
|
| 99 |
+
appendMessage("bot", `❌ Ошибка: ${error.message}`);
|
| 100 |
+
} finally {
|
| 101 |
+
// Освобождаем ресурсы
|
| 102 |
+
audioStream.getTracks().forEach(track => track.stop());
|
| 103 |
+
}
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
mediaRecorder.start();
|
| 107 |
+
recordBtn.disabled = true;
|
| 108 |
+
stopBtn.disabled = false;
|
| 109 |
+
|
| 110 |
+
} catch (error) {
|
| 111 |
+
console.error("Ошибка записи:", error);
|
| 112 |
+
appendMessage("bot", "❌ Не удалось получить доступ к микрофону");
|
| 113 |
+
}
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
// Остановка записи
|
| 117 |
+
stopBtn.addEventListener("click", () => {
|
| 118 |
+
if (mediaRecorder && mediaRecorder.state === "recording") {
|
| 119 |
+
mediaRecorder.stop();
|
| 120 |
+
recordBtn.disabled = false;
|
| 121 |
+
stopBtn.disabled = true;
|
| 122 |
+
}
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
// ===== Вспомогательные функции =====
|
| 126 |
+
function appendMessage(sender, text) {
|
| 127 |
+
const message = document.createElement("div");
|
| 128 |
+
message.classList.add("message", sender === "user" ? "user-message" : "bot-message");
|
| 129 |
+
message.innerHTML = text; // Используем innerHTML для поддержки эмодзи
|
| 130 |
+
chatBox.appendChild(message);
|
| 131 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 132 |
+
}
|
| 133 |
+
});
|
static/styles.css
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Основные стили (как у вас были) */
|
| 2 |
+
body {
|
| 3 |
+
margin: 0;
|
| 4 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 5 |
+
background: linear-gradient(135deg, #1e1e2f, #2a2a40);
|
| 6 |
+
height: 100vh;
|
| 7 |
+
display: flex;
|
| 8 |
+
justify-content: center;
|
| 9 |
+
align-items: center;
|
| 10 |
+
color: #fff;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
.chat-container {
|
| 14 |
+
width: 500px;
|
| 15 |
+
background: #2a2a40;
|
| 16 |
+
border-radius: 16px;
|
| 17 |
+
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
| 18 |
+
overflow: hidden;
|
| 19 |
+
display: flex;
|
| 20 |
+
flex-direction: column;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.chat-title {
|
| 24 |
+
text-align: center;
|
| 25 |
+
font-size: 1.5rem;
|
| 26 |
+
color: #fff;
|
| 27 |
+
padding: 16px;
|
| 28 |
+
background: linear-gradient(90deg, #4a4ae8, #3b3b98);
|
| 29 |
+
margin: 0;
|
| 30 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.chat-box {
|
| 34 |
+
flex: 1;
|
| 35 |
+
padding: 16px;
|
| 36 |
+
overflow-y: auto;
|
| 37 |
+
background: #1e1e2f;
|
| 38 |
+
display: flex;
|
| 39 |
+
flex-direction: column;
|
| 40 |
+
gap: 12px;
|
| 41 |
+
max-height: 400px;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.message {
|
| 45 |
+
max-width: 80%;
|
| 46 |
+
padding: 12px 16px;
|
| 47 |
+
border-radius: 16px;
|
| 48 |
+
font-size: 0.9rem;
|
| 49 |
+
line-height: 1.4;
|
| 50 |
+
animation: fadeIn 0.3s ease-in-out;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.user-message {
|
| 54 |
+
background: linear-gradient(90deg, #4a4ae8, #3b3b98);
|
| 55 |
+
color: white;
|
| 56 |
+
align-self: flex-end;
|
| 57 |
+
border-bottom-right-radius: 0;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.bot-message {
|
| 61 |
+
background: #333;
|
| 62 |
+
color: #fff;
|
| 63 |
+
align-self: flex-start;
|
| 64 |
+
border-bottom-left-radius: 0;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
@keyframes fadeIn {
|
| 68 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 69 |
+
to { opacity: 1; transform: translateY(0); }
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.input-container {
|
| 73 |
+
padding: 12px;
|
| 74 |
+
background: #2a2a40;
|
| 75 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.input-group {
|
| 79 |
+
display: flex;
|
| 80 |
+
gap: 8px;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.chat-input {
|
| 84 |
+
flex: 1;
|
| 85 |
+
padding: 12px;
|
| 86 |
+
border: 2px solid rgba(255, 255, 255, 0.2);
|
| 87 |
+
border-radius: 8px;
|
| 88 |
+
font-size: 0.9rem;
|
| 89 |
+
background: #1e1e2f;
|
| 90 |
+
color: #fff;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
.chat-input:focus {
|
| 94 |
+
border-color: #4a4ae8;
|
| 95 |
+
outline: none;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.send-btn {
|
| 99 |
+
padding: 12px 20px;
|
| 100 |
+
background: linear-gradient(90deg, #4a4ae8, #3b3b98);
|
| 101 |
+
color: white;
|
| 102 |
+
border: none;
|
| 103 |
+
border-radius: 8px;
|
| 104 |
+
cursor: pointer;
|
| 105 |
+
font-size: 0.9rem;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
/* Стили для аудио элементов */
|
| 109 |
+
.audio-controls {
|
| 110 |
+
display: flex;
|
| 111 |
+
align-items: center;
|
| 112 |
+
gap: 10px;
|
| 113 |
+
padding: 12px;
|
| 114 |
+
background: #2a2a40;
|
| 115 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.audio-btn {
|
| 119 |
+
padding: 10px 15px;
|
| 120 |
+
background: linear-gradient(90deg, #4a4ae8, #3b3b98);
|
| 121 |
+
color: white;
|
| 122 |
+
border: none;
|
| 123 |
+
border-radius: 8px;
|
| 124 |
+
cursor: pointer;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.audio-btn:disabled {
|
| 128 |
+
background: #555;
|
| 129 |
+
cursor: not-allowed;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
#waveform {
|
| 133 |
+
flex-grow: 1;
|
| 134 |
+
height: 60px;
|
| 135 |
+
background: #1e1e2f;
|
| 136 |
+
border-radius: 8px;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.file-upload {
|
| 140 |
+
display: flex;
|
| 141 |
+
gap: 10px;
|
| 142 |
+
align-items: center;
|
| 143 |
+
margin-top: 10px;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.file-upload input[type="file"] {
|
| 147 |
+
flex: 1;
|
| 148 |
+
}
|
templates/index.html
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ru">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Emotion Analyzer</title>
|
| 7 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<div class="chat-container">
|
| 12 |
+
<h1 class="chat-title">Анализатор эмоций</h1>
|
| 13 |
+
|
| 14 |
+
<div id="chat-box" class="chat-box">
|
| 15 |
+
<div class="message bot-message">
|
| 16 |
+
Привет! Отправьте текст или голосовое сообщение для анализа эмоций.
|
| 17 |
+
</div>
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
<div class="audio-controls">
|
| 21 |
+
<button id="record-btn" class="audio-btn">
|
| 22 |
+
<i class="fas fa-microphone"></i> Запись
|
| 23 |
+
</button>
|
| 24 |
+
<button id="stop-btn" class="audio-btn" disabled>
|
| 25 |
+
<i class="fas fa-stop"></i> Стоп
|
| 26 |
+
</button>
|
| 27 |
+
<canvas id="waveform" width="300" height="60"></canvas>
|
| 28 |
+
</div>
|
| 29 |
+
|
| 30 |
+
<div class="input-container">
|
| 31 |
+
<div class="input-group">
|
| 32 |
+
<input type="text" id="user-input" class="chat-input" placeholder="Введите сообщение...">
|
| 33 |
+
<button id="send-btn" class="send-btn">Отправить</button>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<div class="upload-container">
|
| 38 |
+
<label for="audio-file">Или загрузите аудиофайл:</label>
|
| 39 |
+
<input type="file" id="audio-file" accept="audio/*">
|
| 40 |
+
<button id="upload-btn" class="audio-btn">
|
| 41 |
+
<i class="fas fa-upload"></i> Загрузить
|
| 42 |
+
</button>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<script src="{{ url_for('static', filename='script.js') }}"></script>
|
| 47 |
+
</body>
|
| 48 |
+
</html>
|